Created
July 9, 2014 19:45
-
-
Save Envek/0580865d6fea8df7374b to your computer and use it in GitHub Desktop.
ActiveRecord::SchemaDumper does not correctly dump UUID primary keys (when you use not uuid-ossp but pgcrypto)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'rack', github: 'rack/rack' | |
gem 'pg' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
require 'active_support/all' | |
require 'minitest/autorun' | |
require 'logger' | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'test', user: 'postgres') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
enable_extension 'pgcrypto' | |
drop_table :foos if table_exists?(:foos) | |
create_table :foos, id: :uuid, default: 'gen_random_uuid()' | |
end | |
class Foo < ActiveRecord::Base | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
schema_io = StringIO.new | |
ActiveRecord::SchemaDumper.dump(Foo.connection, schema_io) | |
schema_io.seek(0) | |
schema = schema_io.read | |
assert_equal 'id', Foo.connection.primary_key('foos') | |
assert_equal ['id', nil], Foo.connection.pk_and_sequence_for('foos') | |
assert_match /primary_key: true/, schema | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment