-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_postgres.ts
41 lines (36 loc) · 1.13 KB
/
test_postgres.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { dirname, fromFileUrl, resolve } from "./deps.ts";
import { PostgresMigrate, PostgresMigrateOptions } from "./postgres.ts";
export async function cleanupInit(migrate: PostgresMigrate) {
await migrate.connect();
try {
const transaction = migrate.client.createTransaction(
"postgres_test_cleanup_init",
);
await transaction.begin();
await transaction.queryArray("DROP TABLE migration");
await transaction.queryArray("DROP FUNCTION trigger_migration_timestamp");
await transaction.commit();
} catch {
await migrate.connect();
}
}
export interface MigrateTest {
migrate?: PostgresMigrate;
}
export interface InitializedMigrateTest extends MigrateTest {
migrate: PostgresMigrate;
}
const isTestBuild = Deno.env.get("MIGRATE_TEST_BUILD") === "true";
export const options: PostgresMigrateOptions = {
client: {
hostname: isTestBuild ? "postgres" : "localhost",
port: isTestBuild ? 5432 : 6001,
database: "postgres",
user: "postgres",
password: "postgres",
},
};
export const exampleMigrationsDir = resolve(
dirname(fromFileUrl(import.meta.url)),
"examples/postgres/migrations",
);