diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-04 05:49:59 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-04 05:49:59 -0700 |
commit | 903a2c2d33c91edaae08a952d94b4ac35a7443da (patch) | |
tree | 8decf4b359e08812149b1b3ee3a0a747884ae8f4 /activerecord/lib | |
parent | 29dce6e4b540d01bd5fd3ba7b31d2b0efc43bf81 (diff) | |
parent | fa87e3166fd404f9d494965fb20712a55af078fb (diff) | |
download | rails-903a2c2d33c91edaae08a952d94b4ac35a7443da.tar.gz rails-903a2c2d33c91edaae08a952d94b4ac35a7443da.tar.bz2 rails-903a2c2d33c91edaae08a952d94b4ac35a7443da.zip |
Merge pull request #10458 from bwbuchanan/issue-10451
Make SchemaDumper emit "id: :uuid" when using UUID primary keys
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index d9b807bba4..98916b06a5 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -321,6 +321,7 @@ module ActiveRecord result = query(<<-end_sql, 'SCHEMA')[0] SELECT attr.attname, CASE + WHEN pg_get_expr(def.adbin, def.adrelid) !~* 'nextval' THEN NULL WHEN split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2) ~ '.' THEN substr(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2), strpos(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2), '.')+1) @@ -332,7 +333,7 @@ module ActiveRecord JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1]) WHERE t.oid = '#{quote_table_name(table)}'::regclass AND cons.contype = 'p' - AND pg_get_expr(def.adbin, def.adrelid) ~* 'nextval' + AND pg_get_expr(def.adbin, def.adrelid) ~* 'nextval|uuid_generate' end_sql end diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 10c6d272cd..1181cc739e 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -106,9 +106,12 @@ HEADER end tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}" - if columns.detect { |c| c.name == pk } + pkcol = columns.detect { |c| c.name == pk } + if pkcol if pk != 'id' tbl.print %Q(, primary_key: "#{pk}") + elsif pkcol.sql_type == 'uuid' + tbl.print ", id: :uuid" end else tbl.print ", id: false" |