Created
April 27, 2016 18:35
-
-
Save jrafanie/4c88ca09b170feadadb686f421ed548b to your computer and use it in GitHub Desktop.
WAT cached column on join
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
| begin | |
| require 'bundler/inline' | |
| rescue LoadError => e | |
| $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
| raise e | |
| end | |
| gemfile(true) do | |
| source 'https://rubygems.org' | |
| # gem 'sqlite3' | |
| gem 'pg' | |
| gem 'rails', "~>4.2.x" | |
| # BELOW IS FOR RAILS MASTER | |
| # gem 'rails', github: 'rails/rails' | |
| # gem 'arel', github: 'rails/arel' | |
| # gem 'rack', github: 'rack/rack' | |
| # gem 'sprockets', github: 'rails/sprockets' | |
| # gem 'sprockets-rails', github: 'rails/sprockets-rails' | |
| # gem 'sass-rails', github: 'rails/sass-rails' | |
| end | |
| require 'active_record' | |
| require 'logger' | |
| ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'activerecord_unittest') | |
| # ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
| ActiveRecord::Base.logger = Logger.new(STDOUT) | |
| one = <<-EOF | |
| class Migration1 < ActiveRecord::Migration | |
| def change | |
| create_table :groups, force: true do |t| | |
| t.string :filter | |
| end | |
| create_table :entitlements, force: true do |t| | |
| t.belongs_to :group | |
| t.string :other | |
| end | |
| end | |
| end | |
| EOF | |
| two = <<-EOF | |
| class Migration2 < ActiveRecord::Migration | |
| class Group < ActiveRecord::Base | |
| has_one :entitlement, :class_name => "Migration2::Entitlement" | |
| end | |
| class Entitlement < ActiveRecord::Base; end; | |
| def change | |
| Group.create!(:entitlement => Entitlement.create!) | |
| Group.create!(:entitlement => Entitlement.create!) | |
| end | |
| end | |
| EOF | |
| three = <<-EOF | |
| class Migration3 < ActiveRecord::Migration | |
| def change | |
| add_column :entitlements, :filter, :string | |
| remove_column :groups, :filter, :string | |
| end | |
| end | |
| EOF | |
| four = <<-EOF | |
| class Migration4 < ActiveRecord::Migration | |
| class Group < ActiveRecord::Base | |
| has_many :entitlement, :class_name => "Migration4::Entitlement" | |
| end | |
| class Entitlement < ActiveRecord::Base | |
| belongs_to :group, :class_name => "Migration4::Group" | |
| end | |
| def up | |
| # BELOW FIXES IT | |
| # Group.reset_column_information | |
| Group.includes(:entitlement).where(:entitlements => { :other => nil }).all.to_a | |
| end | |
| def down | |
| Group.includes(:entitlement).where(:entitlements => { :other => nil }).all.to_a | |
| end | |
| end | |
| EOF | |
| File.write("./20160427143821_migration1.rb", one) | |
| File.write("./20160427143822_migration2.rb", two) | |
| File.write("./20160427143823_migration3.rb", three) | |
| File.write("./20160427143824_migration4.rb", four) | |
| begin | |
| ActiveRecord::Migrator.migrate('./') | |
| ensure | |
| ActiveRecord::Migrator.migrate('./', 0) | |
| FileUtils.rm_f("./20160427143821_migration1.rb") | |
| FileUtils.rm_f("./20160427143822_migration2.rb") | |
| FileUtils.rm_f("./20160427143823_migration3.rb") | |
| FileUtils.rm_f("./20160427143824_migration4.rb") | |
| end |
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
| Fetching gem metadata from https://rubygems.org/........... | |
| Fetching version metadata from https://rubygems.org/... | |
| Fetching dependency metadata from https://rubygems.org/.. | |
| Resolving dependencies... | |
| Using rake 11.1.2 | |
| Using i18n 0.7.0 | |
| Using json 1.8.3 | |
| Using minitest 5.8.4 | |
| Using thread_safe 0.3.5 | |
| Using builder 3.2.2 | |
| Using erubis 2.7.0 | |
| Using mini_portile2 2.0.0 | |
| Using rack 1.6.4 | |
| Using mime-types-data 3.2016.0221 | |
| Using arel 6.0.3 | |
| Using bundler 1.11.2 | |
| Using concurrent-ruby 1.0.1 | |
| Using pg 0.18.4 | |
| Using thor 0.19.1 | |
| Using tzinfo 1.2.2 | |
| Using nokogiri 1.6.7.2 | |
| Using rack-test 0.6.3 | |
| Using mime-types 3.0 | |
| Using sprockets 3.6.0 | |
| Using activesupport 4.2.6 | |
| Using loofah 2.0.3 | |
| Using mail 2.6.4 | |
| Using rails-deprecated_sanitizer 1.0.3 | |
| Using globalid 0.3.6 | |
| Using activemodel 4.2.6 | |
| Using rails-html-sanitizer 1.0.3 | |
| Using rails-dom-testing 1.0.7 | |
| Using activejob 4.2.6 | |
| Using activerecord 4.2.6 | |
| Using actionview 4.2.6 | |
| Using actionpack 4.2.6 | |
| Using actionmailer 4.2.6 | |
| Using railties 4.2.6 | |
| Using sprockets-rails 3.0.4 | |
| Using rails 4.2.6 | |
| D, [2016-04-27T14:30:27.183625 #26224] DEBUG -- : ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations" | |
| I, [2016-04-27T14:30:27.186675 #26224] INFO -- : Migrating to Migration1 (20160427143821) | |
| D, [2016-04-27T14:30:27.187242 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143821 Migration1: migrating ======================================= | |
| -- create_table(:groups, {:force=>true}) | |
| D, [2016-04-27T14:30:27.193368 #26224] DEBUG -- : (4.5ms) CREATE TABLE "groups" ("id" serial primary key, "filter" character varying) | |
| -> 0.0060s | |
| -- create_table(:entitlements, {:force=>true}) | |
| D, [2016-04-27T14:30:27.198183 #26224] DEBUG -- : (3.9ms) CREATE TABLE "entitlements" ("id" serial primary key, "group_id" integer, "other" character varying) | |
| -> 0.0047s | |
| == 20160427143821 Migration1: migrated (0.0109s) ============================== | |
| D, [2016-04-27T14:30:27.204189 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20160427143821"]] | |
| D, [2016-04-27T14:30:27.204738 #26224] DEBUG -- : (0.4ms) COMMIT | |
| I, [2016-04-27T14:30:27.204780 #26224] INFO -- : Migrating to Migration2 (20160427143822) | |
| D, [2016-04-27T14:30:27.206705 #26224] DEBUG -- : (0.3ms) BEGIN | |
| == 20160427143822 Migration2: migrating ======================================= | |
| D, [2016-04-27T14:30:27.212023 #26224] DEBUG -- : SQL (0.4ms) INSERT INTO "entitlements" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.218507 #26224] DEBUG -- : SQL (0.6ms) INSERT INTO "groups" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.221921 #26224] DEBUG -- : SQL (0.3ms) UPDATE "entitlements" SET "group_id" = $1 WHERE "entitlements"."id" = $2 [["group_id", 1], ["id", 1]] | |
| D, [2016-04-27T14:30:27.222672 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "entitlements" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.223352 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "groups" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.224014 #26224] DEBUG -- : SQL (0.2ms) UPDATE "entitlements" SET "group_id" = $1 WHERE "entitlements"."id" = $2 [["group_id", 2], ["id", 2]] | |
| == 20160427143822 Migration2: migrated (0.0174s) ============================== | |
| D, [2016-04-27T14:30:27.225302 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20160427143822"]] | |
| D, [2016-04-27T14:30:27.225718 #26224] DEBUG -- : (0.3ms) COMMIT | |
| I, [2016-04-27T14:30:27.225757 #26224] INFO -- : Migrating to Migration3 (20160427143823) | |
| D, [2016-04-27T14:30:27.227502 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143823 Migration3: migrating ======================================= | |
| -- add_column(:entitlements, :filter, :string) | |
| D, [2016-04-27T14:30:27.228256 #26224] DEBUG -- : (0.4ms) ALTER TABLE "entitlements" ADD "filter" character varying | |
| -> 0.0007s | |
| -- remove_column(:groups, :filter, :string) | |
| D, [2016-04-27T14:30:27.228849 #26224] DEBUG -- : (0.5ms) ALTER TABLE "groups" DROP "filter" | |
| -> 0.0006s | |
| == 20160427143823 Migration3: migrated (0.0013s) ============================== | |
| D, [2016-04-27T14:30:27.230090 #26224] DEBUG -- : SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20160427143823"]] | |
| D, [2016-04-27T14:30:27.230487 #26224] DEBUG -- : (0.3ms) COMMIT | |
| I, [2016-04-27T14:30:27.230526 #26224] INFO -- : Migrating to Migration4 (20160427143824) | |
| D, [2016-04-27T14:30:27.233841 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143824 Migration4: migrating ======================================= | |
| D, [2016-04-27T14:30:27.240075 #26224] DEBUG -- : SQL (0.4ms) SELECT "groups"."id" AS t0_r0, "groups"."filter" AS t0_r1, "entitlements"."id" AS t1_r0, "entitlements"."group_id" AS t1_r1, "entitlements"."other" AS t1_r2 FROM "groups" LEFT OUTER JOIN "entitlements" ON "entitlements"."group_id" = "groups"."id" WHERE "entitlements"."other" IS NULL | |
| D, [2016-04-27T14:30:27.240301 #26224] DEBUG -- : (0.1ms) ROLLBACK | |
| D, [2016-04-27T14:30:27.241357 #26224] DEBUG -- : ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" | |
| D, [2016-04-27T14:30:27.242672 #26224] DEBUG -- : ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" | |
| D, [2016-04-27T14:30:27.244293 #26224] DEBUG -- : ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" | |
| I, [2016-04-27T14:30:27.244436 #26224] INFO -- : Migrating to Migration3 (20160427143823) | |
| D, [2016-04-27T14:30:27.244643 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143823 Migration3: reverting ======================================= | |
| -- add_column(:groups, :filter, :string) | |
| D, [2016-04-27T14:30:27.246661 #26224] DEBUG -- : (0.3ms) ALTER TABLE "groups" ADD "filter" character varying | |
| -> 0.0005s | |
| -- remove_column(:entitlements, :filter, :string) | |
| D, [2016-04-27T14:30:27.247041 #26224] DEBUG -- : (0.3ms) ALTER TABLE "entitlements" DROP "filter" | |
| -> 0.0004s | |
| == 20160427143823 Migration3: reverted (0.0024s) ============================== | |
| D, [2016-04-27T14:30:27.248107 #26224] DEBUG -- : SQL (0.2ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = $1 [["version", "20160427143823"]] | |
| D, [2016-04-27T14:30:27.248474 #26224] DEBUG -- : (0.3ms) COMMIT | |
| I, [2016-04-27T14:30:27.248515 #26224] INFO -- : Migrating to Migration2 (20160427143822) | |
| D, [2016-04-27T14:30:27.248718 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143822 Migration2: reverting ======================================= | |
| D, [2016-04-27T14:30:27.249532 #26224] DEBUG -- : SQL (0.3ms) INSERT INTO "entitlements" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.250487 #26224] DEBUG -- : SQL (0.3ms) INSERT INTO "groups" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.251396 #26224] DEBUG -- : SQL (0.2ms) UPDATE "entitlements" SET "group_id" = $1 WHERE "entitlements"."id" = $2 [["group_id", 3], ["id", 3]] | |
| D, [2016-04-27T14:30:27.252069 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "entitlements" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.252841 #26224] DEBUG -- : SQL (0.2ms) INSERT INTO "groups" DEFAULT VALUES RETURNING "id" | |
| D, [2016-04-27T14:30:27.253669 #26224] DEBUG -- : SQL (0.2ms) UPDATE "entitlements" SET "group_id" = $1 WHERE "entitlements"."id" = $2 [["group_id", 4], ["id", 4]] | |
| == 20160427143822 Migration2: reverted (0.0050s) ============================== | |
| D, [2016-04-27T14:30:27.254261 #26224] DEBUG -- : SQL (0.2ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = $1 [["version", "20160427143822"]] | |
| D, [2016-04-27T14:30:27.254674 #26224] DEBUG -- : (0.3ms) COMMIT | |
| I, [2016-04-27T14:30:27.254710 #26224] INFO -- : Migrating to Migration1 (20160427143821) | |
| D, [2016-04-27T14:30:27.254949 #26224] DEBUG -- : (0.1ms) BEGIN | |
| == 20160427143821 Migration1: reverting ======================================= | |
| -- drop_table(:entitlements, {:force=>true}) | |
| D, [2016-04-27T14:30:27.256350 #26224] DEBUG -- : (1.2ms) DROP TABLE "entitlements" | |
| -> 0.0013s | |
| -- drop_table(:groups, {:force=>true}) | |
| D, [2016-04-27T14:30:27.257451 #26224] DEBUG -- : (1.0ms) DROP TABLE "groups" | |
| -> 0.0011s | |
| == 20160427143821 Migration1: reverted (0.0025s) ============================== | |
| D, [2016-04-27T14:30:27.257905 #26224] DEBUG -- : SQL (0.2ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = $1 [["version", "20160427143821"]] | |
| D, [2016-04-27T14:30:27.259541 #26224] DEBUG -- : (1.6ms) COMMIT | |
| /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec': An error has occurred, this and all later migrations canceled: (StandardError) | |
| PG::UndefinedColumn: ERROR: column groups.filter does not exist | |
| LINE 1: SELECT "groups"."id" AS t0_r0, "groups"."filter" AS t0_r1, "... | |
| ^ | |
| : SELECT "groups"."id" AS t0_r0, "groups"."filter" AS t0_r1, "entitlements"."id" AS t1_r0, "entitlements"."group_id" AS t1_r1, "entitlements"."other" AS t1_r2 FROM "groups" LEFT OUTER JOIN "entitlements" ON "entitlements"."group_id" = "groups"."id" WHERE "entitlements"."other" IS NULL | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:356:in `select' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/relation/finder_methods.rb:356:in `find_with_associations' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/relation.rb:639:in `exec_queries' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/relation.rb:515:in `load' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/relation.rb:243:in `to_a' | |
| from /Users/joerafaniello/Code/projects/cached_column_information/20160427143824_migration4.rb:13:in `up' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:611:in `exec_migration' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:592:in `block (2 levels) in migrate' | |
| from /Users/joerafaniello/.rubies/ruby-2.2.4/lib/ruby/2.2.0/benchmark.rb:288:in `measure' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:591:in `block in migrate' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:590:in `migrate' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:768:in `migrate' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:998:in `block in execute_migration_in_transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:1044:in `block in ddl_transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/transactions.rb:220:in `transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:1044:in `ddl_transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:997:in `execute_migration_in_transaction' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:959:in `block in migrate' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:955:in `each' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:955:in `migrate' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:823:in `up' | |
| from /Users/joerafaniello/.gem/ruby/2.2.4/gems/activerecord-4.2.6/lib/active_record/migration.rb:801:in `migrate' | |
| from test.rb:98:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment