Last active
May 2, 2019 07:45
-
-
Save stevehill1981/12a58fc0203a95f32a3bcd19aa50950e to your computer and use it in GitHub Desktop.
This file contains 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem 'rails', '~> 5.2', '>= 5.2.3' | |
gem "pg" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
`dropdb rails5_references_uuid_bug; createdb rails5_references_uuid_bug` | |
# Have to use PostgreSQL here, as the problem does not exist in SQLite. | |
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "rails5_references_uuid_bug") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
end | |
class EnableUuidExtension < ActiveRecord::Migration[5.2] | |
def change | |
enable_extension 'pgcrypto' | |
end | |
end | |
class CreateAuthors < ActiveRecord::Migration[5.2] | |
def change | |
create_table :authors, id: :uuid do |t| | |
t.string :first_name | |
t.string :last_name | |
t.timestamps | |
end | |
end | |
end | |
class CreateBooks < ActiveRecord::Migration[5.2] | |
def change | |
create_table :books, id: :uuid do |t| | |
t.string :title | |
t.references :author, foreign_key: true | |
t.timestamps | |
end | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_migration_up | |
EnableUuidExtension.migrate(:up) | |
CreateAuthors.migrate(:up) | |
CreateBooks.migrate(:up) | |
end | |
end |
This file contains 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
gem "pg" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
`dropdb rails6_references_uuid_bug; createdb rails6_references_uuid_bug` | |
# Have to use PostgreSQL here, as the problem does not exist in SQLite. | |
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "rails6_references_uuid_bug") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
end | |
class EnableUuidExtension < ActiveRecord::Migration[6.0] | |
def change | |
enable_extension 'pgcrypto' | |
end | |
end | |
class CreateAuthors < ActiveRecord::Migration[6.0] | |
def change | |
create_table :authors, id: :uuid do |t| | |
t.string :first_name | |
t.string :last_name | |
t.timestamps | |
end | |
end | |
end | |
class CreateBooks < ActiveRecord::Migration[6.0] | |
def change | |
create_table :books, id: :uuid do |t| | |
t.string :title | |
t.references :author, foreign_key: true | |
t.timestamps | |
end | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_migration_up | |
EnableUuidExtension.migrate(:up) | |
CreateAuthors.migrate(:up) | |
CreateBooks.migrate(:up) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist contains executable bug reports for both Rails 5.2.3 and Rails 6 master.
A working PostgreSQL installation is required; the necessary databases will be created as part of each script.