@@ -21,17 +21,21 @@ import fs from 'fs';
|
||||
const migrationsDir = `${__dirname}/../../migrations`;
|
||||
const migrationsFiles = fs.readdirSync(migrationsDir).sort();
|
||||
|
||||
async function migrateOnce(knex: Knex): Promise<void> {
|
||||
async function migrateUpOnce(knex: Knex): Promise<void> {
|
||||
await knex.migrate.up({ directory: migrationsDir });
|
||||
}
|
||||
|
||||
async function migrateDownOnce(knex: Knex): Promise<void> {
|
||||
await knex.migrate.down({ directory: migrationsDir });
|
||||
}
|
||||
|
||||
async function migrateUntilBefore(knex: Knex, target: string): Promise<void> {
|
||||
const index = migrationsFiles.indexOf(target);
|
||||
if (index === -1) {
|
||||
throw new Error(`Migration ${target} not found`);
|
||||
}
|
||||
for (let i = 0; i < index; i++) {
|
||||
await migrateOnce(knex);
|
||||
await migrateUpOnce(knex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +78,7 @@ describe('migrations', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
await knex.migrate.up({ directory: migrationsDir });
|
||||
await migrateUpOnce(knex);
|
||||
|
||||
await expect(knex('search')).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
@@ -83,6 +87,15 @@ describe('migrations', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
await migrateDownOnce(knex);
|
||||
|
||||
await expect(knex('search')).resolves.toEqual(
|
||||
expect.arrayContaining([
|
||||
{ entity_id: 'i', key: 'k1', value: 'v1' },
|
||||
{ entity_id: 'i', key: 'k2', value: null },
|
||||
]),
|
||||
);
|
||||
|
||||
await knex.destroy();
|
||||
},
|
||||
60_000,
|
||||
|
||||
Reference in New Issue
Block a user