mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
chore: migrations test (#3590)
## About the changes This is a raw but working test for up and down migrations. In the first commit (before Andreas' fix: https://github.com/Unleash/unleash/pull/3589) [it catches the migration errors we found](https://github.com/Unleash/unleash/actions/runs/4766567308/jobs/8473744864?pr=3590#step:5:605). After merging from main the test go green, proving that it can catch these issues earlier
This commit is contained in:
parent
eb07599612
commit
059b43ffaa
@ -99,8 +99,7 @@ export default async function init(
|
||||
|
||||
await db.raw(`DROP SCHEMA IF EXISTS ${config.db.schema} CASCADE`);
|
||||
await db.raw(`CREATE SCHEMA IF NOT EXISTS ${config.db.schema}`);
|
||||
// @ts-expect-error
|
||||
await migrateDb({ ...config, databaseSchema: config.db.schema });
|
||||
await migrateDb(config);
|
||||
await db.destroy();
|
||||
const testDb = createDb(config);
|
||||
const stores = await createStores(config, testDb);
|
||||
|
40
src/test/e2e/migrator.e2e.test.ts
Normal file
40
src/test/e2e/migrator.e2e.test.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { getDbConfig } from './helpers/database-config';
|
||||
import { createTestConfig } from '../config/test-config';
|
||||
import { getInstance } from 'db-migrate';
|
||||
import { Client } from 'pg';
|
||||
import { IDBOption } from 'lib/types';
|
||||
|
||||
async function initSchema(db: IDBOption): Promise<void> {
|
||||
const client = new Client(db);
|
||||
await client.connect();
|
||||
await client.query(`DROP SCHEMA IF EXISTS ${db.schema} CASCADE`);
|
||||
await client.query(`CREATE SCHEMA IF NOT EXISTS ${db.schema}`);
|
||||
await client.end();
|
||||
}
|
||||
|
||||
test('Up & down migrations work', async () => {
|
||||
const config = createTestConfig({
|
||||
db: {
|
||||
...getDbConfig(),
|
||||
pool: { min: 1, max: 4 },
|
||||
schema: 'up_n_down_migrations_test',
|
||||
ssl: false,
|
||||
},
|
||||
});
|
||||
|
||||
await initSchema(config.db);
|
||||
|
||||
const e2e = {
|
||||
...config.db,
|
||||
connectionTimeoutMillis: 2000,
|
||||
};
|
||||
|
||||
const dbm = getInstance(true, {
|
||||
cwd: `${__dirname}/../../`, // relative to src/test/e2e
|
||||
config: { e2e },
|
||||
env: 'e2e',
|
||||
});
|
||||
|
||||
await dbm.up();
|
||||
await dbm.reset();
|
||||
});
|
Loading…
Reference in New Issue
Block a user