aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-01-11 20:24:27 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-01-15 19:27:42 +0900
commit5608d8afe4397757f4d1ec95f5a78416365b17ed (patch)
tree7584b941f573ed71f1391f5037c6e036912bdcde
parent179df9df68396a6916f62192971838b7e73d5f76 (diff)
downloadrails-5608d8afe4397757f4d1ec95f5a78416365b17ed.tar.gz
rails-5608d8afe4397757f4d1ec95f5a78416365b17ed.tar.bz2
rails-5608d8afe4397757f4d1ec95f5a78416365b17ed.zip
Clean up internal metadata definition
Use `t.index` in `create_table` instead of `add_index` It is slightly more efficient. Revert "Use `key` as primary key in schema." This reverts commit 350ae6cdc1ea83e21c23abd10e7e99c9a0bbdbd2. `:primary_key` option does nothing if `id: false`. https://github.com/rails/rails/blob/v5.0.0.beta1/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L251-L261
-rw-r--r--activerecord/lib/active_record/internal_metadata.rb5
-rw-r--r--activerecord/lib/active_record/schema_migration.rb2
2 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/internal_metadata.rb b/activerecord/lib/active_record/internal_metadata.rb
index 2e962f4218..e5c6e5c885 100644
--- a/activerecord/lib/active_record/internal_metadata.rb
+++ b/activerecord/lib/active_record/internal_metadata.rb
@@ -33,13 +33,12 @@ module ActiveRecord
# Creates an internal metadata table with columns +key+ and +value+
def create_table
unless table_exists?
- connection.create_table(table_name, primary_key: :key, id: false ) do |t|
+ connection.create_table(table_name, id: false) do |t|
t.column :key, :string
t.column :value, :string
t.timestamps
+ t.index :key, unique: true, name: index_name
end
-
- connection.add_index table_name, :key, unique: true, name: index_name
end
end
end
diff --git a/activerecord/lib/active_record/schema_migration.rb b/activerecord/lib/active_record/schema_migration.rb
index 3017ee0bbb..ee4c71f304 100644
--- a/activerecord/lib/active_record/schema_migration.rb
+++ b/activerecord/lib/active_record/schema_migration.rb
@@ -31,8 +31,8 @@ module ActiveRecord
connection.create_table(table_name, id: false) do |t|
t.column :version, :string, version_options
+ t.index :version, unique: true, name: index_name
end
- connection.add_index table_name, :version, unique: true, name: index_name
end
end