tj / node-migrate

Abstract migration framework for node
MIT License
1.53k stars 221 forks source link

How to specify path to migrations directory relative to source code (not working directory)? #190

Closed TobiasUhmann closed 2 years ago

TobiasUhmann commented 2 years ago

In my code, I run migrations programmatically via migrate.load(). The source file that calls migrate.load() lies in the project's root directory - next to the migrations folder. When I start the app via npm start from the project root directory during development everything works fine.

However, when packaging the app and running it in another directory via npx or running the app after having been installed globally via npm install -g, it breaks because it cannot find the migrations directory.

Apparently, migrate.load() is looking for the migrations folder relative to the working directory. How can I tell migrate.load() to look relative to its source file so that I can run my app from another directory?

TobiasUhmann commented 2 years ago

Ok, I took the obvious way of getting the file's directory now by passing {migrationsDirectory: path.resolve(__dirname, 'migrations/')} to migrate.load(). But I think migrate.load() should do that itself.