aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-01-09 22:29:44 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-01-09 22:29:44 +0900
commitc352f12cbb75636380b06917616e14029f339189 (patch)
tree4a82b79cdba131835c8aff7d423b297c33c80950 /activerecord
parentcf865331a3b6c8fa7e6bb541846544f98b6c8bb0 (diff)
downloadrails-c352f12cbb75636380b06917616e14029f339189.tar.gz
rails-c352f12cbb75636380b06917616e14029f339189.tar.bz2
rails-c352f12cbb75636380b06917616e14029f339189.zip
Fix UUID primary key with default nil in legacy migration
UUID primary key with no default value feature (#10404, #18206) was lost in legacy migration caused by #25395 got merged. Restore the feature again in legacy migration.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb2
-rw-r--r--activerecord/test/cases/adapters/postgresql/uuid_test.rb19
2 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb
index 2904634eb7..a5d8893634 100644
--- a/activerecord/lib/active_record/migration/compatibility.rb
+++ b/activerecord/lib/active_record/migration/compatibility.rb
@@ -16,7 +16,7 @@ module ActiveRecord
class V5_0 < V5_1
def create_table(table_name, options = {})
if adapter_name == "PostgreSQL"
- if options[:id] == :uuid && !options[:default]
+ if options[:id] == :uuid && !options.key?(:default)
options[:default] = "uuid_generate_v4()"
end
end
diff --git a/activerecord/test/cases/adapters/postgresql/uuid_test.rb b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
index 29052126d2..4655cd1d20 100644
--- a/activerecord/test/cases/adapters/postgresql/uuid_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/uuid_test.rb
@@ -283,6 +283,25 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::PostgreSQLTestCase
schema = dump_table_schema "pg_uuids"
assert_match(/\bcreate_table "pg_uuids", id: :uuid, default: nil/, schema)
end
+
+ def test_schema_dumper_for_uuid_primary_key_with_default_nil_in_legacy_migration
+ @verbose_was = ActiveRecord::Migration.verbose
+ ActiveRecord::Migration.verbose = false
+
+ migration = Class.new(ActiveRecord::Migration[5.0]) do
+ def version; 101 end
+ def migrate(x)
+ create_table("pg_uuids_4", id: :uuid, default: nil)
+ end
+ end.new
+ ActiveRecord::Migrator.new(:up, [migration]).migrate
+
+ schema = dump_table_schema "pg_uuids_4"
+ assert_match(/\bcreate_table "pg_uuids_4", id: :uuid, default: nil/, schema)
+ ensure
+ drop_table "pg_uuids_4"
+ ActiveRecord::Migration.verbose = @verbose_was
+ end
end
end