aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorfatkodima <fatkodima@rambler.ru>2017-12-25 23:41:28 +0200
committerfatkodima <fatkodima@rambler.ru>2017-12-25 23:42:18 +0200
commit55eea4e42d557037600c71556700bb82fcebcb0a (patch)
tree62e5d55a8d3233e538c594b856c0753097823960 /activerecord
parent237397e41a6a71fbc8424201a21cad00e132ff21 (diff)
downloadrails-55eea4e42d557037600c71556700bb82fcebcb0a.tar.gz
rails-55eea4e42d557037600c71556700bb82fcebcb0a.tar.bz2
rails-55eea4e42d557037600c71556700bb82fcebcb0a.zip
Fix `add_column` with :primary_key type compatibility for SQLite
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb2
-rw-r--r--activerecord/test/cases/migration/compatibility_test.rb19
2 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index c72db15ce3..a8c3318905 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -297,7 +297,7 @@ module ActiveRecord
end
def add_column(table_name, column_name, type, options = {}) #:nodoc:
- if valid_alter_table_type?(type)
+ if valid_alter_table_type?(type) && !options[:primary_key]
super(table_name, column_name, type, options)
else
alter_table(table_name) do |definition|
diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb
index cc2391f349..eb6d65d1b1 100644
--- a/activerecord/test/cases/migration/compatibility_test.rb
+++ b/activerecord/test/cases/migration/compatibility_test.rb
@@ -267,6 +267,25 @@ module LegacyPrimaryKeyTestCases
end
end
+ if current_adapter?(:SQLite3Adapter)
+ def test_add_column_with_legacy_primary_key_should_work
+ @migration = Class.new(migration_class) {
+ def change
+ create_table :legacy_primary_keys, id: false do |t|
+ t.integer :dummy
+ end
+ add_column :legacy_primary_keys, :id, :primary_key
+ end
+ }.new
+
+ @migration.migrate(:up)
+
+ assert_equal "id", LegacyPrimaryKey.primary_key
+ legacy_pk = LegacyPrimaryKey.columns_hash["id"]
+ assert_not legacy_pk.null
+ end
+ end
+
def test_legacy_join_table_foreign_keys_should_be_integer
@migration = Class.new(migration_class) {
def change