Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature Request: .mjs (es module) migrations and seeds (no cli) #3850
Comments
|
Sorry if I'm missing something :) import knex from 'knex';
// const db = app.context.db = knex({ client: "sqlite", connection: "./knex-mjs.sqlite" });
const db = knex({
client: "sqlite3",
connection: {
filename: "./knex-mjs.sqlite"
},
migrations: { // important!
loadExtensions: [".mjs"],
},
useNullAsDefault: true
});
db.migrate.latest({
extension: 'mjs',
directory: 'db/migrations',
}).then(() => {
console.log("done")
process.exit()
}).catch(e => {
console.error(e);
process.exit(1)
})
|
|
Thanks! I didn't realize I had to specify the extension of my migration files twice... or maybe the "extension:" key is not needed? I find it really strange that the I suggest either:
or
|
|
Yes, Its not very intuitive, I think. |


Environment
Knex version: 0.21.1
OS: docker node:latest
I'd like to be able to write my migrations (and seed) files as es modules with the .mjs file extension like I'm doing with all my other javascript files.
I'd like to be able to run these migrations from within node (not via the cli) like this:
Ditto for seed files.
Thanks!