@geekmidas/testkit 10.0.0-alpha.98 → 10.0.0
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/CHANGELOG.md +160 -0
- package/README.md +0 -74
- package/dist/Factory-BFVnMMCC.mjs +51 -0
- package/dist/Factory-BFVnMMCC.mjs.map +1 -0
- package/dist/Factory-BOX312yd.d.cts +147 -0
- package/dist/Factory-BOX312yd.d.cts.map +1 -0
- package/dist/Factory-BhjUOBWN.cjs +57 -0
- package/dist/Factory-BhjUOBWN.cjs.map +1 -0
- package/dist/Factory-SFupxRC2.d.mts +147 -0
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.cjs +2 -51
- package/dist/Factory.d.cts +3 -143
- package/dist/Factory.d.mts +3 -143
- package/dist/Factory.mjs +2 -50
- package/dist/KyselyFactory-BFqVIn_0.cjs +246 -0
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -0
- package/dist/KyselyFactory-DMswpwji.mjs +241 -0
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -0
- package/dist/KyselyFactory-Dy5zzV4B.d.cts +228 -0
- package/dist/KyselyFactory-Dy5zzV4B.d.cts.map +1 -0
- package/dist/KyselyFactory-vAxYodck.d.mts +228 -0
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.cjs +4 -237
- package/dist/KyselyFactory.d.cts +4 -224
- package/dist/KyselyFactory.d.mts +4 -224
- package/dist/KyselyFactory.mjs +4 -236
- package/dist/ObjectionFactory-BWjB49-i.d.mts +241 -0
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs +272 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -0
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts +241 -0
- package/dist/ObjectionFactory-CD-WFuMJ.d.cts.map +1 -0
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs +267 -0
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -0
- package/dist/ObjectionFactory.cjs +4 -265
- package/dist/ObjectionFactory.d.cts +4 -237
- package/dist/ObjectionFactory.d.mts +4 -237
- package/dist/ObjectionFactory.mjs +4 -264
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts +84 -0
- package/dist/PostgresKyselyMigrator-B2M6Gjvv.d.cts.map +1 -0
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs +101 -0
- package/dist/PostgresKyselyMigrator-BGBxjnFv.cjs.map +1 -0
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts +84 -0
- package/dist/PostgresKyselyMigrator-CvwXycJE.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs +95 -0
- package/dist/PostgresKyselyMigrator-PI0QhvB1.mjs.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +3 -94
- package/dist/PostgresKyselyMigrator.d.cts +3 -80
- package/dist/PostgresKyselyMigrator.d.mts +3 -80
- package/dist/PostgresKyselyMigrator.mjs +3 -93
- package/dist/{PostgresMigrator-CDPnnwMJ.d.cts → PostgresMigrator-C_QQ6q35.d.mts} +5 -11
- package/dist/PostgresMigrator-C_QQ6q35.d.mts.map +1 -0
- package/dist/{PostgresMigrator-CDPnnwMJ.d.mts → PostgresMigrator-CeYy-eHF.d.cts} +5 -11
- package/dist/PostgresMigrator-CeYy-eHF.d.cts.map +1 -0
- package/dist/PostgresMigrator-DVAY04qN.mjs +166 -0
- package/dist/PostgresMigrator-DVAY04qN.mjs.map +1 -0
- package/dist/PostgresMigrator-M9jpzOvN.cjs +172 -0
- package/dist/PostgresMigrator-M9jpzOvN.cjs.map +1 -0
- package/dist/PostgresMigrator.cjs +2 -178
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +2 -175
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts +79 -0
- package/dist/PostgresObjectionMigrator-1j6YIB1c.d.mts.map +1 -0
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts +79 -0
- package/dist/PostgresObjectionMigrator-DHVC9h_P.d.cts.map +1 -0
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs +123 -0
- package/dist/PostgresObjectionMigrator-DSaPhwjY.cjs.map +1 -0
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs +118 -0
- package/dist/PostgresObjectionMigrator-DjPKdUbm.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +3 -118
- package/dist/PostgresObjectionMigrator.d.cts +3 -75
- package/dist/PostgresObjectionMigrator.d.mts +3 -75
- package/dist/PostgresObjectionMigrator.mjs +3 -117
- package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs +65 -0
- package/dist/VitestKyselyTransactionIsolator-0CqOsuc9.cjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts +59 -0
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs +60 -0
- package/dist/VitestKyselyTransactionIsolator-CfSMOFlN.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts +59 -0
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +3 -66
- package/dist/VitestKyselyTransactionIsolator.d.cts +3 -60
- package/dist/VitestKyselyTransactionIsolator.d.mts +3 -60
- package/dist/VitestKyselyTransactionIsolator.mjs +3 -65
- package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs +68 -0
- package/dist/VitestObjectionTransactionIsolator-B5J9jjKq.cjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts +60 -0
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs +63 -0
- package/dist/VitestObjectionTransactionIsolator-CNo40EdC.mjs.map +1 -0
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts +60 -0
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +3 -62
- package/dist/VitestObjectionTransactionIsolator.d.cts +3 -56
- package/dist/VitestObjectionTransactionIsolator.d.mts +3 -56
- package/dist/VitestObjectionTransactionIsolator.mjs +3 -61
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts +207 -0
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts +207 -0
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-CtZaOUjH.cjs +193 -0
- package/dist/VitestTransactionIsolator-CtZaOUjH.cjs.map +1 -0
- package/dist/VitestTransactionIsolator-D6ZxLWys.mjs +175 -0
- package/dist/VitestTransactionIsolator-D6ZxLWys.mjs.map +1 -0
- package/dist/VitestTransactionIsolator.cjs +4 -187
- package/dist/VitestTransactionIsolator.d.cts +2 -219
- package/dist/VitestTransactionIsolator.d.mts +2 -219
- package/dist/VitestTransactionIsolator.mjs +2 -184
- package/dist/aws.cjs +4 -3
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +8 -3
- package/dist/aws.d.cts.map +1 -1
- package/dist/aws.d.mts +8 -3
- package/dist/aws.d.mts.map +1 -1
- package/dist/aws.mjs +2 -1
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs +2 -2
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +6 -4
- package/dist/benchmark.d.cts.map +1 -1
- package/dist/benchmark.d.mts +6 -4
- package/dist/benchmark.d.mts.map +1 -1
- package/dist/benchmark.mjs +1 -1
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +15 -31
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +4 -13142
- package/dist/better-auth.d.cts.map +1 -1
- package/dist/better-auth.d.mts +4 -13142
- package/dist/better-auth.d.mts.map +1 -1
- package/dist/better-auth.mjs +13 -29
- package/dist/better-auth.mjs.map +1 -1
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
- package/dist/directory-Bpz5c5pj.d.cts +13 -0
- package/dist/directory-Bpz5c5pj.d.cts.map +1 -0
- package/dist/directory-BxjqmtCT.mjs +27 -0
- package/dist/directory-BxjqmtCT.mjs.map +1 -0
- package/dist/directory-CVrfTq1I.d.mts +13 -0
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-DD_xQoSh.cjs +33 -0
- package/dist/directory-DD_xQoSh.cjs.map +1 -0
- package/dist/faker-B14IEMIN.cjs +304 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -0
- package/dist/faker-BGKYFoCT.mjs +262 -0
- package/dist/faker-BGKYFoCT.mjs.map +1 -0
- package/dist/faker-Cg76aFNO.d.cts +166 -0
- package/dist/faker-Cg76aFNO.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts +166 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.cjs +8 -313
- package/dist/faker.d.cts +2 -169
- package/dist/faker.d.mts +2 -169
- package/dist/faker.mjs +2 -305
- package/dist/helpers.cjs +5 -6
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +5 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +5 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +2 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/initScript.cjs +15 -15
- package/dist/initScript.cjs.map +1 -1
- package/dist/initScript.d.cts +4 -2
- package/dist/initScript.d.cts.map +1 -1
- package/dist/initScript.d.mts +4 -2
- package/dist/initScript.d.mts.map +1 -1
- package/dist/initScript.mjs +12 -10
- package/dist/initScript.mjs.map +1 -1
- package/dist/kysely.cjs +13 -10
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +14 -10
- package/dist/kysely.d.cts.map +1 -1
- package/dist/kysely.d.mts +14 -10
- package/dist/kysely.d.mts.map +1 -1
- package/dist/kysely.mjs +14 -10
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs +4 -3
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +5 -1
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.mts +5 -1
- package/dist/logger.d.mts.map +1 -1
- package/dist/logger.mjs +2 -1
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +13 -10
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +14 -10
- package/dist/objection.d.cts.map +1 -1
- package/dist/objection.d.mts +14 -10
- package/dist/objection.d.mts.map +1 -1
- package/dist/objection.mjs +14 -10
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.cjs +2 -31
- package/dist/os/directory.d.cts +2 -9
- package/dist/os/directory.d.mts +2 -9
- package/dist/os/directory.mjs +2 -25
- package/dist/os/index.cjs +3 -3
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/os/index.mjs +3 -2
- package/dist/requestContext.cjs +11 -10
- package/dist/requestContext.cjs.map +1 -1
- package/dist/requestContext.d.cts +9 -5
- package/dist/requestContext.d.cts.map +1 -1
- package/dist/requestContext.d.mts +9 -5
- package/dist/requestContext.d.mts.map +1 -1
- package/dist/requestContext.mjs +3 -2
- package/dist/requestContext.mjs.map +1 -1
- package/dist/timer.cjs +2 -2
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +4 -1
- package/dist/timer.d.cts.map +1 -1
- package/dist/timer.d.mts +4 -1
- package/dist/timer.d.mts.map +1 -1
- package/dist/timer.mjs +1 -1
- package/dist/timer.mjs.map +1 -1
- package/package.json +25 -65
- package/src/Factory.ts +174 -0
- package/src/KyselyFactory.ts +391 -0
- package/src/ObjectionFactory.ts +412 -0
- package/src/PostgresKyselyMigrator.ts +104 -0
- package/src/PostgresMigrator.ts +193 -0
- package/src/PostgresObjectionMigrator.ts +138 -0
- package/src/VitestKyselyTransactionIsolator.ts +72 -0
- package/src/VitestObjectionTransactionIsolator.ts +75 -0
- package/src/VitestTransactionIsolator.ts +348 -0
- package/src/__tests__/Factory.spec.ts +178 -0
- package/src/__tests__/KyselyFactory.spec.ts +458 -0
- package/src/__tests__/ObjectionFactory.spec.ts +586 -0
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +794 -0
- package/src/__tests__/PostgresMigrator.spec.ts +471 -0
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +634 -0
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +138 -0
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +21 -0
- package/src/__tests__/faker.spec.ts +231 -0
- package/src/__tests__/initScript.spec.ts +332 -0
- package/src/__tests__/integration.spec.ts +610 -0
- package/src/__tests__/requestContext.spec.ts +113 -0
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +131 -0
- package/src/benchmark.ts +48 -0
- package/src/better-auth.ts +310 -0
- package/src/faker.ts +349 -0
- package/src/helpers.ts +45 -0
- package/src/initScript.ts +122 -0
- package/src/kysely.ts +166 -0
- package/src/logger.ts +18 -0
- package/src/objection.ts +157 -0
- package/src/os/directory.ts +26 -0
- package/src/os/index.ts +1 -0
- package/src/requestContext.ts +119 -0
- package/src/timer.ts +3 -0
- package/test/globalSetup.ts +54 -0
- package/test/helpers.ts +268 -0
- package/test/migrations/1749664623372_user.ts +22 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +8 -0
- package/dist/Factory.cjs.map +0 -1
- package/dist/Factory.d.cts.map +0 -1
- package/dist/Factory.d.mts.map +0 -1
- package/dist/Factory.mjs.map +0 -1
- package/dist/KyselyFactory.cjs.map +0 -1
- package/dist/KyselyFactory.d.cts.map +0 -1
- package/dist/KyselyFactory.d.mts.map +0 -1
- package/dist/KyselyFactory.mjs.map +0 -1
- package/dist/ObjectionFactory.cjs.map +0 -1
- package/dist/ObjectionFactory.d.cts.map +0 -1
- package/dist/ObjectionFactory.d.mts.map +0 -1
- package/dist/ObjectionFactory.mjs.map +0 -1
- package/dist/PostgresKyselyMigrator.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator.d.cts.map +0 -1
- package/dist/PostgresKyselyMigrator.d.mts.map +0 -1
- package/dist/PostgresKyselyMigrator.mjs.map +0 -1
- package/dist/PostgresMigrator-CDPnnwMJ.d.cts.map +0 -1
- package/dist/PostgresMigrator-CDPnnwMJ.d.mts.map +0 -1
- package/dist/PostgresMigrator.cjs.map +0 -1
- package/dist/PostgresMigrator.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator.d.cts.map +0 -1
- package/dist/PostgresObjectionMigrator.d.mts.map +0 -1
- package/dist/PostgresObjectionMigrator.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.cjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestKyselyTransactionIsolator.mjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestObjectionTransactionIsolator.mjs.map +0 -1
- package/dist/VitestTransactionIsolator.cjs.map +0 -1
- package/dist/VitestTransactionIsolator.d.cts.map +0 -1
- package/dist/VitestTransactionIsolator.d.mts.map +0 -1
- package/dist/VitestTransactionIsolator.mjs.map +0 -1
- package/dist/browser.cjs +0 -149
- package/dist/browser.cjs.map +0 -1
- package/dist/browser.d.cts +0 -62
- package/dist/browser.d.cts.map +0 -1
- package/dist/browser.d.mts +0 -62
- package/dist/browser.d.mts.map +0 -1
- package/dist/browser.mjs +0 -147
- package/dist/browser.mjs.map +0 -1
- package/dist/context.cjs +0 -80
- package/dist/context.cjs.map +0 -1
- package/dist/context.d.cts +0 -55
- package/dist/context.d.cts.map +0 -1
- package/dist/context.d.mts +0 -55
- package/dist/context.d.mts.map +0 -1
- package/dist/context.mjs +0 -73
- package/dist/context.mjs.map +0 -1
- package/dist/faker.cjs.map +0 -1
- package/dist/faker.d.cts.map +0 -1
- package/dist/faker.d.mts.map +0 -1
- package/dist/faker.mjs.map +0 -1
- package/dist/mailbox.cjs +0 -95
- package/dist/mailbox.cjs.map +0 -1
- package/dist/mailbox.d.cts +0 -58
- package/dist/mailbox.d.cts.map +0 -1
- package/dist/mailbox.d.mts +0 -58
- package/dist/mailbox.d.mts.map +0 -1
- package/dist/mailbox.mjs +0 -92
- package/dist/mailbox.mjs.map +0 -1
- package/dist/os/directory.cjs.map +0 -1
- package/dist/os/directory.d.cts.map +0 -1
- package/dist/os/directory.d.mts.map +0 -1
- package/dist/os/directory.mjs.map +0 -1
- package/dist/transactions.cjs +0 -239
- package/dist/transactions.cjs.map +0 -1
- package/dist/transactions.d.cts +0 -44
- package/dist/transactions.d.cts.map +0 -1
- package/dist/transactions.d.mts +0 -44
- package/dist/transactions.d.mts.map +0 -1
- package/dist/transactions.mjs +0 -234
- package/dist/transactions.mjs.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-CeYy-eHF.cjs";
|
|
2
|
+
import { Knex } from "knex";
|
|
3
|
+
|
|
4
|
+
//#region src/PostgresObjectionMigrator.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
8
|
+
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
9
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import knex from 'knex';
|
|
14
|
+
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
15
|
+
*
|
|
16
|
+
* // Create Knex instance
|
|
17
|
+
* const db = knex({
|
|
18
|
+
* client: 'pg',
|
|
19
|
+
* connection: uri,
|
|
20
|
+
* migrations: {
|
|
21
|
+
* directory: path.join(__dirname, 'migrations'),
|
|
22
|
+
* extension: 'ts'
|
|
23
|
+
* }
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Create and use migrator
|
|
27
|
+
* const migrator = new PostgresObjectionMigrator({
|
|
28
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
29
|
+
* knex: db
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const cleanup = await migrator.start();
|
|
33
|
+
* // Run tests...
|
|
34
|
+
* await cleanup();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare class PostgresObjectionMigrator extends PostgresMigrator {
|
|
38
|
+
private options;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new PostgresObjectionMigrator instance.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Configuration options
|
|
43
|
+
* @param options.uri - PostgreSQL connection URI
|
|
44
|
+
* @param options.knex - Knex database instance configured with migrations
|
|
45
|
+
*/
|
|
46
|
+
constructor(options: {
|
|
47
|
+
uri: string;
|
|
48
|
+
knex: Knex;
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Executes Knex migrations to the latest version.
|
|
52
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
53
|
+
*
|
|
54
|
+
* @throws Error if migrations fail to apply
|
|
55
|
+
* @returns Promise that resolves when all migrations are applied
|
|
56
|
+
*/
|
|
57
|
+
migrate(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Rolls back the last batch of migrations.
|
|
60
|
+
* Useful for testing migration rollback scenarios.
|
|
61
|
+
*
|
|
62
|
+
* @returns Promise that resolves when rollback is complete
|
|
63
|
+
*/
|
|
64
|
+
rollback(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the current migration status.
|
|
67
|
+
* Returns information about completed and pending migrations.
|
|
68
|
+
*
|
|
69
|
+
* @returns Promise with migration status information
|
|
70
|
+
*/
|
|
71
|
+
status(): Promise<{
|
|
72
|
+
completed: string[];
|
|
73
|
+
pending: string[];
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=PostgresObjectionMigrator.d.ts.map
|
|
77
|
+
//#endregion
|
|
78
|
+
export { PostgresObjectionMigrator };
|
|
79
|
+
//# sourceMappingURL=PostgresObjectionMigrator-DHVC9h_P.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresObjectionMigrator-DHVC9h_P.d.cts","names":[],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":[],"mappings":";;;;;;;AAuCA;;;;;;;AAA+D;;;;;;;;;;;;;;;;;;;;;;cAAlD,yBAAA,SAAkC,gBAAA;;;;;;;;;;;UAWtC;;;;;;;;;aAaS;;;;;;;cA8BC;;;;;;;YA4BF"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_PostgresMigrator = require('./PostgresMigrator-M9jpzOvN.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/PostgresObjectionMigrator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default logger instance for migration operations.
|
|
6
|
+
*/
|
|
7
|
+
const logger = console;
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
10
|
+
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
11
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import knex from 'knex';
|
|
16
|
+
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
17
|
+
*
|
|
18
|
+
* // Create Knex instance
|
|
19
|
+
* const db = knex({
|
|
20
|
+
* client: 'pg',
|
|
21
|
+
* connection: uri,
|
|
22
|
+
* migrations: {
|
|
23
|
+
* directory: path.join(__dirname, 'migrations'),
|
|
24
|
+
* extension: 'ts'
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Create and use migrator
|
|
29
|
+
* const migrator = new PostgresObjectionMigrator({
|
|
30
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
31
|
+
* knex: db
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const cleanup = await migrator.start();
|
|
35
|
+
* // Run tests...
|
|
36
|
+
* await cleanup();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
var PostgresObjectionMigrator = class extends require_PostgresMigrator.PostgresMigrator {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new PostgresObjectionMigrator instance.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options
|
|
44
|
+
* @param options.uri - PostgreSQL connection URI
|
|
45
|
+
* @param options.knex - Knex database instance configured with migrations
|
|
46
|
+
*/
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super(options.uri);
|
|
49
|
+
this.options = options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Executes Knex migrations to the latest version.
|
|
53
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
54
|
+
*
|
|
55
|
+
* @throws Error if migrations fail to apply
|
|
56
|
+
* @returns Promise that resolves when all migrations are applied
|
|
57
|
+
*/
|
|
58
|
+
async migrate() {
|
|
59
|
+
try {
|
|
60
|
+
const [batchNo, migrations] = await this.options.knex.migrate.latest();
|
|
61
|
+
if (migrations.length > 0) {
|
|
62
|
+
logger.log(`Applied batch ${batchNo} with ${migrations.length} migrations:`);
|
|
63
|
+
migrations.forEach((migration) => {
|
|
64
|
+
logger.log(` - ${migration}`);
|
|
65
|
+
});
|
|
66
|
+
} else logger.log("No pending migrations to apply");
|
|
67
|
+
} catch (error) {
|
|
68
|
+
logger.error("Failed to apply migrations:", error);
|
|
69
|
+
throw error;
|
|
70
|
+
} finally {
|
|
71
|
+
await this.options.knex.destroy();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Rolls back the last batch of migrations.
|
|
76
|
+
* Useful for testing migration rollback scenarios.
|
|
77
|
+
*
|
|
78
|
+
* @returns Promise that resolves when rollback is complete
|
|
79
|
+
*/
|
|
80
|
+
async rollback() {
|
|
81
|
+
try {
|
|
82
|
+
const [batchNo, migrations] = await this.options.knex.migrate.rollback();
|
|
83
|
+
if (migrations.length > 0) {
|
|
84
|
+
logger.log(`Rolled back batch ${batchNo} with ${migrations.length} migrations:`);
|
|
85
|
+
migrations.forEach((migration) => {
|
|
86
|
+
logger.log(` - ${migration}`);
|
|
87
|
+
});
|
|
88
|
+
} else logger.log("No migrations to rollback");
|
|
89
|
+
} catch (error) {
|
|
90
|
+
logger.error("Failed to rollback migrations:", error);
|
|
91
|
+
throw error;
|
|
92
|
+
} finally {
|
|
93
|
+
await this.options.knex.destroy();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current migration status.
|
|
98
|
+
* Returns information about completed and pending migrations.
|
|
99
|
+
*
|
|
100
|
+
* @returns Promise with migration status information
|
|
101
|
+
*/
|
|
102
|
+
async status() {
|
|
103
|
+
try {
|
|
104
|
+
const completed = await this.options.knex.migrate.list();
|
|
105
|
+
const [, pending] = await this.options.knex.migrate.currentVersion();
|
|
106
|
+
return {
|
|
107
|
+
completed: Array.isArray(completed[0]) ? completed[0] : [],
|
|
108
|
+
pending: Array.isArray(pending) ? pending : []
|
|
109
|
+
};
|
|
110
|
+
} finally {
|
|
111
|
+
await this.options.knex.destroy();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
Object.defineProperty(exports, 'PostgresObjectionMigrator', {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function () {
|
|
120
|
+
return PostgresObjectionMigrator;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
//# sourceMappingURL=PostgresObjectionMigrator-DSaPhwjY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresObjectionMigrator-DSaPhwjY.cjs","names":["PostgresMigrator","options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t}","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresObjectionMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.knex - Knex database instance configured with migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t},\n\t) {\n\t\tsuper(options.uri);\n\t}\n\n\t/**\n\t * Executes Knex migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\ttry {\n\t\t\t// Run migrations to latest\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Applied batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No pending migrations to apply');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to apply migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// Always destroy the connection pool\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Rolls back the last batch of migrations.\n\t * Useful for testing migration rollback scenarios.\n\t *\n\t * @returns Promise that resolves when rollback is complete\n\t */\n\tasync rollback(): Promise<void> {\n\t\ttry {\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No migrations to rollback');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to rollback migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Gets the current migration status.\n\t * Returns information about completed and pending migrations.\n\t *\n\t * @returns Promise with migration status information\n\t */\n\tasync status(): Promise<{\n\t\tcompleted: string[];\n\t\tpending: string[];\n\t}> {\n\t\ttry {\n\t\t\tconst completed = await this.options.knex.migrate.list();\n\t\t\tconst [, pending] = await this.options.knex.migrate.currentVersion();\n\n\t\t\treturn {\n\t\t\t\tcompleted: Array.isArray(completed[0]) ? completed[0] : [],\n\t\t\t\tpending: Array.isArray(pending) ? pending : [],\n\t\t\t};\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCf,IAAa,4BAAb,cAA+CA,0CAAiB;;;;;;;;CAQ/D,YACSC,SAIP;AACD,QAAM,QAAQ,IAAI;EALV;CAMR;;;;;;;;CASD,MAAM,UAAyB;AAC9B,MAAI;GAEH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAEtE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,gBAAgB,QAAQ,QAAQ,WAAW,OAAO,cACnD;AACD,eAAW,QAAQ,CAACC,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,iCAAiC;EAE7C,SAAQ,OAAO;AACf,UAAO,MAAM,+BAA+B,MAAM;AAClD,SAAM;EACN,UAAS;AAET,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,WAA0B;AAC/B,MAAI;GACH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,UAAU;AAExE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,oBAAoB,QAAQ,QAAQ,WAAW,OAAO,cACvD;AACD,eAAW,QAAQ,CAACA,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,4BAA4B;EAExC,SAAQ,OAAO;AACf,UAAO,MAAM,kCAAkC,MAAM;AACrD,SAAM;EACN,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,SAGH;AACF,MAAI;GACH,MAAM,YAAY,MAAM,KAAK,QAAQ,KAAK,QAAQ,MAAM;GACxD,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,gBAAgB;AAEpE,UAAO;IACN,WAAW,MAAM,QAAQ,UAAU,GAAG,GAAG,UAAU,KAAK,CAAE;IAC1D,SAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC9C;EACD,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;AACD"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { PostgresMigrator } from "./PostgresMigrator-DVAY04qN.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/PostgresObjectionMigrator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Default logger instance for migration operations.
|
|
6
|
+
*/
|
|
7
|
+
const logger = console;
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
10
|
+
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
11
|
+
* Automatically creates test databases and applies migrations for testing environments.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import knex from 'knex';
|
|
16
|
+
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
17
|
+
*
|
|
18
|
+
* // Create Knex instance
|
|
19
|
+
* const db = knex({
|
|
20
|
+
* client: 'pg',
|
|
21
|
+
* connection: uri,
|
|
22
|
+
* migrations: {
|
|
23
|
+
* directory: path.join(__dirname, 'migrations'),
|
|
24
|
+
* extension: 'ts'
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Create and use migrator
|
|
29
|
+
* const migrator = new PostgresObjectionMigrator({
|
|
30
|
+
* uri: 'postgresql://localhost:5432/test_db',
|
|
31
|
+
* knex: db
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const cleanup = await migrator.start();
|
|
35
|
+
* // Run tests...
|
|
36
|
+
* await cleanup();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
var PostgresObjectionMigrator = class extends PostgresMigrator {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new PostgresObjectionMigrator instance.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options
|
|
44
|
+
* @param options.uri - PostgreSQL connection URI
|
|
45
|
+
* @param options.knex - Knex database instance configured with migrations
|
|
46
|
+
*/
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super(options.uri);
|
|
49
|
+
this.options = options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Executes Knex migrations to the latest version.
|
|
53
|
+
* Implements the abstract migrate() method from PostgresMigrator.
|
|
54
|
+
*
|
|
55
|
+
* @throws Error if migrations fail to apply
|
|
56
|
+
* @returns Promise that resolves when all migrations are applied
|
|
57
|
+
*/
|
|
58
|
+
async migrate() {
|
|
59
|
+
try {
|
|
60
|
+
const [batchNo, migrations] = await this.options.knex.migrate.latest();
|
|
61
|
+
if (migrations.length > 0) {
|
|
62
|
+
logger.log(`Applied batch ${batchNo} with ${migrations.length} migrations:`);
|
|
63
|
+
migrations.forEach((migration) => {
|
|
64
|
+
logger.log(` - ${migration}`);
|
|
65
|
+
});
|
|
66
|
+
} else logger.log("No pending migrations to apply");
|
|
67
|
+
} catch (error) {
|
|
68
|
+
logger.error("Failed to apply migrations:", error);
|
|
69
|
+
throw error;
|
|
70
|
+
} finally {
|
|
71
|
+
await this.options.knex.destroy();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Rolls back the last batch of migrations.
|
|
76
|
+
* Useful for testing migration rollback scenarios.
|
|
77
|
+
*
|
|
78
|
+
* @returns Promise that resolves when rollback is complete
|
|
79
|
+
*/
|
|
80
|
+
async rollback() {
|
|
81
|
+
try {
|
|
82
|
+
const [batchNo, migrations] = await this.options.knex.migrate.rollback();
|
|
83
|
+
if (migrations.length > 0) {
|
|
84
|
+
logger.log(`Rolled back batch ${batchNo} with ${migrations.length} migrations:`);
|
|
85
|
+
migrations.forEach((migration) => {
|
|
86
|
+
logger.log(` - ${migration}`);
|
|
87
|
+
});
|
|
88
|
+
} else logger.log("No migrations to rollback");
|
|
89
|
+
} catch (error) {
|
|
90
|
+
logger.error("Failed to rollback migrations:", error);
|
|
91
|
+
throw error;
|
|
92
|
+
} finally {
|
|
93
|
+
await this.options.knex.destroy();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current migration status.
|
|
98
|
+
* Returns information about completed and pending migrations.
|
|
99
|
+
*
|
|
100
|
+
* @returns Promise with migration status information
|
|
101
|
+
*/
|
|
102
|
+
async status() {
|
|
103
|
+
try {
|
|
104
|
+
const completed = await this.options.knex.migrate.list();
|
|
105
|
+
const [, pending] = await this.options.knex.migrate.currentVersion();
|
|
106
|
+
return {
|
|
107
|
+
completed: Array.isArray(completed[0]) ? completed[0] : [],
|
|
108
|
+
pending: Array.isArray(pending) ? pending : []
|
|
109
|
+
};
|
|
110
|
+
} finally {
|
|
111
|
+
await this.options.knex.destroy();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { PostgresObjectionMigrator };
|
|
118
|
+
//# sourceMappingURL=PostgresObjectionMigrator-DjPKdUbm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgresObjectionMigrator-DjPKdUbm.mjs","names":["options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t}","migration: string"],"sources":["../src/PostgresObjectionMigrator.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport { PostgresMigrator } from './PostgresMigrator';\n\n/**\n * Default logger instance for migration operations.\n */\nconst logger = console;\n\n/**\n * PostgreSQL migrator implementation for Objection.js ORM with Knex.\n * Extends PostgresMigrator to provide Knex-specific migration functionality.\n * Automatically creates test databases and applies migrations for testing environments.\n *\n * @example\n * ```typescript\n * import knex from 'knex';\n * import { PostgresObjectionMigrator } from '@geekmidas/testkit';\n *\n * // Create Knex instance\n * const db = knex({\n * client: 'pg',\n * connection: uri,\n * migrations: {\n * directory: path.join(__dirname, 'migrations'),\n * extension: 'ts'\n * }\n * });\n *\n * // Create and use migrator\n * const migrator = new PostgresObjectionMigrator({\n * uri: 'postgresql://localhost:5432/test_db',\n * knex: db\n * });\n *\n * const cleanup = await migrator.start();\n * // Run tests...\n * await cleanup();\n * ```\n */\nexport class PostgresObjectionMigrator extends PostgresMigrator {\n\t/**\n\t * Creates a new PostgresObjectionMigrator instance.\n\t *\n\t * @param options - Configuration options\n\t * @param options.uri - PostgreSQL connection URI\n\t * @param options.knex - Knex database instance configured with migrations\n\t */\n\tconstructor(\n\t\tprivate options: {\n\t\t\turi: string;\n\t\t\tknex: Knex;\n\t\t},\n\t) {\n\t\tsuper(options.uri);\n\t}\n\n\t/**\n\t * Executes Knex migrations to the latest version.\n\t * Implements the abstract migrate() method from PostgresMigrator.\n\t *\n\t * @throws Error if migrations fail to apply\n\t * @returns Promise that resolves when all migrations are applied\n\t */\n\tasync migrate(): Promise<void> {\n\t\ttry {\n\t\t\t// Run migrations to latest\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.latest();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Applied batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No pending migrations to apply');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to apply migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\t// Always destroy the connection pool\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Rolls back the last batch of migrations.\n\t * Useful for testing migration rollback scenarios.\n\t *\n\t * @returns Promise that resolves when rollback is complete\n\t */\n\tasync rollback(): Promise<void> {\n\t\ttry {\n\t\t\tconst [batchNo, migrations] = await this.options.knex.migrate.rollback();\n\n\t\t\tif (migrations.length > 0) {\n\t\t\t\tlogger.log(\n\t\t\t\t\t`Rolled back batch ${batchNo} with ${migrations.length} migrations:`,\n\t\t\t\t);\n\t\t\t\tmigrations.forEach((migration: string) => {\n\t\t\t\t\tlogger.log(` - ${migration}`);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tlogger.log('No migrations to rollback');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlogger.error('Failed to rollback migrations:', error);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n\n\t/**\n\t * Gets the current migration status.\n\t * Returns information about completed and pending migrations.\n\t *\n\t * @returns Promise with migration status information\n\t */\n\tasync status(): Promise<{\n\t\tcompleted: string[];\n\t\tpending: string[];\n\t}> {\n\t\ttry {\n\t\t\tconst completed = await this.options.knex.migrate.list();\n\t\t\tconst [, pending] = await this.options.knex.migrate.currentVersion();\n\n\t\t\treturn {\n\t\t\t\tcompleted: Array.isArray(completed[0]) ? completed[0] : [],\n\t\t\t\tpending: Array.isArray(pending) ? pending : [],\n\t\t\t};\n\t\t} finally {\n\t\t\tawait this.options.knex.destroy();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCf,IAAa,4BAAb,cAA+C,iBAAiB;;;;;;;;CAQ/D,YACSA,SAIP;AACD,QAAM,QAAQ,IAAI;EALV;CAMR;;;;;;;;CASD,MAAM,UAAyB;AAC9B,MAAI;GAEH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAEtE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,gBAAgB,QAAQ,QAAQ,WAAW,OAAO,cACnD;AACD,eAAW,QAAQ,CAACC,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,iCAAiC;EAE7C,SAAQ,OAAO;AACf,UAAO,MAAM,+BAA+B,MAAM;AAClD,SAAM;EACN,UAAS;AAET,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,WAA0B;AAC/B,MAAI;GACH,MAAM,CAAC,SAAS,WAAW,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,UAAU;AAExE,OAAI,WAAW,SAAS,GAAG;AAC1B,WAAO,KACL,oBAAoB,QAAQ,QAAQ,WAAW,OAAO,cACvD;AACD,eAAW,QAAQ,CAACA,cAAsB;AACzC,YAAO,KAAK,MAAM,UAAU,EAAE;IAC9B,EAAC;GACF,MACA,QAAO,IAAI,4BAA4B;EAExC,SAAQ,OAAO;AACf,UAAO,MAAM,kCAAkC,MAAM;AACrD,SAAM;EACN,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;;;;;;;CAQD,MAAM,SAGH;AACF,MAAI;GACH,MAAM,YAAY,MAAM,KAAK,QAAQ,KAAK,QAAQ,MAAM;GACxD,MAAM,GAAG,QAAQ,GAAG,MAAM,KAAK,QAAQ,KAAK,QAAQ,gBAAgB;AAEpE,UAAO;IACN,WAAW,MAAM,QAAQ,UAAU,GAAG,GAAG,UAAU,KAAK,CAAE;IAC1D,SAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAE;GAC9C;EACD,UAAS;AACT,SAAM,KAAK,QAAQ,KAAK,SAAS;EACjC;CACD;AACD"}
|
|
@@ -1,119 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
//#region src/PostgresObjectionMigrator.ts
|
|
4
|
-
/**
|
|
5
|
-
* Default logger instance for migration operations.
|
|
6
|
-
*/
|
|
7
|
-
const logger = console;
|
|
8
|
-
/**
|
|
9
|
-
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
10
|
-
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
11
|
-
* Automatically creates test databases and applies migrations for testing environments.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import knex from 'knex';
|
|
16
|
-
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
17
|
-
*
|
|
18
|
-
* // Create Knex instance
|
|
19
|
-
* const db = knex({
|
|
20
|
-
* client: 'pg',
|
|
21
|
-
* connection: uri,
|
|
22
|
-
* migrations: {
|
|
23
|
-
* directory: path.join(__dirname, 'migrations'),
|
|
24
|
-
* extension: 'ts'
|
|
25
|
-
* }
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* // Create and use migrator
|
|
29
|
-
* const migrator = new PostgresObjectionMigrator({
|
|
30
|
-
* uri: 'postgresql://localhost:5432/test_db',
|
|
31
|
-
* knex: db
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* const cleanup = await migrator.start();
|
|
35
|
-
* // Run tests...
|
|
36
|
-
* await cleanup();
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
var PostgresObjectionMigrator = class extends require_PostgresMigrator.PostgresMigrator {
|
|
40
|
-
options;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new PostgresObjectionMigrator instance.
|
|
43
|
-
*
|
|
44
|
-
* @param options - Configuration options
|
|
45
|
-
* @param options.uri - PostgreSQL connection URI
|
|
46
|
-
* @param options.knex - Knex database instance configured with migrations
|
|
47
|
-
*/
|
|
48
|
-
constructor(options) {
|
|
49
|
-
super(options.uri);
|
|
50
|
-
this.options = options;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Executes Knex migrations to the latest version.
|
|
54
|
-
* Implements the abstract migrate() method from PostgresMigrator.
|
|
55
|
-
*
|
|
56
|
-
* @throws Error if migrations fail to apply
|
|
57
|
-
* @returns Promise that resolves when all migrations are applied
|
|
58
|
-
*/
|
|
59
|
-
async migrate() {
|
|
60
|
-
try {
|
|
61
|
-
const [batchNo, migrations] = await this.options.knex.migrate.latest();
|
|
62
|
-
if (migrations.length > 0) {
|
|
63
|
-
logger.log(`Applied batch ${batchNo} with ${migrations.length} migrations:`);
|
|
64
|
-
migrations.forEach((migration) => {
|
|
65
|
-
logger.log(` - ${migration}`);
|
|
66
|
-
});
|
|
67
|
-
} else logger.log("No pending migrations to apply");
|
|
68
|
-
} catch (error) {
|
|
69
|
-
logger.error("Failed to apply migrations:", error);
|
|
70
|
-
throw error;
|
|
71
|
-
} finally {
|
|
72
|
-
await this.options.knex.destroy();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Rolls back the last batch of migrations.
|
|
77
|
-
* Useful for testing migration rollback scenarios.
|
|
78
|
-
*
|
|
79
|
-
* @returns Promise that resolves when rollback is complete
|
|
80
|
-
*/
|
|
81
|
-
async rollback() {
|
|
82
|
-
try {
|
|
83
|
-
const [batchNo, migrations] = await this.options.knex.migrate.rollback();
|
|
84
|
-
if (migrations.length > 0) {
|
|
85
|
-
logger.log(`Rolled back batch ${batchNo} with ${migrations.length} migrations:`);
|
|
86
|
-
migrations.forEach((migration) => {
|
|
87
|
-
logger.log(` - ${migration}`);
|
|
88
|
-
});
|
|
89
|
-
} else logger.log("No migrations to rollback");
|
|
90
|
-
} catch (error) {
|
|
91
|
-
logger.error("Failed to rollback migrations:", error);
|
|
92
|
-
throw error;
|
|
93
|
-
} finally {
|
|
94
|
-
await this.options.knex.destroy();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets the current migration status.
|
|
99
|
-
* Returns information about completed and pending migrations.
|
|
100
|
-
*
|
|
101
|
-
* @returns Promise with migration status information
|
|
102
|
-
*/
|
|
103
|
-
async status() {
|
|
104
|
-
try {
|
|
105
|
-
const completed = await this.options.knex.migrate.list();
|
|
106
|
-
const [, pending] = await this.options.knex.migrate.currentVersion();
|
|
107
|
-
return {
|
|
108
|
-
completed: Array.isArray(completed[0]) ? completed[0] : [],
|
|
109
|
-
pending: Array.isArray(pending) ? pending : []
|
|
110
|
-
};
|
|
111
|
-
} finally {
|
|
112
|
-
await this.options.knex.destroy();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
//#endregion
|
|
117
|
-
exports.PostgresObjectionMigrator = PostgresObjectionMigrator;
|
|
1
|
+
require('./PostgresMigrator-M9jpzOvN.cjs');
|
|
2
|
+
const require_PostgresObjectionMigrator = require('./PostgresObjectionMigrator-DSaPhwjY.cjs');
|
|
118
3
|
|
|
119
|
-
|
|
4
|
+
exports.PostgresObjectionMigrator = require_PostgresObjectionMigrator.PostgresObjectionMigrator;
|
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
6
|
-
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
7
|
-
* Automatically creates test databases and applies migrations for testing environments.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import knex from 'knex';
|
|
12
|
-
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
13
|
-
*
|
|
14
|
-
* // Create Knex instance
|
|
15
|
-
* const db = knex({
|
|
16
|
-
* client: 'pg',
|
|
17
|
-
* connection: uri,
|
|
18
|
-
* migrations: {
|
|
19
|
-
* directory: path.join(__dirname, 'migrations'),
|
|
20
|
-
* extension: 'ts'
|
|
21
|
-
* }
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* // Create and use migrator
|
|
25
|
-
* const migrator = new PostgresObjectionMigrator({
|
|
26
|
-
* uri: 'postgresql://localhost:5432/test_db',
|
|
27
|
-
* knex: db
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* const cleanup = await migrator.start();
|
|
31
|
-
* // Run tests...
|
|
32
|
-
* await cleanup();
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare class PostgresObjectionMigrator extends PostgresMigrator {
|
|
36
|
-
private options;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new PostgresObjectionMigrator instance.
|
|
39
|
-
*
|
|
40
|
-
* @param options - Configuration options
|
|
41
|
-
* @param options.uri - PostgreSQL connection URI
|
|
42
|
-
* @param options.knex - Knex database instance configured with migrations
|
|
43
|
-
*/
|
|
44
|
-
constructor(options: {
|
|
45
|
-
uri: string;
|
|
46
|
-
knex: Knex;
|
|
47
|
-
});
|
|
48
|
-
/**
|
|
49
|
-
* Executes Knex migrations to the latest version.
|
|
50
|
-
* Implements the abstract migrate() method from PostgresMigrator.
|
|
51
|
-
*
|
|
52
|
-
* @throws Error if migrations fail to apply
|
|
53
|
-
* @returns Promise that resolves when all migrations are applied
|
|
54
|
-
*/
|
|
55
|
-
migrate(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Rolls back the last batch of migrations.
|
|
58
|
-
* Useful for testing migration rollback scenarios.
|
|
59
|
-
*
|
|
60
|
-
* @returns Promise that resolves when rollback is complete
|
|
61
|
-
*/
|
|
62
|
-
rollback(): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Gets the current migration status.
|
|
65
|
-
* Returns information about completed and pending migrations.
|
|
66
|
-
*
|
|
67
|
-
* @returns Promise with migration status information
|
|
68
|
-
*/
|
|
69
|
-
status(): Promise<{
|
|
70
|
-
completed: string[];
|
|
71
|
-
pending: string[];
|
|
72
|
-
}>;
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//# sourceMappingURL=PostgresObjectionMigrator.d.cts.map
|
|
1
|
+
import "./PostgresMigrator-CeYy-eHF.cjs";
|
|
2
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-DHVC9h_P.cjs";
|
|
3
|
+
export { PostgresObjectionMigrator };
|
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* PostgreSQL migrator implementation for Objection.js ORM with Knex.
|
|
6
|
-
* Extends PostgresMigrator to provide Knex-specific migration functionality.
|
|
7
|
-
* Automatically creates test databases and applies migrations for testing environments.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import knex from 'knex';
|
|
12
|
-
* import { PostgresObjectionMigrator } from '@geekmidas/testkit';
|
|
13
|
-
*
|
|
14
|
-
* // Create Knex instance
|
|
15
|
-
* const db = knex({
|
|
16
|
-
* client: 'pg',
|
|
17
|
-
* connection: uri,
|
|
18
|
-
* migrations: {
|
|
19
|
-
* directory: path.join(__dirname, 'migrations'),
|
|
20
|
-
* extension: 'ts'
|
|
21
|
-
* }
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* // Create and use migrator
|
|
25
|
-
* const migrator = new PostgresObjectionMigrator({
|
|
26
|
-
* uri: 'postgresql://localhost:5432/test_db',
|
|
27
|
-
* knex: db
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* const cleanup = await migrator.start();
|
|
31
|
-
* // Run tests...
|
|
32
|
-
* await cleanup();
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare class PostgresObjectionMigrator extends PostgresMigrator {
|
|
36
|
-
private options;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new PostgresObjectionMigrator instance.
|
|
39
|
-
*
|
|
40
|
-
* @param options - Configuration options
|
|
41
|
-
* @param options.uri - PostgreSQL connection URI
|
|
42
|
-
* @param options.knex - Knex database instance configured with migrations
|
|
43
|
-
*/
|
|
44
|
-
constructor(options: {
|
|
45
|
-
uri: string;
|
|
46
|
-
knex: Knex;
|
|
47
|
-
});
|
|
48
|
-
/**
|
|
49
|
-
* Executes Knex migrations to the latest version.
|
|
50
|
-
* Implements the abstract migrate() method from PostgresMigrator.
|
|
51
|
-
*
|
|
52
|
-
* @throws Error if migrations fail to apply
|
|
53
|
-
* @returns Promise that resolves when all migrations are applied
|
|
54
|
-
*/
|
|
55
|
-
migrate(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Rolls back the last batch of migrations.
|
|
58
|
-
* Useful for testing migration rollback scenarios.
|
|
59
|
-
*
|
|
60
|
-
* @returns Promise that resolves when rollback is complete
|
|
61
|
-
*/
|
|
62
|
-
rollback(): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Gets the current migration status.
|
|
65
|
-
* Returns information about completed and pending migrations.
|
|
66
|
-
*
|
|
67
|
-
* @returns Promise with migration status information
|
|
68
|
-
*/
|
|
69
|
-
status(): Promise<{
|
|
70
|
-
completed: string[];
|
|
71
|
-
pending: string[];
|
|
72
|
-
}>;
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//# sourceMappingURL=PostgresObjectionMigrator.d.mts.map
|
|
1
|
+
import "./PostgresMigrator-C_QQ6q35.mjs";
|
|
2
|
+
import { PostgresObjectionMigrator } from "./PostgresObjectionMigrator-1j6YIB1c.mjs";
|
|
3
|
+
export { PostgresObjectionMigrator };
|