feat: ignore unrelated files in migration directory#28
Open
basti1302 wants to merge 1 commit intoboujeepossum:masterfrom
Open
feat: ignore unrelated files in migration directory#28basti1302 wants to merge 1 commit intoboujeepossum:masterfrom
basti1302 wants to merge 1 commit intoboujeepossum:masterfrom
Conversation
Also, provide a useful message when the a migration files does not
match the naming scheme.
This fixes
ERROR: TypeError: Cannot read properties of null (reading '0')
at /path/to/project/node_modules/sql-migrations/commands/run-migrations-command.js:36:43
when the migration folder contains a file that does not comply withthe
naming pattern.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the migration directory contains additional files,
sql-migrationsaborts with a rather cryptic error:The reason is twofold:
migration-provider.jsreturns all files in the migration directory (the result offs.readdirunconditionally and unfiltered.commands/run-migrations-command.jsmatches on the file name to extract the migration ID/timestamp and has no check if there is a match or not, it just uses the first match unconditionally.This is especially annoying when working on migrations with editors that create a temporary file in the current directory, like vim does (vim automatically creates
.1662812614706_up_my_migration.sql.swpwhen working on1662812614706_up_my_migration.sqlin the same directory). There might be other editors with similar behavior.The fix in this change is also twofold:
migration-provider.jsnow filters on files that end with.sqland will ignore other files. This might be debatable. Do people also use other file formats/suffixes? I am fine with dropping this change if you feel this is too restrictive.commands/run-migrations-command.jsnow checks if there is actually a match and prints a useful warning about the file that didn't match the expected pattern. Even with the first fix inmigration-provider.jsin place, this is still useful if there is an.sqlfile in the directory that does not match the expected file name pattern.