Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevehill1981/12a58fc0203a95f32a3bcd19aa50950e to your computer and use it in GitHub Desktop.
Save stevehill1981/12a58fc0203a95f32a3bcd19aa50950e to your computer and use it in GitHub Desktop.
# 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
# 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
@stevehill1981
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment