Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump PostgreSQL primary key with custom function as a default. #16127

Merged
merged 1 commit into from
Jul 14, 2014
Merged

Dump PostgreSQL primary key with custom function as a default. #16127

merged 1 commit into from
Jul 14, 2014

Conversation

Envek
Copy link
Contributor

@Envek Envek commented Jul 10, 2014

Fixes #16111. See it for more information.

For example, if I use pgcrypto extension in PostgreSQL 9.4 beta 1, where uuid-ossp extension isn't available for moment of writing, and thus required to use a gen_random_uuid() method as a primary key default.

In this case schema dumper wasn't able to correctly reconstruct create_table statement and lost primary key constraint on schema load.

If I create migration in PostgreSQL 9.4 beta 1 as:

enable_extension 'pgcrypto'
create_table "pg_uuids", id: :uuid, default: "gen_random_uuid()", force: true do |t|
  t.string "name"
  t.uuid   "other_uuid", default: "gen_random_uuid()"
end

Schema dumper currently dumps it as this:

create_table "pg_uuids", id: false, force: true do |t|
  t.uuid   "id",         default: "gen_random_uuid()", null: false
  t.string "name"
  t.uuid   "other_uuid", default: "gen_random_uuid()"
end

Instead of this:

create_table "pg_uuids", id: :uuid, default: "gen_random_uuid()", force: true do |t|
  t.string "name"
  t.uuid   "other_uuid", default: "gen_random_uuid()"
end

What about to also backport it to 4-1-stable?

@@ -117,6 +117,13 @@ def enable_uuid_ossp!(connection)
return true if connection.extension_enabled?('uuid-ossp')

connection.enable_extension 'uuid-ossp'
# Create custom PostgreSQL function to generate UUIDs
# to test dumping tables which columns have defaults with custom functions
connection.execute <<-SQL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it better to place it inside the test that use it

@matthewd
Copy link
Member

Squash please

For example, if use pgcrypto extension in PostgreSQL 9.4 beta 1, where
uuid-ossp extension isn't available for moment of writing, and thus to
use a gen_random_uuid() method as a primary key default.

In this case schema dumper wasn't able to correctly reconstruct
create_table statement and lost primary key constraint on schema load.

Fixes #16111.
@Envek
Copy link
Contributor Author

Envek commented Jul 14, 2014

I've squashed it few days ago, is there anything I should to do yet?

matthewd added a commit that referenced this pull request Jul 14, 2014
Dump PostgreSQL primary key with custom function as a default.
@matthewd matthewd merged commit defc680 into rails:master Jul 14, 2014
@matthewd
Copy link
Member

Thanks -- there's no notification when it's updated

@Envek
Copy link
Contributor Author

Envek commented Jul 14, 2014

Thanks, will know about notification absense in future.

Can I backport this pull request in 4-1-stable?

matthewd added a commit that referenced this pull request Jul 14, 2014
Dump PostgreSQL primary key with custom function as a default.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/adapters/postgresql/uuid_test.rb
@matthewd
Copy link
Member

Done: 136cbca

@Envek Envek deleted the fix_16111 branch July 23, 2014 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema dumper does not correctly dump UUID primary keys (when using pgcrypto extension)
4 participants