db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

db-migrate version 1.0 fails with "cannot find module" when migration directory is not the standard one #720

Closed vladimirtiukhtin closed 3 years ago

vladimirtiukhtin commented 3 years ago

I'm submitting a...

Current behavior

My command line is

db-migrate -m test -e test up

While version 0.11.11 works fine, version 1.0.0-beta.13 fails with

[ERROR] unhandledRejection
[ERROR] Error: Cannot find module 'test/20201217180525-init.js'
Require stack:
- /opt/node_modules/db-migrate/lib/file.js
- /opt/node_modules/db-migrate/lib/commands/helper/migration-hook.js
- /opt/node_modules/db-migrate/lib/commands/up.js
- /opt/node_modules/db-migrate/lib/commands/index.js
- /opt/node_modules/db-migrate/api.js
- /opt/node_modules/db-migrate/index.js
- /usr/local/lib/node_modules/db-migrate/bin/db-migrate
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at File.get (/opt/node_modules/db-migrate/lib/file.js:84:48)
    at /opt/node_modules/db-migrate/lib/walker.js:185:28
    at tryCatcher (/opt/node_modules/bluebird/js/release/util.js:16:23)
    at Object.gotValue (/opt/node_modules/bluebird/js/release/reduce.js:166:18)
    at Object.gotAccum (/opt/node_modules/bluebird/js/release/reduce.js:155:25)
    at Object.tryCatcher (/opt/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/opt/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/opt/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromiseCtx (/opt/node_modules/bluebird/js/release/promise.js:641:10)
    at _drainQueueStep (/opt/node_modules/bluebird/js/release/async.js:97:12)
    at _drainQueue (/opt/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/opt/node_modules/bluebird/js/release/async.js:102:5)

Renaming folder back to "migrations" makes it work, but down migration fails anyway with

[ERROR] Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key = '__dbmigrate_state__'' at line 3

Expected behavior

Same as 0.11.11, just work

Minimal reproduction of the problem with instructions

Create migrations in non-standard folder, specify it using "-m" flag

Environment


db-migrate version: 1.0.0-beta.13

Additional information:
- Node version: v14.15.3
- Platform:  Alpine Linux v3.11
wzrdtales commented 3 years ago

thank you for reporting! fix will come shortly