Skip to content

Make status command find migrations in subdirectories#367

Merged
vprigent merged 1 commit intoilyakatz:mainfrom
arzezak:migration-subpaths
Nov 7, 2025
Merged

Make status command find migrations in subdirectories#367
vprigent merged 1 commit intoilyakatz:mainfrom
arzezak:migration-subpaths

Conversation

@arzezak
Copy link
Contributor

@arzezak arzezak commented Nov 6, 2025

Previously, db:migrate:status:with_data used Dir.foreach and Dir.children, which only scan the top-level migration directory. As a result, archived migrations placed in subdirectories (e.g., db/migrate/archive/) appeared as "*** NO SCHEMA FILE ***" even though they existed in the database.

The fix switches to Dir.glob with a recursive **/*.rb pattern and then filters by matching file basenames against /(\d{14})_(.+)\\.rb/, enabling the command to find migrations in nested directories and correctly report their status.

This ensures that migrations stored anywhere under the migration paths are recognized and displayed accurately in the status output.

Before:

~/Project (main) % bundle exec rake db:migrate:status | grep 20210323133030
   up     20210323133030  Create resource
~/Project (main) % bundle exec rake db:migrate:status:with_data | grep 20210323133030
   up     20210323133030  *** NO SCHEMA FILE ***```

After:

~/Project (main) % bundle exec rake db:migrate:status | grep 20210323133030
   up     20210323133030  Create resource
~/Project (main|!|+) % bundle exec rake db:migrate:status:with_data | grep 20210323133030
   up     schema  20210323133030  Create resource

Previously, `db:migrate:status:with_data` used `Dir.foreach` and
`Dir.children`, which only scan the top-level migration directory. As a
result, archived migrations placed in subdirectories (e.g.,
`db/migrate/archive/`) appeared as "*** NO SCHEMA FILE ***" even though
they existed in the database.

The fix switches to `Dir.glob` with a recursive `**/*.rb` pattern and
then filters by matching file basenames against `/(\d{14})_(.+)\\.rb/`,
enabling the command to find migrations in nested directories and
correctly report their status.

This ensures that migrations stored anywhere under the migration paths
are recognized and displayed accurately in the status output.

Before:

```
~/Project (main) % bundle exec rake db:migrate:status | grep 20210323133030
   up     20210323133030  Create resource
~/Project (main) % bundle exec rake db:migrate:status:with_data | grep 20210323133030
   up     20210323133030  *** NO SCHEMA FILE ***```
```

After:

```
~/Project (main) % bundle exec rake db:migrate:status | grep 20210323133030
   up     20210323133030  Create resource
~/Project (main|!|+) % bundle exec rake db:migrate:status:with_data | grep 20210323133030
   up     schema  20210323133030  Create resource
```
@vprigent
Copy link
Collaborator

vprigent commented Nov 7, 2025

Thank you!

@vprigent vprigent merged commit 5865ad5 into ilyakatz:main Nov 7, 2025
20 checks passed
@arzezak arzezak deleted the migration-subpaths branch November 11, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants