kysely-migration-cli
kysely-migration-cli copied to clipboard
Run migration on dev and test env
I would like to migrate both dev and test database at the same time but I can't figure out a way to make it work. Here is my take:
import * as path from 'path';
import { promises as fs } from 'fs';
import { Pool } from 'pg';
import { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely';
import { run } from 'kysely-migration-cli';
const migrationFolder = path.join(__dirname, './migrations');
if (!!process.env.DATABASE_URL) {
const db = new Kysely<any>({
dialect: new PostgresDialect({
pool: new Pool({
connectionString: process.env.DATABASE_URL,
}),
}),
});
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder,
}),
});
console.log('Running development migrations...');
run(db, migrator, migrationFolder);
db.destroy();
} else {
console.log('No dev database url. Skipping...');
}
if (!!process.env.TEST_DATABASE_URL) {
const test_db = new Kysely<any>({
dialect: new PostgresDialect({
pool: new Pool({
connectionString: process.env.TEST_DATABASE_URL,
}),
}),
});
const test_migrator = new Migrator({
db: test_db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder,
}),
});
console.log('Running test migrations...');
run(test_db, test_migrator, migrationFolder);
test_db.destroy();
} else {
console.log('No test database. Skipping...');
}
It does run twice but always on the first database, not the second. Is there a way to do this ? Thanks !