Skip to content

Instantly share code, notes, and snippets.

@dolphorama
Last active April 18, 2017 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolphorama/9760138887e2df5c520a31646d3ebd54 to your computer and use it in GitHub Desktop.
Save dolphorama/9760138887e2df5c520a31646d3ebd54 to your computer and use it in GitHub Desktop.

Hello!

I'm having some issues with migrations and schemas when moving from Rails 4.2 to 5.02. My migration files are split up into two places one in the default location db/migrate and also in another location for db/shards/migrate. When running migrations I am setting:

ActiveRecord::Tasks::DatabaseTasks.migrations_paths = ["db/shards/migrate"]

Everything within db/migrate is working properly.

When running migrations under db/shards/migrate, the schema.rb is not being written properly. Specifically, all columns are being set as null: false, and when creating the indexes base on the new format, none of the columns are being set on the index. As an example:

# Previous
add_index "notes", ["user_id"], name: "index_notes_on_user_id", using: :btree
#Updated
t.index [], name: "index_notes_on_user_id", unique: true, using: :btree

There is one other strange occurance that may be a useful datapoint. I had been getting errors from the SchemaDumper based on PostreSQL::SchemaStatements.indexes. The count from this subquery (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L102) which was being set here (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L123) was returning the count as "0" rather than 0. This caused an error here (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L123) due to trying to compare a Integer to a String. I couldn't quite figure out why that was happening and just monkey patched opclass = row[6].to_i to avoid getting stuck.

I'm not sure what that second issue has to do with, but just thought I should throw it out there as another symptom.

I've been banging my head against this for a while and would love any suggestion any person may have.

Thanks!

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