Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## About the changes This is a raw but working test for up and down migrations. In the first commit (before Andreas' fix: #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
- Loading branch information
1 parent
eb07599
commit 059b43f
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |