Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

renames the primary key constraint on renaming table #14088

Closed
wants to merge 2 commits into from

5 participants

@rubydog

Related to issue #12856

Closes #12856

@deivid-rodriguez

This is the exact same workaround I'm using.

@rubydog

Good, I generalised it :)

@deivid-rodriguez

Oh, i didn't realize it was mentioned in the report, I thought it was a coincidence... :)

@senny
Owner

/cc @matthewd

@senny senny added the PostgreSQL label
@sgrif sgrif self-assigned this
@sgrif sgrif closed this pull request from a commit
@sgrif sgrif 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
dcc143c
@sgrif sgrif closed this in dcc143c
@sgrif sgrif referenced this pull request from a commit
@sgrif sgrif Rename the primary key index when renaming a table in pg
Backport of dcc143c

Fixes #12856
Closes #14088
1460470
@sgrif sgrif referenced this pull request from a commit
@sgrif sgrif Rename the primary key index when renaming a table in pg
Backport of dcc143c

Fixes #12856
Closes #14088
e39b1f3
@sachin004 sachin004 referenced this pull request from a commit in sachin004/rails
@sgrif sgrif 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
6825f3a
@ttosch ttosch referenced this pull request from a commit
@sgrif sgrif Rename the primary key index when renaming a table in pg
Backport of dcc143c

Fixes #12856
Closes #14088
804b02e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 17, 2014
  1. renames the primary key constraint on renaming table

    bhushan lodha authored
Commits on Feb 20, 2014
This page is out of date. Refresh to see the latest.
View
4 activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
@@ -381,8 +381,10 @@ def rename_table(table_name, new_name)
if seq == "#{table_name}_#{pk}_seq"
new_seq = "#{new_name}_#{pk}_seq"
execute "ALTER TABLE #{quote_table_name(seq)} RENAME TO #{quote_table_name(new_seq)}"
+ execute "ALTER TABLE #{new_name} DROP CONSTRAINT #{table_name}_pkey;"
+ execute "ALTER TABLE #{new_name} ADD PRIMARY KEY (#{pk});"
end
-
+
rename_table_indexes(table_name, new_name)
end
Something went wrong with that request. Please try again.