2021-09-10 11:42:11 +02:00
|
|
|
import { log } from 'db-migrate-shared';
|
|
|
|
import { getInstance } from 'db-migrate';
|
|
|
|
import { IUnleashConfig } from './lib/types/option';
|
2021-11-02 15:13:46 +01:00
|
|
|
import { secondsToMilliseconds } from 'date-fns';
|
2021-09-10 11:42:11 +02:00
|
|
|
|
|
|
|
log.setLogLevel('error');
|
|
|
|
|
|
|
|
export async function migrateDb({ db }: IUnleashConfig): Promise<void> {
|
2021-11-02 15:13:46 +01:00
|
|
|
const custom = {
|
|
|
|
...db,
|
|
|
|
connectionTimeoutMillis: secondsToMilliseconds(10),
|
|
|
|
};
|
2021-09-10 11:42:11 +02:00
|
|
|
|
|
|
|
const dbm = getInstance(true, {
|
|
|
|
cwd: __dirname,
|
|
|
|
config: { custom },
|
|
|
|
env: 'custom',
|
|
|
|
});
|
|
|
|
|
|
|
|
return dbm.up();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This exists to ease testing
|
|
|
|
export async function resetDb({ db }: IUnleashConfig): Promise<void> {
|
2021-11-02 15:13:46 +01:00
|
|
|
const custom = {
|
|
|
|
...db,
|
|
|
|
connectionTimeoutMillis: secondsToMilliseconds(10),
|
|
|
|
};
|
2021-09-10 11:42:11 +02:00
|
|
|
|
|
|
|
const dbm = getInstance(true, {
|
|
|
|
cwd: __dirname,
|
|
|
|
config: { custom },
|
|
|
|
env: 'custom',
|
|
|
|
});
|
|
|
|
|
|
|
|
return dbm.reset();
|
|
|
|
}
|