db:schema:load with migrations in subdirectories #14012

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
@d-unseductable

Getting pending migrations errors after running

$ rake db:schema:load

when db/migrate directory contains any migrations in its subdirectories.

Example directories structure:

db/
    migrate/
        archive/
            1_create_people.rb
            2_add_age_to_people.rb
        3_add_phone_number_to_people.rb

If the db/migrate directory contains any migrations in its subdirectories, their versions are not inserted into schema_migrations table.

As for the example above, ActiveRecord::ConnectionAdapters::SchemaStatements.assume_migrated_upto_version method inserts only the 3rd version into the schema_migrations table.
But ActiveRecord::Migrator.migrations method expects the table to include all of the 3 versions. 1 and 2 are perceived as pending and this fact causes the pending migrations error.

The assume_migrated_upto_version fetched migrations files using

paths = migrations_paths.map {|p| "#{p}/[0-9]*_*.rb" }

So there was no subdirectories support.
The behaviour is fixed by

paths = migrations_paths.map {|p| "#{p}/**/[0-9]*_*.rb" }

Added a test case.

@andreychernih

This comment has been minimized.

Show comment
Hide comment
@andreychernih

andreychernih Mar 27, 2015

Contributor

We're getting the same problems. Any plans to get this merged?

Contributor

andreychernih commented Mar 27, 2015

We're getting the same problems. Any plans to get this merged?

@rafaelfranca rafaelfranca self-assigned this Mar 27, 2015

@d-unseductable

This comment has been minimized.

Show comment
Hide comment
@d-unseductable

d-unseductable Apr 26, 2015

Hi @rafaelfranca !

I rebased the branch, ready to merge.

Hi @rafaelfranca !

I rebased the branch, ready to merge.

db:schema:load with migrations in subdirectories
Example directories structure:
    db/
      migrate/
        archive/
          1_create_people.rb
          2_add_age_to_people.rb
        3_add_phone_number_to_people.rb

If the db/migrate directory contains any migrations in its
subdirectories, their versions are not inserted into schema_migrations
table.

As for the example above,
ActiveRecord::ConnectionAdapters::SchemaStatements
  .assume_migrated_upto_version
method inserts only the 3rd version into the schema_migrations table.
But
ActiveRecord::Migrator.migrations
method expects the table to include all of the 3 versions. 1 and 2 are
perceived as pending and this fact causes the pending migrations error.

The assume_migrated_upto_version fetched migration files using
    paths = migrations_paths.map {|p| "#{p}/[0-9]*_*.rb" }
So there were no subdirectories support.
The behaviour is fixed by
    paths = migrations_paths.map {|p| "#{p}/**/[0-9]*_*.rb" }
Added a test case.
@kamipo

This comment has been minimized.

Show comment
Hide comment
@kamipo

kamipo Apr 26, 2017

Member

Closing since it has been fixed in #28287.

Member

kamipo commented Apr 26, 2017

Closing since it has been fixed in #28287.

@kamipo kamipo closed this Apr 26, 2017

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