Skip to content

Commit 3669a79

Browse files
author
Jesse Hallett
authored
feat: add option to getTestDatabase to skip running migrations (#5)
This is useful if you don't have TypeORM configuration in `ormconfig.js`. For example you might use `ormconfig.ts` instead. Originate-scripts currently does not have support for running a TypeScript configuration module.
1 parent 81641f9 commit 3669a79

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/getTestDatabase.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export interface Options {
99
* Docker image to run; e.g. `postgres:12`
1010
*/
1111
image?: string;
12+
13+
/**
14+
* If true, connect and run migrations according to configuration in `ormconfig.js`
15+
*/
16+
runMigrations?: boolean;
1217
}
1318

1419
/**
@@ -17,9 +22,11 @@ export interface Options {
1722
* for that database, and a function to call to stop and remove the container.
1823
*
1924
* @param options.image Docker image to run; e.g. `"postgres:12"` (default: "postgres:latest")
25+
* @param options.runMigrations If true, connect and run migrations according to configuration in `ormconfig.js` (default: true)
2026
*/
2127
export async function getTestDatabase({
2228
image = "postgres:latest",
29+
runMigrations = true,
2330
}: Options): Promise<{
2431
stop: () => Promise<void>;
2532
}> {
@@ -33,9 +40,11 @@ export async function getTestDatabase({
3340
const { port, stop } = await startPostgresContainer(config);
3441
process.env.DATABASE_URL = `postgres://${config.user}:${config.password}@localhost:${port}/${config.database}`;
3542

36-
const conn = await createConnection();
37-
await conn.runMigrations();
38-
await conn.close();
43+
if (runMigrations) {
44+
const conn = await createConnection();
45+
await conn.runMigrations();
46+
await conn.close();
47+
}
3948

4049
return { stop };
4150
}

0 commit comments

Comments
 (0)