aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-22 13:16:14 -0700
committerSean Griffin <sean@thoughtbot.com>2014-11-22 13:16:14 -0700
commitdcc143cd702bfbfef9cb92e1fde75171d088a5ac (patch)
treef0b9c0a407d286bfc57fd7a9d3ec04382650bfba /activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
parentb33ed44ad312c5274fe72b26172ac0116d9ffb28 (diff)
downloadrails-dcc143cd702bfbfef9cb92e1fde75171d088a5ac.tar.gz
rails-dcc143cd702bfbfef9cb92e1fde75171d088a5ac.tar.bz2
rails-dcc143cd702bfbfef9cb92e1fde75171d088a5ac.zip
Rename the primary key index when renaming a table in pg
Also checked to make sure this does not affect foreign key constraints. (It doesn't). Fixes #12856 Closes #14088
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb3
1 files changed, 3 insertions, 0 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 b4b066c06e..515ff2dd44 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -411,7 +411,10 @@ module ActiveRecord
pk, seq = pk_and_sequence_for(new_name)
if seq && seq.identifier == "#{table_name}_#{pk}_seq"
new_seq = "#{new_name}_#{pk}_seq"
+ idx = "#{table_name}_pkey"
+ new_idx = "#{new_name}_pkey"
execute "ALTER TABLE #{quote_table_name(seq)} RENAME TO #{quote_table_name(new_seq)}"
+ execute "ALTER INDEX #{quote_table_name(idx)} RENAME TO #{quote_table_name(new_idx)}"
end
rename_table_indexes(table_name, new_name)