@geekmidas/testkit 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Factory-D7P3bKKb.d.mts → Factory-BZ8uMoXl.d.cts} +3 -2
- package/dist/{Factory-pNV7ZQ7-.d.cts → Factory-CRquB4vz.d.mts} +3 -2
- package/dist/Factory-WMhTNZ9S.cjs +2 -1
- package/dist/Factory-WMhTNZ9S.cjs.map +1 -0
- package/dist/Factory-z2m01hMj.mjs +2 -1
- package/dist/Factory-z2m01hMj.mjs.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +2 -2
- package/dist/{KyselyFactory-72P98y5I.d.mts → KyselyFactory-BDS_QqRT.d.mts} +4 -3
- package/dist/KyselyFactory-BcYkC0t2.mjs +2 -1
- package/dist/KyselyFactory-BcYkC0t2.mjs.map +1 -0
- package/dist/KyselyFactory-Cf0o2YxO.cjs +2 -1
- package/dist/KyselyFactory-Cf0o2YxO.cjs.map +1 -0
- package/dist/{KyselyFactory-DLBrYWxU.d.cts → KyselyFactory-DRQ83r0o.d.cts} +4 -3
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +3 -3
- package/dist/ObjectionFactory-8hebmnai.mjs +2 -1
- package/dist/ObjectionFactory-8hebmnai.mjs.map +1 -0
- package/dist/{ObjectionFactory-B40NQWSe.d.mts → ObjectionFactory-C3tHvX1d.d.mts} +4 -3
- package/dist/{ObjectionFactory-D3l1VuyX.d.cts → ObjectionFactory-C4X78k0B.d.cts} +4 -3
- package/dist/ObjectionFactory-CDriunkS.cjs +2 -1
- package/dist/ObjectionFactory-CDriunkS.cjs.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +3 -3
- package/dist/{PostgresKyselyMigrator-_6yHZigp.d.mts → PostgresKyselyMigrator-CIx3AFSR.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-CQ3aUoy_.d.cts +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs +2 -1
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-Bdhl251C.mjs → PostgresKyselyMigrator-upT-hmrz.mjs} +3 -2
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/PostgresMigrator-D5UkK1_K.d.cts +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs +2 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +1 -0
- package/dist/{PostgresMigrator-BlvuQl7d.d.mts → PostgresMigrator-DQaRxoaY.d.mts} +2 -1
- package/dist/{PostgresMigrator-DxPC_gGu.mjs → PostgresMigrator-DbuJGAVy.mjs} +4 -3
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +1 -0
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs +2 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-CZHHcCOv.d.cts +2 -1
- package/dist/{PostgresObjectionMigrator-G4h5FLvU.mjs → PostgresObjectionMigrator-DPj2pOpX.mjs} +3 -2
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-C69n7vzr.d.mts → PostgresObjectionMigrator-D_hCcrQu.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-BxjlD1YM.mjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CnxpE9cH.d.mts → VitestKyselyTransactionIsolator-COCVfvfr.d.mts} +3 -2
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs +2 -1
- package/dist/VitestKyselyTransactionIsolator-Cst3vFjb.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-DYUYVEh9.d.cts +2 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-BU-jXEhz.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CJ4ds5Qv.d.cts +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs +2 -1
- package/dist/VitestObjectionTransactionIsolator-DzeF4UAq.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-DIM79dCq.d.mts → VitestObjectionTransactionIsolator-b973r9O1.d.mts} +3 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs +2 -1
- package/dist/VitestTransactionIsolator-BQ5FpLtC.cjs.map +1 -0
- package/dist/{VitestTransactionIsolator-zdyiS_SY.d.mts → VitestTransactionIsolator-CsfJBxcb.d.mts} +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs +2 -1
- package/dist/VitestTransactionIsolator-CskiiJbW.mjs.map +1 -0
- package/dist/VitestTransactionIsolator-DdLNODZg.d.cts +2 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs +126 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +22 -0
- package/dist/aws.d.mts +22 -0
- package/dist/aws.mjs +123 -0
- package/dist/aws.mjs.map +1 -0
- package/dist/better-auth.cjs +245 -0
- package/dist/better-auth.cjs.map +1 -0
- package/dist/better-auth.d.cts +17 -0
- package/dist/better-auth.d.mts +17 -0
- package/dist/better-auth.mjs +244 -0
- package/dist/better-auth.mjs.map +1 -0
- package/dist/directory-B-Ozljzk.mjs +22 -0
- package/dist/directory-B-Ozljzk.mjs.map +1 -0
- package/dist/directory-B4oYx02C.d.mts +12 -0
- package/dist/directory-BUcnztHI.d.cts +12 -0
- package/dist/directory-BVC8g7cX.cjs +28 -0
- package/dist/directory-BVC8g7cX.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +2 -1
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +2 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/{faker-C-Iuk_R1.d.mts → faker-Br8MzXil.d.mts} +4 -3
- package/dist/{faker-BSH1EMtg.d.cts → faker-Cg76aFNO.d.cts} +4 -3
- package/dist/faker.d.cts +1 -1
- package/dist/faker.d.mts +1 -1
- package/dist/helpers.cjs +48 -2
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.d.cts +2 -1
- package/dist/helpers.d.mts +2 -1
- package/dist/helpers.mjs +47 -2
- package/dist/helpers.mjs.map +1 -0
- package/dist/kysely.cjs +65 -2
- package/dist/kysely.cjs.map +1 -0
- package/dist/kysely.d.cts +5 -4
- package/dist/kysely.d.mts +9 -8
- package/dist/kysely.mjs +67 -4
- package/dist/kysely.mjs.map +1 -0
- package/dist/logger.cjs +23 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +11 -0
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +22 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/objection.cjs +80 -2
- package/dist/objection.cjs.map +1 -0
- package/dist/objection.d.cts +5 -4
- package/dist/objection.d.mts +9 -8
- package/dist/objection.mjs +82 -4
- package/dist/objection.mjs.map +1 -0
- package/dist/os/directory.cjs +3 -0
- package/dist/os/directory.d.cts +2 -0
- package/dist/os/directory.d.mts +2 -0
- package/dist/os/directory.mjs +3 -0
- package/dist/os/index.cjs +3 -0
- package/dist/os/index.d.cts +2 -0
- package/dist/os/index.d.mts +2 -0
- package/dist/os/index.mjs +3 -0
- package/dist/timer.cjs +9 -0
- package/dist/timer.cjs.map +1 -0
- package/dist/timer.d.cts +5 -0
- package/dist/timer.d.mts +5 -0
- package/dist/timer.mjs +8 -0
- package/dist/timer.mjs.map +1 -0
- package/package.json +30 -2
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/aws.ts +131 -0
- package/src/better-auth.ts +327 -0
- package/src/logger.ts +18 -0
- package/src/os/directory.ts +21 -0
- package/src/os/index.ts +1 -0
- package/src/timer.ts +3 -0
- package/dist/__tests__/Factory.spec.cjs +0 -139
- package/dist/__tests__/Factory.spec.d.cts +0 -1
- package/dist/__tests__/Factory.spec.d.mts +0 -1
- package/dist/__tests__/Factory.spec.mjs +0 -138
- package/dist/__tests__/KyselyFactory.spec.cjs +0 -235
- package/dist/__tests__/KyselyFactory.spec.d.cts +0 -1
- package/dist/__tests__/KyselyFactory.spec.d.mts +0 -1
- package/dist/__tests__/KyselyFactory.spec.mjs +0 -234
- package/dist/__tests__/ObjectionFactory.spec.cjs +0 -340
- package/dist/__tests__/ObjectionFactory.spec.d.cts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.d.mts +0 -1
- package/dist/__tests__/ObjectionFactory.spec.mjs +0 -339
- package/dist/__tests__/PostgresKyselyMigrator.spec.cjs +0 -397
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresKyselyMigrator.spec.mjs +0 -396
- package/dist/__tests__/PostgresMigrator.spec.cjs +0 -256
- package/dist/__tests__/PostgresMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresMigrator.spec.mjs +0 -255
- package/dist/__tests__/PostgresObjectionMigrator.spec.cjs +0 -432
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.cts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.d.mts +0 -1
- package/dist/__tests__/PostgresObjectionMigrator.spec.mjs +0 -431
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.cjs +0 -122
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.cts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.d.mts +0 -1
- package/dist/__tests__/VitestObjectionTransactionIsolator.spec.mjs +0 -121
- package/dist/__tests__/faker.spec.cjs +0 -115
- package/dist/__tests__/faker.spec.d.cts +0 -1
- package/dist/__tests__/faker.spec.d.mts +0 -1
- package/dist/__tests__/faker.spec.mjs +0 -114
- package/dist/__tests__/integration.spec.cjs +0 -282
- package/dist/__tests__/integration.spec.d.cts +0 -1
- package/dist/__tests__/integration.spec.d.mts +0 -1
- package/dist/__tests__/integration.spec.mjs +0 -281
- package/dist/helpers-B4TXg3Wp.mjs +0 -86
- package/dist/helpers-Bf0nXhbu.cjs +0 -116
- package/dist/helpers-BuPmgzyQ.mjs +0 -47
- package/dist/helpers-nEUtQ7eo.cjs +0 -53
- package/dist/kysely-C3h7kitU.mjs +0 -67
- package/dist/kysely-VU3MwvMD.cjs +0 -72
- package/dist/objection-BI7F86qf.mjs +0 -82
- package/dist/objection-BpLv_ZfC.cjs +0 -87
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { PostgresMigrator } from "../PostgresMigrator-DxPC_gGu.mjs";
|
|
2
|
-
import { createTestDatabase } from "../helpers-B4TXg3Wp.mjs";
|
|
3
|
-
import { Client } from "pg";
|
|
4
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
//#region src/__tests__/PostgresMigrator.spec.ts
|
|
7
|
-
var TestPostgresMigrator = class extends PostgresMigrator {
|
|
8
|
-
migrateCalled = false;
|
|
9
|
-
migrateError;
|
|
10
|
-
customMigrations = [];
|
|
11
|
-
async migrate() {
|
|
12
|
-
this.migrateCalled = true;
|
|
13
|
-
if (this.migrateError) throw this.migrateError;
|
|
14
|
-
for (const migration of this.customMigrations) await migration();
|
|
15
|
-
}
|
|
16
|
-
addMigration(migration) {
|
|
17
|
-
this.customMigrations.push(migration);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
describe("PostgresMigrator", () => {
|
|
21
|
-
let testDbName;
|
|
22
|
-
let cleanupDb;
|
|
23
|
-
let consoleSpy;
|
|
24
|
-
beforeAll(async () => {
|
|
25
|
-
testDbName = `test_postgres_migrator_${Date.now()}`;
|
|
26
|
-
cleanupDb = await createTestDatabase(testDbName);
|
|
27
|
-
});
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
30
|
-
});
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
consoleSpy.mockRestore();
|
|
33
|
-
});
|
|
34
|
-
afterAll(async () => {
|
|
35
|
-
await cleanupDb();
|
|
36
|
-
});
|
|
37
|
-
describe("constructor", () => {
|
|
38
|
-
it("should create a PostgresMigrator instance", () => {
|
|
39
|
-
const migrator = new TestPostgresMigrator(`postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`);
|
|
40
|
-
expect(migrator).toBeInstanceOf(PostgresMigrator);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe("start method", () => {
|
|
44
|
-
it("should create database, migrate, and return cleanup function", async () => {
|
|
45
|
-
const newDbName = `test_start_${Date.now()}`;
|
|
46
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
47
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
48
|
-
let migrationRan = false;
|
|
49
|
-
migrator.addMigration(async () => {
|
|
50
|
-
migrationRan = true;
|
|
51
|
-
});
|
|
52
|
-
const cleanup = await migrator.start();
|
|
53
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
54
|
-
expect(migrationRan).toBe(true);
|
|
55
|
-
expect(consoleSpy).toHaveBeenCalledWith(`Migrating database: ${newDbName}`);
|
|
56
|
-
expect(typeof cleanup).toBe("function");
|
|
57
|
-
await cleanup();
|
|
58
|
-
});
|
|
59
|
-
it("should handle existing database", async () => {
|
|
60
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`;
|
|
61
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
62
|
-
let migrationRan = false;
|
|
63
|
-
migrator.addMigration(async () => {
|
|
64
|
-
migrationRan = true;
|
|
65
|
-
});
|
|
66
|
-
const cleanup = await migrator.start();
|
|
67
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
68
|
-
expect(migrationRan).toBe(true);
|
|
69
|
-
expect(typeof cleanup).toBe("function");
|
|
70
|
-
});
|
|
71
|
-
it("should handle URI with query parameters", async () => {
|
|
72
|
-
const queryDbName = `test_query_params_${Date.now()}`;
|
|
73
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${queryDbName}?ssl=false&timeout=30`;
|
|
74
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
75
|
-
const cleanup = await migrator.start();
|
|
76
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
77
|
-
expect(typeof cleanup).toBe("function");
|
|
78
|
-
await cleanup();
|
|
79
|
-
});
|
|
80
|
-
it("should clean up connections even if migration fails", async () => {
|
|
81
|
-
const failDbName = `test_fail_${Date.now()}`;
|
|
82
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${failDbName}`;
|
|
83
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
84
|
-
migrator.migrateError = new Error("Migration failed");
|
|
85
|
-
await expect(migrator.start()).rejects.toThrow("Migration failed");
|
|
86
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
87
|
-
const cleanupClient = new Client({
|
|
88
|
-
host: "localhost",
|
|
89
|
-
port: 5432,
|
|
90
|
-
user: "geekmidas",
|
|
91
|
-
password: "geekmidas",
|
|
92
|
-
database: "postgres"
|
|
93
|
-
});
|
|
94
|
-
try {
|
|
95
|
-
await cleanupClient.connect();
|
|
96
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${failDbName}"`);
|
|
97
|
-
} finally {
|
|
98
|
-
await cleanupClient.end();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
it("should return cleanup function that drops database", async () => {
|
|
102
|
-
const cleanupDbName = `test_cleanup_${Date.now()}`;
|
|
103
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${cleanupDbName}`;
|
|
104
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
105
|
-
const cleanup = await migrator.start();
|
|
106
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
107
|
-
expect(typeof cleanup).toBe("function");
|
|
108
|
-
const checkClient = new Client({
|
|
109
|
-
host: "localhost",
|
|
110
|
-
port: 5432,
|
|
111
|
-
user: "geekmidas",
|
|
112
|
-
password: "geekmidas",
|
|
113
|
-
database: "postgres"
|
|
114
|
-
});
|
|
115
|
-
await checkClient.connect();
|
|
116
|
-
const beforeResult = await checkClient.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = $1`, [cleanupDbName]);
|
|
117
|
-
expect(beforeResult.rowCount).toBe(1);
|
|
118
|
-
await checkClient.end();
|
|
119
|
-
await cleanup();
|
|
120
|
-
const checkClient2 = new Client({
|
|
121
|
-
host: "localhost",
|
|
122
|
-
port: 5432,
|
|
123
|
-
user: "geekmidas",
|
|
124
|
-
password: "geekmidas",
|
|
125
|
-
database: "postgres"
|
|
126
|
-
});
|
|
127
|
-
await checkClient2.connect();
|
|
128
|
-
const afterResult = await checkClient2.query(`SELECT * FROM pg_catalog.pg_database WHERE datname = $1`, [cleanupDbName]);
|
|
129
|
-
expect(afterResult.rowCount).toBe(0);
|
|
130
|
-
await checkClient2.end();
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe("database creation", () => {
|
|
134
|
-
it("should handle connection errors gracefully", async () => {
|
|
135
|
-
const badDbName = `test_bad_connection_${Date.now()}`;
|
|
136
|
-
const uri = `postgresql://invalid_user:invalid_pass@localhost:5432/${badDbName}`;
|
|
137
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
138
|
-
await expect(migrator.start()).rejects.toThrow();
|
|
139
|
-
});
|
|
140
|
-
it("should handle invalid database names", async () => {
|
|
141
|
-
const invalidDbName = "test-invalid-db-name!";
|
|
142
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${invalidDbName}`;
|
|
143
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
144
|
-
await expect(migrator.start).rejects.toThrow();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe("URI parsing", () => {
|
|
148
|
-
it("should parse different URI formats correctly", async () => {
|
|
149
|
-
const testDbName$1 = `test_uri_parsing_${Date.now()}`;
|
|
150
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName$1}`;
|
|
151
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
152
|
-
const cleanup = await migrator.start();
|
|
153
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
154
|
-
expect(typeof cleanup).toBe("function");
|
|
155
|
-
await cleanup();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe("error handling", () => {
|
|
159
|
-
it("should propagate migration errors", async () => {
|
|
160
|
-
const errorDbName = `test_migration_error_${Date.now()}`;
|
|
161
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${errorDbName}`;
|
|
162
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
163
|
-
const migrationError = new Error("Custom migration error");
|
|
164
|
-
migrator.migrateError = migrationError;
|
|
165
|
-
await expect(migrator.start()).rejects.toThrow("Custom migration error");
|
|
166
|
-
const cleanupClient = new Client({
|
|
167
|
-
host: "localhost",
|
|
168
|
-
port: 5432,
|
|
169
|
-
user: "geekmidas",
|
|
170
|
-
password: "geekmidas",
|
|
171
|
-
database: "postgres"
|
|
172
|
-
});
|
|
173
|
-
try {
|
|
174
|
-
await cleanupClient.connect();
|
|
175
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${errorDbName}"`);
|
|
176
|
-
} finally {
|
|
177
|
-
await cleanupClient.end();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
it("should handle cleanup errors gracefully", async () => {
|
|
181
|
-
const cleanupErrorDbName = `test_cleanup_error_${Date.now()}`;
|
|
182
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${cleanupErrorDbName}`;
|
|
183
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
184
|
-
const cleanup = await migrator.start();
|
|
185
|
-
const adminClient = new Client({
|
|
186
|
-
host: "localhost",
|
|
187
|
-
port: 5432,
|
|
188
|
-
user: "geekmidas",
|
|
189
|
-
password: "geekmidas",
|
|
190
|
-
database: "postgres"
|
|
191
|
-
});
|
|
192
|
-
await adminClient.connect();
|
|
193
|
-
await adminClient.query(`DROP DATABASE IF EXISTS "${cleanupErrorDbName}"`);
|
|
194
|
-
await adminClient.end();
|
|
195
|
-
await expect(cleanup()).rejects.toThrow();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe("abstract method", () => {
|
|
199
|
-
it("should require concrete implementation of migrate method", () => {
|
|
200
|
-
const migrator = new TestPostgresMigrator(`postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`);
|
|
201
|
-
expect(typeof migrator.migrate).toBe("function");
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
describe("integration scenarios", () => {
|
|
205
|
-
it("should handle complete workflow", async () => {
|
|
206
|
-
const integrationDbName = `test_integration_${Date.now()}`;
|
|
207
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${integrationDbName}`;
|
|
208
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
209
|
-
migrator.addMigration(async () => {
|
|
210
|
-
const client = new Client({
|
|
211
|
-
host: "localhost",
|
|
212
|
-
port: 5432,
|
|
213
|
-
user: "geekmidas",
|
|
214
|
-
password: "geekmidas",
|
|
215
|
-
database: integrationDbName
|
|
216
|
-
});
|
|
217
|
-
await client.connect();
|
|
218
|
-
await client.query(`
|
|
219
|
-
CREATE TABLE IF NOT EXISTS test_table (
|
|
220
|
-
id SERIAL PRIMARY KEY,
|
|
221
|
-
name VARCHAR(255) NOT NULL
|
|
222
|
-
)
|
|
223
|
-
`);
|
|
224
|
-
await client.end();
|
|
225
|
-
});
|
|
226
|
-
const cleanup = await migrator.start();
|
|
227
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
228
|
-
expect(consoleSpy).toHaveBeenCalledWith(`Migrating database: ${integrationDbName}`);
|
|
229
|
-
const verifyClient = new Client({
|
|
230
|
-
host: "localhost",
|
|
231
|
-
port: 5432,
|
|
232
|
-
user: "geekmidas",
|
|
233
|
-
password: "geekmidas",
|
|
234
|
-
database: integrationDbName
|
|
235
|
-
});
|
|
236
|
-
await verifyClient.connect();
|
|
237
|
-
const tableResult = await verifyClient.query(`
|
|
238
|
-
SELECT table_name FROM information_schema.tables
|
|
239
|
-
WHERE table_schema = 'public' AND table_name = 'test_table'
|
|
240
|
-
`);
|
|
241
|
-
expect(tableResult.rowCount).toBe(1);
|
|
242
|
-
await verifyClient.end();
|
|
243
|
-
await cleanup();
|
|
244
|
-
});
|
|
245
|
-
it("should handle database that already exists and cleanup", async () => {
|
|
246
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`;
|
|
247
|
-
const migrator = new TestPostgresMigrator(uri);
|
|
248
|
-
const cleanup = await migrator.start();
|
|
249
|
-
expect(migrator.migrateCalled).toBe(true);
|
|
250
|
-
expect(typeof cleanup).toBe("function");
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('../chunk-CUT6urMc.cjs');
|
|
2
|
-
require('../PostgresMigrator-DFcNdCvD.cjs');
|
|
3
|
-
const require_PostgresObjectionMigrator = require('../PostgresObjectionMigrator-BG6ymgnt.cjs');
|
|
4
|
-
const require_helpers = require('../helpers-Bf0nXhbu.cjs');
|
|
5
|
-
const pg = require_chunk.__toESM(require("pg"));
|
|
6
|
-
const vitest = require_chunk.__toESM(require("vitest"));
|
|
7
|
-
const knex = require_chunk.__toESM(require("knex"));
|
|
8
|
-
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
9
|
-
const node_path = require_chunk.__toESM(require("node:path"));
|
|
10
|
-
|
|
11
|
-
//#region src/__tests__/PostgresObjectionMigrator.spec.ts
|
|
12
|
-
(0, vitest.describe)("PostgresObjectionMigrator", () => {
|
|
13
|
-
let testDbName;
|
|
14
|
-
let cleanupDb;
|
|
15
|
-
let consoleSpy;
|
|
16
|
-
let consoleErrorSpy;
|
|
17
|
-
let testMigrationsDir;
|
|
18
|
-
(0, vitest.beforeAll)(async () => {
|
|
19
|
-
testDbName = `test_postgres_objection_migrator_${Date.now()}`;
|
|
20
|
-
cleanupDb = await require_helpers.createTestDatabase(testDbName);
|
|
21
|
-
testMigrationsDir = node_path.default.join(process.cwd(), "test-migrations", Date.now().toString());
|
|
22
|
-
await node_fs.promises.mkdir(testMigrationsDir, { recursive: true });
|
|
23
|
-
await node_fs.promises.writeFile(node_path.default.join(testMigrationsDir, "001_create_users.js"), `
|
|
24
|
-
exports.up = function(knex) {
|
|
25
|
-
return knex.schema.createTable('users', function(table) {
|
|
26
|
-
table.increments('id').primary();
|
|
27
|
-
table.string('name');
|
|
28
|
-
table.string('email').unique();
|
|
29
|
-
table.timestamps(true, true);
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.down = function(knex) {
|
|
34
|
-
return knex.schema.dropTable('users');
|
|
35
|
-
};
|
|
36
|
-
`);
|
|
37
|
-
await node_fs.promises.writeFile(node_path.default.join(testMigrationsDir, "002_create_posts.js"), `
|
|
38
|
-
exports.up = function(knex) {
|
|
39
|
-
return knex.schema.createTable('posts', function(table) {
|
|
40
|
-
table.increments('id').primary();
|
|
41
|
-
table.string('title');
|
|
42
|
-
table.text('content');
|
|
43
|
-
table.integer('user_id').unsigned().references('id').inTable('users');
|
|
44
|
-
table.timestamps(true, true);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
exports.down = function(knex) {
|
|
49
|
-
return knex.schema.dropTable('posts');
|
|
50
|
-
};
|
|
51
|
-
`);
|
|
52
|
-
});
|
|
53
|
-
(0, vitest.beforeEach)(() => {
|
|
54
|
-
consoleSpy = vitest.vi.spyOn(console, "log").mockImplementation(() => {});
|
|
55
|
-
consoleErrorSpy = vitest.vi.spyOn(console, "error").mockImplementation(() => {});
|
|
56
|
-
});
|
|
57
|
-
(0, vitest.afterEach)(() => {
|
|
58
|
-
consoleSpy.mockRestore();
|
|
59
|
-
consoleErrorSpy.mockRestore();
|
|
60
|
-
});
|
|
61
|
-
(0, vitest.afterAll)(async () => {
|
|
62
|
-
await cleanupDb();
|
|
63
|
-
await node_fs.promises.rm(testMigrationsDir, {
|
|
64
|
-
recursive: true,
|
|
65
|
-
force: true
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
(0, vitest.describe)("constructor", () => {
|
|
69
|
-
(0, vitest.it)("should create a PostgresObjectionMigrator instance", () => {
|
|
70
|
-
const knexInstance = (0, knex.default)({
|
|
71
|
-
client: "pg",
|
|
72
|
-
connection: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`
|
|
73
|
-
});
|
|
74
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
75
|
-
uri: `postgresql://geekmidas:geekmidas@localhost:5432/${testDbName}`,
|
|
76
|
-
knex: knexInstance
|
|
77
|
-
});
|
|
78
|
-
(0, vitest.expect)(migrator).toBeInstanceOf(require_PostgresObjectionMigrator.PostgresObjectionMigrator);
|
|
79
|
-
knexInstance.destroy();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
(0, vitest.describe)("migrate method", () => {
|
|
83
|
-
(0, vitest.it)("should run migrations to latest", async () => {
|
|
84
|
-
const newDbName = `test_migrate_${Date.now()}`;
|
|
85
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
86
|
-
const knexInstance = (0, knex.default)({
|
|
87
|
-
client: "pg",
|
|
88
|
-
connection: uri,
|
|
89
|
-
migrations: { directory: testMigrationsDir }
|
|
90
|
-
});
|
|
91
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
92
|
-
uri,
|
|
93
|
-
knex: knexInstance
|
|
94
|
-
});
|
|
95
|
-
const cleanup = await migrator.start();
|
|
96
|
-
(0, vitest.expect)(consoleSpy).toHaveBeenCalledWith(`Migrating database: ${newDbName}`);
|
|
97
|
-
(0, vitest.expect)(consoleSpy).toHaveBeenCalledWith(vitest.expect.stringContaining("Applied batch"));
|
|
98
|
-
const verifyClient = new pg.Client({
|
|
99
|
-
host: "localhost",
|
|
100
|
-
port: 5432,
|
|
101
|
-
user: "geekmidas",
|
|
102
|
-
password: "geekmidas",
|
|
103
|
-
database: newDbName
|
|
104
|
-
});
|
|
105
|
-
await verifyClient.connect();
|
|
106
|
-
const tablesResult = await verifyClient.query(`
|
|
107
|
-
SELECT table_name FROM information_schema.tables
|
|
108
|
-
WHERE table_schema = 'public'
|
|
109
|
-
AND table_name IN ('users', 'posts')
|
|
110
|
-
ORDER BY table_name
|
|
111
|
-
`);
|
|
112
|
-
(0, vitest.expect)(tablesResult.rows).toEqual([{ table_name: "posts" }, { table_name: "users" }]);
|
|
113
|
-
await verifyClient.end();
|
|
114
|
-
await cleanup();
|
|
115
|
-
});
|
|
116
|
-
(0, vitest.it)("should handle no pending migrations", async () => {
|
|
117
|
-
const newDbName = `test_no_pending_${Date.now()}`;
|
|
118
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
119
|
-
const knexInstance1 = (0, knex.default)({
|
|
120
|
-
client: "pg",
|
|
121
|
-
connection: uri,
|
|
122
|
-
migrations: { directory: testMigrationsDir }
|
|
123
|
-
});
|
|
124
|
-
const migrator1 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
125
|
-
uri,
|
|
126
|
-
knex: knexInstance1
|
|
127
|
-
});
|
|
128
|
-
const cleanup = await migrator1.start();
|
|
129
|
-
consoleSpy.mockClear();
|
|
130
|
-
const knexInstance2 = (0, knex.default)({
|
|
131
|
-
client: "pg",
|
|
132
|
-
connection: uri,
|
|
133
|
-
migrations: { directory: testMigrationsDir }
|
|
134
|
-
});
|
|
135
|
-
const migrator2 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
136
|
-
uri,
|
|
137
|
-
knex: knexInstance2
|
|
138
|
-
});
|
|
139
|
-
await migrator2.migrate();
|
|
140
|
-
(0, vitest.expect)(consoleSpy).toHaveBeenCalledWith("No pending migrations to apply");
|
|
141
|
-
await cleanup();
|
|
142
|
-
});
|
|
143
|
-
(0, vitest.it)("should handle migration errors", async () => {
|
|
144
|
-
const newDbName = `test_migration_error_${Date.now()}`;
|
|
145
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
146
|
-
const badMigrationsDir = node_path.default.join(process.cwd(), "bad-migrations", Date.now().toString());
|
|
147
|
-
await node_fs.promises.mkdir(badMigrationsDir, { recursive: true });
|
|
148
|
-
await node_fs.promises.writeFile(node_path.default.join(badMigrationsDir, "001_bad_migration.js"), `
|
|
149
|
-
exports.up = function(knex) {
|
|
150
|
-
throw new Error('Migration failed on purpose');
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
exports.down = function(knex) {
|
|
154
|
-
return Promise.resolve();
|
|
155
|
-
};
|
|
156
|
-
`);
|
|
157
|
-
const knexInstance = (0, knex.default)({
|
|
158
|
-
client: "pg",
|
|
159
|
-
connection: uri,
|
|
160
|
-
migrations: { directory: badMigrationsDir }
|
|
161
|
-
});
|
|
162
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
163
|
-
uri,
|
|
164
|
-
knex: knexInstance
|
|
165
|
-
});
|
|
166
|
-
await (0, vitest.expect)(migrator.start()).rejects.toThrow("Migration failed on purpose");
|
|
167
|
-
(0, vitest.expect)(consoleErrorSpy).toHaveBeenCalledWith("Failed to apply migrations:", vitest.expect.any(Error));
|
|
168
|
-
await node_fs.promises.rm(badMigrationsDir, {
|
|
169
|
-
recursive: true,
|
|
170
|
-
force: true
|
|
171
|
-
});
|
|
172
|
-
const cleanupClient = new pg.Client({
|
|
173
|
-
host: "localhost",
|
|
174
|
-
port: 5432,
|
|
175
|
-
user: "geekmidas",
|
|
176
|
-
password: "geekmidas",
|
|
177
|
-
database: "postgres"
|
|
178
|
-
});
|
|
179
|
-
await cleanupClient.connect();
|
|
180
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${newDbName}"`);
|
|
181
|
-
await cleanupClient.end();
|
|
182
|
-
});
|
|
183
|
-
(0, vitest.it)("should destroy knex connection after migration", async () => {
|
|
184
|
-
const newDbName = `test_destroy_${Date.now()}`;
|
|
185
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
186
|
-
const knexInstance = (0, knex.default)({
|
|
187
|
-
client: "pg",
|
|
188
|
-
connection: uri,
|
|
189
|
-
migrations: { directory: testMigrationsDir }
|
|
190
|
-
});
|
|
191
|
-
const destroySpy = vitest.vi.spyOn(knexInstance, "destroy");
|
|
192
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
193
|
-
uri,
|
|
194
|
-
knex: knexInstance
|
|
195
|
-
});
|
|
196
|
-
const cleanup = await migrator.start();
|
|
197
|
-
(0, vitest.expect)(destroySpy).toHaveBeenCalled();
|
|
198
|
-
await cleanup();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
(0, vitest.describe)("rollback method", () => {
|
|
202
|
-
(0, vitest.it)("should rollback last migration batch", async () => {
|
|
203
|
-
const newDbName = `test_rollback_${Date.now()}`;
|
|
204
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
205
|
-
const knexInstance1 = (0, knex.default)({
|
|
206
|
-
client: "pg",
|
|
207
|
-
connection: uri,
|
|
208
|
-
migrations: { directory: testMigrationsDir }
|
|
209
|
-
});
|
|
210
|
-
const migrator1 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
211
|
-
uri,
|
|
212
|
-
knex: knexInstance1
|
|
213
|
-
});
|
|
214
|
-
const cleanup = await migrator1.start();
|
|
215
|
-
consoleSpy.mockClear();
|
|
216
|
-
const knexInstance2 = (0, knex.default)({
|
|
217
|
-
client: "pg",
|
|
218
|
-
connection: uri,
|
|
219
|
-
migrations: { directory: testMigrationsDir }
|
|
220
|
-
});
|
|
221
|
-
const migrator2 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
222
|
-
uri,
|
|
223
|
-
knex: knexInstance2
|
|
224
|
-
});
|
|
225
|
-
await migrator2.rollback();
|
|
226
|
-
(0, vitest.expect)(consoleSpy).toHaveBeenCalledWith(vitest.expect.stringContaining("Rolled back batch"));
|
|
227
|
-
const verifyClient = new pg.Client({
|
|
228
|
-
host: "localhost",
|
|
229
|
-
port: 5432,
|
|
230
|
-
user: "geekmidas",
|
|
231
|
-
password: "geekmidas",
|
|
232
|
-
database: newDbName
|
|
233
|
-
});
|
|
234
|
-
await verifyClient.connect();
|
|
235
|
-
const tablesResult = await verifyClient.query(`
|
|
236
|
-
SELECT table_name FROM information_schema.tables
|
|
237
|
-
WHERE table_schema = 'public'
|
|
238
|
-
AND table_name IN ('users', 'posts')
|
|
239
|
-
`);
|
|
240
|
-
(0, vitest.expect)(tablesResult.rows).toEqual([]);
|
|
241
|
-
await verifyClient.end();
|
|
242
|
-
await cleanup();
|
|
243
|
-
});
|
|
244
|
-
(0, vitest.it)("should handle no migrations to rollback", async () => {
|
|
245
|
-
const newDbName = `test_no_rollback_${Date.now()}`;
|
|
246
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
247
|
-
const createClient = new pg.Client({
|
|
248
|
-
host: "localhost",
|
|
249
|
-
port: 5432,
|
|
250
|
-
user: "geekmidas",
|
|
251
|
-
password: "geekmidas",
|
|
252
|
-
database: "postgres"
|
|
253
|
-
});
|
|
254
|
-
await createClient.connect();
|
|
255
|
-
await createClient.query(`CREATE DATABASE "${newDbName}"`);
|
|
256
|
-
await createClient.end();
|
|
257
|
-
const knexInstance = (0, knex.default)({
|
|
258
|
-
client: "pg",
|
|
259
|
-
connection: uri,
|
|
260
|
-
migrations: { directory: testMigrationsDir }
|
|
261
|
-
});
|
|
262
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
263
|
-
uri,
|
|
264
|
-
knex: knexInstance
|
|
265
|
-
});
|
|
266
|
-
await migrator.rollback();
|
|
267
|
-
(0, vitest.expect)(consoleSpy).toHaveBeenCalledWith("No migrations to rollback");
|
|
268
|
-
const cleanupClient = new pg.Client({
|
|
269
|
-
host: "localhost",
|
|
270
|
-
port: 5432,
|
|
271
|
-
user: "geekmidas",
|
|
272
|
-
password: "geekmidas",
|
|
273
|
-
database: "postgres"
|
|
274
|
-
});
|
|
275
|
-
await cleanupClient.connect();
|
|
276
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${newDbName}"`);
|
|
277
|
-
await cleanupClient.end();
|
|
278
|
-
});
|
|
279
|
-
(0, vitest.it)("should handle rollback errors", async () => {
|
|
280
|
-
const newDbName = `test_rollback_error_${Date.now()}`;
|
|
281
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
282
|
-
const knexInstance = (0, knex.default)({
|
|
283
|
-
client: "pg",
|
|
284
|
-
connection: uri,
|
|
285
|
-
migrations: { directory: testMigrationsDir }
|
|
286
|
-
});
|
|
287
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
288
|
-
uri,
|
|
289
|
-
knex: knexInstance
|
|
290
|
-
});
|
|
291
|
-
await (0, vitest.expect)(migrator.rollback()).rejects.toThrow();
|
|
292
|
-
(0, vitest.expect)(consoleErrorSpy).toHaveBeenCalledWith("Failed to rollback migrations:", vitest.expect.any(Error));
|
|
293
|
-
await knexInstance.destroy();
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
(0, vitest.describe)("status method", () => {
|
|
297
|
-
(0, vitest.it)("should return migration status", async () => {
|
|
298
|
-
const newDbName = `test_status_${Date.now()}`;
|
|
299
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
300
|
-
const knexInstance1 = (0, knex.default)({
|
|
301
|
-
client: "pg",
|
|
302
|
-
connection: uri,
|
|
303
|
-
migrations: { directory: testMigrationsDir }
|
|
304
|
-
});
|
|
305
|
-
const migrator1 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
306
|
-
uri,
|
|
307
|
-
knex: knexInstance1
|
|
308
|
-
});
|
|
309
|
-
const cleanup = await migrator1.start();
|
|
310
|
-
const knexInstance2 = (0, knex.default)({
|
|
311
|
-
client: "pg",
|
|
312
|
-
connection: uri,
|
|
313
|
-
migrations: { directory: testMigrationsDir }
|
|
314
|
-
});
|
|
315
|
-
const migrator2 = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
316
|
-
uri,
|
|
317
|
-
knex: knexInstance2
|
|
318
|
-
});
|
|
319
|
-
const status = await migrator2.status();
|
|
320
|
-
(0, vitest.expect)(status).toHaveProperty("completed");
|
|
321
|
-
(0, vitest.expect)(status).toHaveProperty("pending");
|
|
322
|
-
(0, vitest.expect)(Array.isArray(status.completed)).toBe(true);
|
|
323
|
-
(0, vitest.expect)(Array.isArray(status.pending)).toBe(true);
|
|
324
|
-
await cleanup();
|
|
325
|
-
});
|
|
326
|
-
(0, vitest.it)("should destroy connection after getting status", async () => {
|
|
327
|
-
const newDbName = `test_status_destroy_${Date.now()}`;
|
|
328
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${newDbName}`;
|
|
329
|
-
const knexInstance = (0, knex.default)({
|
|
330
|
-
client: "pg",
|
|
331
|
-
connection: uri,
|
|
332
|
-
migrations: { directory: testMigrationsDir }
|
|
333
|
-
});
|
|
334
|
-
const destroySpy = vitest.vi.spyOn(knexInstance, "destroy");
|
|
335
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
336
|
-
uri,
|
|
337
|
-
knex: knexInstance
|
|
338
|
-
});
|
|
339
|
-
const createClient = new pg.Client({
|
|
340
|
-
host: "localhost",
|
|
341
|
-
port: 5432,
|
|
342
|
-
user: "geekmidas",
|
|
343
|
-
password: "geekmidas",
|
|
344
|
-
database: "postgres"
|
|
345
|
-
});
|
|
346
|
-
await createClient.connect();
|
|
347
|
-
await createClient.query(`CREATE DATABASE "${newDbName}"`);
|
|
348
|
-
await createClient.end();
|
|
349
|
-
await migrator.status();
|
|
350
|
-
(0, vitest.expect)(destroySpy).toHaveBeenCalled();
|
|
351
|
-
const cleanupClient = new pg.Client({
|
|
352
|
-
host: "localhost",
|
|
353
|
-
port: 5432,
|
|
354
|
-
user: "geekmidas",
|
|
355
|
-
password: "geekmidas",
|
|
356
|
-
database: "postgres"
|
|
357
|
-
});
|
|
358
|
-
await cleanupClient.connect();
|
|
359
|
-
await cleanupClient.query(`DROP DATABASE IF EXISTS "${newDbName}"`);
|
|
360
|
-
await cleanupClient.end();
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
(0, vitest.describe)("integration scenarios", () => {
|
|
364
|
-
(0, vitest.it)("should handle complete workflow with complex migrations", async () => {
|
|
365
|
-
const integrationDbName = `test_integration_${Date.now()}`;
|
|
366
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${integrationDbName}`;
|
|
367
|
-
const knexInstance = (0, knex.default)({
|
|
368
|
-
client: "pg",
|
|
369
|
-
connection: uri,
|
|
370
|
-
migrations: { directory: testMigrationsDir }
|
|
371
|
-
});
|
|
372
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
373
|
-
uri,
|
|
374
|
-
knex: knexInstance
|
|
375
|
-
});
|
|
376
|
-
const cleanup = await migrator.start();
|
|
377
|
-
const testClient = new pg.Client({
|
|
378
|
-
host: "localhost",
|
|
379
|
-
port: 5432,
|
|
380
|
-
user: "geekmidas",
|
|
381
|
-
password: "geekmidas",
|
|
382
|
-
database: integrationDbName
|
|
383
|
-
});
|
|
384
|
-
await testClient.connect();
|
|
385
|
-
const userResult = await testClient.query(`INSERT INTO users (name, email) VALUES ($1, $2) RETURNING id`, ["Test User", "test@example.com"]);
|
|
386
|
-
const userId = userResult.rows[0].id;
|
|
387
|
-
await testClient.query(`INSERT INTO posts (title, content, user_id) VALUES ($1, $2, $3)`, [
|
|
388
|
-
"Test Post",
|
|
389
|
-
"This is a test post",
|
|
390
|
-
userId
|
|
391
|
-
]);
|
|
392
|
-
const postResult = await testClient.query(`SELECT * FROM posts WHERE user_id = $1`, [userId]);
|
|
393
|
-
(0, vitest.expect)(postResult.rowCount).toBe(1);
|
|
394
|
-
(0, vitest.expect)(postResult.rows[0].title).toBe("Test Post");
|
|
395
|
-
await testClient.end();
|
|
396
|
-
await cleanup();
|
|
397
|
-
});
|
|
398
|
-
(0, vitest.it)("should work with transaction-based tests", async () => {
|
|
399
|
-
const transactionDbName = `test_transaction_${Date.now()}`;
|
|
400
|
-
const uri = `postgresql://geekmidas:geekmidas@localhost:5432/${transactionDbName}`;
|
|
401
|
-
const knexInstance = (0, knex.default)({
|
|
402
|
-
client: "pg",
|
|
403
|
-
connection: uri,
|
|
404
|
-
migrations: { directory: testMigrationsDir }
|
|
405
|
-
});
|
|
406
|
-
const migrator = new require_PostgresObjectionMigrator.PostgresObjectionMigrator({
|
|
407
|
-
uri,
|
|
408
|
-
knex: knexInstance
|
|
409
|
-
});
|
|
410
|
-
const cleanup = await migrator.start();
|
|
411
|
-
const testKnex = (0, knex.default)({
|
|
412
|
-
client: "pg",
|
|
413
|
-
connection: uri
|
|
414
|
-
});
|
|
415
|
-
await testKnex.transaction(async (trx) => {
|
|
416
|
-
await trx("users").insert({
|
|
417
|
-
name: "Transaction User",
|
|
418
|
-
email: "trx@example.com"
|
|
419
|
-
});
|
|
420
|
-
const users$1 = await trx("users").select("*");
|
|
421
|
-
(0, vitest.expect)(users$1.length).toBeGreaterThan(0);
|
|
422
|
-
throw new Error("Rollback transaction");
|
|
423
|
-
}).catch(() => {});
|
|
424
|
-
const users = await testKnex("users").select("*");
|
|
425
|
-
(0, vitest.expect)(users.length).toBe(0);
|
|
426
|
-
await testKnex.destroy();
|
|
427
|
-
await cleanup();
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
//#endregion
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|