aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-10-15 20:18:12 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-10-15 20:43:38 +0900
commit9493d4553569118b2a85da84fd3a8ba2b5b2de76 (patch)
tree8e7c221b830c31f7f7c405dc9257db80d8b0224a /activerecord/test/cases/adapters/mysql2
parenta92e4bfff31dd862e842bd68ddd78f3db720b3a4 (diff)
downloadrails-9493d4553569118b2a85da84fd3a8ba2b5b2de76.tar.gz
rails-9493d4553569118b2a85da84fd3a8ba2b5b2de76.tar.bz2
rails-9493d4553569118b2a85da84fd3a8ba2b5b2de76.zip
MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`
Currently `AUTO_INCREMENT` is implicitly used in the default primary key definition. But `AUTO_INCREMENT` is not only used for single column primary key, but also for composite primary key. In that case, `auto_increment: true` should be dumped explicitly in the `db/schema.rb`. Fixes #30894.
Diffstat (limited to 'activerecord/test/cases/adapters/mysql2')
-rw-r--r--activerecord/test/cases/adapters/mysql2/auto_increment_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/auto_increment_test.rb b/activerecord/test/cases/adapters/mysql2/auto_increment_test.rb
new file mode 100644
index 0000000000..4c67633946
--- /dev/null
+++ b/activerecord/test/cases/adapters/mysql2/auto_increment_test.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require "cases/helper"
+require "support/schema_dumping_helper"
+
+class Mysql2AutoIncrementTest < ActiveRecord::Mysql2TestCase
+ include SchemaDumpingHelper
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ end
+
+ def teardown
+ @connection.drop_table :auto_increments, if_exists: true
+ end
+
+ def test_auto_increment_without_primary_key
+ @connection.create_table :auto_increments, id: false, force: true do |t|
+ t.integer :id, null: false, auto_increment: true
+ t.index :id
+ end
+ output = dump_table_schema("auto_increments")
+ assert_match(/t\.integer\s+"id",\s+null: false,\s+auto_increment: true$/, output)
+ end
+
+ def test_auto_increment_with_composite_primary_key
+ @connection.create_table :auto_increments, primary_key: [:id, :created_at], force: true do |t|
+ t.integer :id, null: false, auto_increment: true
+ t.datetime :created_at, null: false
+ end
+ output = dump_table_schema("auto_increments")
+ assert_match(/t\.integer\s+"id",\s+null: false,\s+auto_increment: true$/, output)
+ end
+end