Skip to content

Commit

Permalink
Resolve migrations and seeds relatively to knexfile directory (#2959)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored and elhigu committed Dec 17, 2018
1 parent 6dbe503 commit 02e327c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug fixes:

- @babel/polyfill loaded multiple times #2955
- Resolve migrations and seeds relatively to knexfile directory when specified (the way it used to be before 0.16.1) #2952

# 0.16.2 - 10 Dec, 2018

Expand Down
2 changes: 2 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function initKnex(env, opts) {
// If knexfile is specified
else {
const resolvedKnexfilePath = path.resolve(opts.knexfile);
const knexfileDir = path.dirname(resolvedKnexfilePath);
process.chdir(knexfileDir);
env.configuration = require(resolvedKnexfilePath);

if (!env.configuration) {
Expand Down
12 changes: 12 additions & 0 deletions test/jake-util/knexfile-relative/knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
client: 'sqlite3',
connection: {
filename: __dirname + '/../test.sqlite3',
},
migrations: {
directory: './knexfile_migrations',
},
seeds: {
directory: './knexfile_seeds',
},
};
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions test/jake/jakelib/knexfile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ test(taskList, 'Run migrations with knexfile passed', (temp) => {
);
});

test(taskList, 'Resolves migrations relatively to knexfile', (temp) => {
return assertExec(
`node ${KNEX} migrate:latest --knexfile=test/jake-util/knexfile-relative/knexfile.js --knexpath=../knex.js`
);
});

test(taskList, 'Throws informative error when no knexfile is found', (temp) => {
return assertExecError(
`node ${KNEX} migrate:latest --knexpath=../knex.js`
Expand Down

0 comments on commit 02e327c

Please sign in to comment.