Open whitte-h opened 5 years ago
I don't quite understand what are you after... why do you have to give --cwd
there and not only --migrations-directory users/migrations
.
Closing as this sounds like knex usage question and github issue tracker should not be used for that. Can be reopened if there is a knex bug involved.
I don't quite understand what are you after... why do you have to give
--cwd
there and not only--migrations-directory users/migrations
.Closing as this sounds like knex usage question and github issue tracker should not be used for that. Can be reopened if there is a knex bug involved.
@elhigu So this is a bug, cause when I do just the command that you suggest, the migration is been created at the same level as src
in the usual migration folder, not even creating the folder users inside it
I expect that command to at least create something like:
src
migrations
-users
--my_new_migration.js
Even when I try: npx knex migrate:make create_users_table1 --migrations-directory src/entities/users/migrations
It still create the migration in the migration folder, that's the reason why I use --cwd
Sounds like a bug I suppose... should write jake test to verify this.
I specified multiple migration directories, and after run knex migrate:make create_table_name
, it always create file in the last folder in directories(migrations/DML/201901010101_create_table_name.js
).
// knex.js
module.exports = {
migrations: {
directory: ['migrations/DCL', 'migrations/DDL', 'migrations/DML']
}
}
after debugging, I find below line in knex source migrationGenerator.js
// line 65 of MigrationGenerator.js in knex source codes
_writeNewMigration(name, tmpl) {
const config = this.config;
const dirs = this._absoluteConfigDirs();
// below line will only fetch the last specified directory
const dir = dirs.slice(-1)[0]; // Get last specified directory
}
@idododu it is expected behavior that migration is created to the last of the configured migration directories. Please add feature request if you need it to work in a different manner.
You can do this:
require('dotenv').config()
module.exports = {
development: {
client: "pg",
connection: {
database : process.env.DB_NAME,
host : process.env.DB_HOST,
user : process.env.DB_USERNAME,
password : process.env.DB_PASSWORD,
},
migrations: {
directory: "src/migrations"
}
// debug: true
}
};
In my case I mistakenly named migrations key as migration in knexfile.ts. like Expected:
migrations: {
directory: './database/migrations'
},
What I had written:
migration: {
directory: './database/migrations'
},
Currently, I have this project structure: src -entities --users ---model.js ---migrations ----20190303042400_create_users_table
What I'm trying to accomplish is to have my config setted up to my entities folder, so I can do like:
npx knex migrate:make create_users_table --migrations-directory users
But I can only accomplish this by doing:
npx knex migrate:make create_users_table1 --cwd="./src/entities" --migrations-directory users/migrations
That I find very repetitive given the fact that my entities folder will never change, I tried to set a base folder route in my knex file but I didn't get to make it work, so, is it possible?