@dads-framework/postgres 0.1.0 → 0.3.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/README.md +24 -2
- package/dist/lib/attributed-pool.d.ts +1 -1
- package/dist/lib/attributed-pool.d.ts.map +1 -1
- package/dist/lib/attributed-pool.js +1 -1
- package/dist/lib/attributed-pool.js.map +1 -1
- package/dist/lib/counting-client.js +1 -1
- package/dist/lib/counting-client.js.map +1 -1
- package/dist/migrations/bin/adopt-existing-schema.d.ts +3 -0
- package/dist/migrations/bin/adopt-existing-schema.d.ts.map +1 -0
- package/dist/migrations/bin/adopt-existing-schema.js +26 -0
- package/dist/migrations/bin/adopt-existing-schema.js.map +1 -0
- package/dist/migrations/bin/check-migration-compatibility.d.ts +14 -0
- package/dist/migrations/bin/check-migration-compatibility.d.ts.map +1 -0
- package/dist/migrations/bin/check-migration-compatibility.js +177 -0
- package/dist/migrations/bin/check-migration-compatibility.js.map +1 -0
- package/dist/migrations/bin/migrate.d.ts +3 -0
- package/dist/migrations/bin/migrate.d.ts.map +1 -0
- package/dist/migrations/bin/migrate.js +15 -0
- package/dist/migrations/bin/migrate.js.map +1 -0
- package/dist/migrations/bin/migration-log.d.ts +18 -0
- package/dist/migrations/bin/migration-log.d.ts.map +1 -0
- package/dist/migrations/bin/migration-log.js +30 -0
- package/dist/migrations/bin/migration-log.js.map +1 -0
- package/dist/migrations/bin/new-migration.d.ts +19 -0
- package/dist/migrations/bin/new-migration.d.ts.map +1 -0
- package/dist/migrations/bin/new-migration.js +86 -0
- package/dist/migrations/bin/new-migration.js.map +1 -0
- package/dist/migrations/bin/read-database-journal-status-result.d.ts +2 -0
- package/dist/migrations/bin/read-database-journal-status-result.d.ts.map +1 -0
- package/dist/migrations/bin/read-database-journal-status-result.js +14 -0
- package/dist/migrations/bin/read-database-journal-status-result.js.map +1 -0
- package/dist/migrations/bin/read-database-journal-status.d.ts +3 -0
- package/dist/migrations/bin/read-database-journal-status.d.ts.map +1 -0
- package/dist/migrations/bin/read-database-journal-status.js +20 -0
- package/dist/migrations/bin/read-database-journal-status.js.map +1 -0
- package/dist/migrations/compatibility/compatibility-catalog-queries.d.ts +8 -0
- package/dist/migrations/compatibility/compatibility-catalog-queries.d.ts.map +1 -0
- package/dist/migrations/compatibility/compatibility-catalog-queries.js +309 -0
- package/dist/migrations/compatibility/compatibility-catalog-queries.js.map +1 -0
- package/dist/migrations/compatibility/migration-support-files.d.ts +8 -0
- package/dist/migrations/compatibility/migration-support-files.d.ts.map +1 -0
- package/dist/migrations/compatibility/migration-support-files.js +120 -0
- package/dist/migrations/compatibility/migration-support-files.js.map +1 -0
- package/dist/migrations/compatibility/plan-migration-compatibility.d.ts +11 -0
- package/dist/migrations/compatibility/plan-migration-compatibility.d.ts.map +1 -0
- package/dist/migrations/compatibility/plan-migration-compatibility.js +31 -0
- package/dist/migrations/compatibility/plan-migration-compatibility.js.map +1 -0
- package/dist/migrations/compatibility/read-migration-compatibility-state.d.ts +22 -0
- package/dist/migrations/compatibility/read-migration-compatibility-state.d.ts.map +1 -0
- package/dist/migrations/compatibility/read-migration-compatibility-state.js +128 -0
- package/dist/migrations/compatibility/read-migration-compatibility-state.js.map +1 -0
- package/dist/migrations/compatibility/rehearsal-sources.d.ts +19 -0
- package/dist/migrations/compatibility/rehearsal-sources.d.ts.map +1 -0
- package/dist/migrations/compatibility/rehearsal-sources.js +55 -0
- package/dist/migrations/compatibility/rehearsal-sources.js.map +1 -0
- package/dist/migrations/compatibility/rehearse-migration-compatibility.d.ts +20 -0
- package/dist/migrations/compatibility/rehearse-migration-compatibility.d.ts.map +1 -0
- package/dist/migrations/compatibility/rehearse-migration-compatibility.js +100 -0
- package/dist/migrations/compatibility/rehearse-migration-compatibility.js.map +1 -0
- package/dist/migrations/index.d.ts +12 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +11 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/journal-status.d.ts +11 -0
- package/dist/migrations/journal-status.d.ts.map +1 -0
- package/dist/migrations/journal-status.js +4 -0
- package/dist/migrations/journal-status.js.map +1 -0
- package/dist/migrations/lib/logic/describe-migration-failure.d.ts +7 -0
- package/dist/migrations/lib/logic/describe-migration-failure.d.ts.map +1 -0
- package/dist/migrations/lib/logic/describe-migration-failure.js +19 -0
- package/dist/migrations/lib/logic/describe-migration-failure.js.map +1 -0
- package/dist/migrations/lib/logic/journal-stamp-decision.d.ts +6 -0
- package/dist/migrations/lib/logic/journal-stamp-decision.d.ts.map +1 -0
- package/dist/migrations/lib/logic/journal-stamp-decision.js +10 -0
- package/dist/migrations/lib/logic/journal-stamp-decision.js.map +1 -0
- package/dist/migrations/lib/logic/parse-concurrent-index-statement.d.ts +31 -0
- package/dist/migrations/lib/logic/parse-concurrent-index-statement.d.ts.map +1 -0
- package/dist/migrations/lib/logic/parse-concurrent-index-statement.js +50 -0
- package/dist/migrations/lib/logic/parse-concurrent-index-statement.js.map +1 -0
- package/dist/migrations/lib/logic/parse-migration-environment.d.ts +16 -0
- package/dist/migrations/lib/logic/parse-migration-environment.d.ts.map +1 -0
- package/dist/migrations/lib/logic/parse-migration-environment.js +15 -0
- package/dist/migrations/lib/logic/parse-migration-environment.js.map +1 -0
- package/dist/migrations/lib/logic/sibling-database-url.d.ts +3 -0
- package/dist/migrations/lib/logic/sibling-database-url.d.ts.map +1 -0
- package/dist/migrations/lib/logic/sibling-database-url.js +14 -0
- package/dist/migrations/lib/logic/sibling-database-url.js.map +1 -0
- package/dist/migrations/lib/node-pg/apply-concurrent-index-migration.d.ts +15 -0
- package/dist/migrations/lib/node-pg/apply-concurrent-index-migration.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/apply-concurrent-index-migration.js +84 -0
- package/dist/migrations/lib/node-pg/apply-concurrent-index-migration.js.map +1 -0
- package/dist/migrations/lib/node-pg/apply-graph-migrations.d.ts +12 -0
- package/dist/migrations/lib/node-pg/apply-graph-migrations.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/apply-graph-migrations.js +84 -0
- package/dist/migrations/lib/node-pg/apply-graph-migrations.js.map +1 -0
- package/dist/migrations/lib/node-pg/discover-domain-migrations.d.ts +3 -0
- package/dist/migrations/lib/node-pg/discover-domain-migrations.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/discover-domain-migrations.js +101 -0
- package/dist/migrations/lib/node-pg/discover-domain-migrations.js.map +1 -0
- package/dist/migrations/lib/node-pg/domain-migration.d.ts +40 -0
- package/dist/migrations/lib/node-pg/domain-migration.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/domain-migration.js +2 -0
- package/dist/migrations/lib/node-pg/domain-migration.js.map +1 -0
- package/dist/migrations/lib/node-pg/inspect-node-pg-migrations.d.ts +4 -0
- package/dist/migrations/lib/node-pg/inspect-node-pg-migrations.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/inspect-node-pg-migrations.js +22 -0
- package/dist/migrations/lib/node-pg/inspect-node-pg-migrations.js.map +1 -0
- package/dist/migrations/lib/node-pg/load-domain-migration-module.d.ts +8 -0
- package/dist/migrations/lib/node-pg/load-domain-migration-module.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/load-domain-migration-module.js +23 -0
- package/dist/migrations/lib/node-pg/load-domain-migration-module.js.map +1 -0
- package/dist/migrations/lib/node-pg/migration-checksum.d.ts +2 -0
- package/dist/migrations/lib/node-pg/migration-checksum.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/migration-checksum.js +7 -0
- package/dist/migrations/lib/node-pg/migration-checksum.js.map +1 -0
- package/dist/migrations/lib/node-pg/migration-journal-error.d.ts +6 -0
- package/dist/migrations/lib/node-pg/migration-journal-error.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/migration-journal-error.js +11 -0
- package/dist/migrations/lib/node-pg/migration-journal-error.js.map +1 -0
- package/dist/migrations/lib/node-pg/migration-workspace.d.ts +40 -0
- package/dist/migrations/lib/node-pg/migration-workspace.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/migration-workspace.js +31 -0
- package/dist/migrations/lib/node-pg/migration-workspace.js.map +1 -0
- package/dist/migrations/lib/node-pg/node-pg-journal.d.ts +38 -0
- package/dist/migrations/lib/node-pg/node-pg-journal.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/node-pg-journal.js +58 -0
- package/dist/migrations/lib/node-pg/node-pg-journal.js.map +1 -0
- package/dist/migrations/lib/node-pg/plan-migration-order.d.ts +7 -0
- package/dist/migrations/lib/node-pg/plan-migration-order.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/plan-migration-order.js +94 -0
- package/dist/migrations/lib/node-pg/plan-migration-order.js.map +1 -0
- package/dist/migrations/lib/node-pg/read-validated-migration-plan.d.ts +8 -0
- package/dist/migrations/lib/node-pg/read-validated-migration-plan.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/read-validated-migration-plan.js +76 -0
- package/dist/migrations/lib/node-pg/read-validated-migration-plan.js.map +1 -0
- package/dist/migrations/lib/node-pg/run-node-pg-migrations.d.ts +10 -0
- package/dist/migrations/lib/node-pg/run-node-pg-migrations.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/run-node-pg-migrations.js +163 -0
- package/dist/migrations/lib/node-pg/run-node-pg-migrations.js.map +1 -0
- package/dist/migrations/lib/node-pg/shipped-migration-files.d.ts +20 -0
- package/dist/migrations/lib/node-pg/shipped-migration-files.d.ts.map +1 -0
- package/dist/migrations/lib/node-pg/shipped-migration-files.js +110 -0
- package/dist/migrations/lib/node-pg/shipped-migration-files.js.map +1 -0
- package/dist/migrations/lib/public-schema-fingerprint.d.ts +4 -0
- package/dist/migrations/lib/public-schema-fingerprint.d.ts.map +1 -0
- package/dist/migrations/lib/public-schema-fingerprint.js +73 -0
- package/dist/migrations/lib/public-schema-fingerprint.js.map +1 -0
- package/dist/migrations/lib/run-database-migrations.d.ts +11 -0
- package/dist/migrations/lib/run-database-migrations.d.ts.map +1 -0
- package/dist/migrations/lib/run-database-migrations.js +21 -0
- package/dist/migrations/lib/run-database-migrations.js.map +1 -0
- package/dist/migrations/lib/stamp-journal-when-schema-matches.d.ts +8 -0
- package/dist/migrations/lib/stamp-journal-when-schema-matches.d.ts.map +1 -0
- package/dist/migrations/lib/stamp-journal-when-schema-matches.js +86 -0
- package/dist/migrations/lib/stamp-journal-when-schema-matches.js.map +1 -0
- package/dist/postgres.tsbuildinfo +1 -1
- package/dist/testing/create-test-pool.d.ts +1 -1
- package/dist/testing/create-test-pool.d.ts.map +1 -1
- package/dist/testing/create-test-pool.js +1 -1
- package/dist/testing/create-test-pool.js.map +1 -1
- package/dist/testing/start-test-postgres.js +2 -2
- package/dist/testing/start-test-postgres.js.map +1 -1
- package/migrations/README.md +100 -0
- package/package.json +24 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sibling-database-url.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/sibling-database-url.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAS/D;AAED,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAIR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function databaseNameFromUrl(databaseUrl) {
|
|
2
|
+
const url = new URL(databaseUrl);
|
|
3
|
+
const name = decodeURIComponent(url.pathname.replace(/^\//, "")).split("/")[0];
|
|
4
|
+
if (name === undefined || name === "") {
|
|
5
|
+
throw new Error("DATABASE_URL has no database name");
|
|
6
|
+
}
|
|
7
|
+
return name;
|
|
8
|
+
}
|
|
9
|
+
export function siblingDatabaseUrl(databaseUrl, databaseName) {
|
|
10
|
+
const url = new URL(databaseUrl);
|
|
11
|
+
url.pathname = `/${databaseName}`;
|
|
12
|
+
return url.toString();
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=sibling-database-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sibling-database-url.js","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/sibling-database-url.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,WAAmB;IACrD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CACpE,GAAG,CACJ,CAAC,CAAC,CAAC,CAAC;IACL,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,WAAmB,EACnB,YAAoB;IAEpB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACjC,GAAG,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IAClC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PostgresClient as Client } from "../../../index.js";
|
|
2
|
+
import type { DiscoveredDomainMigration } from "./domain-migration.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runs a `buildsIndexesConcurrently` file: its index statements one by one,
|
|
5
|
+
* outside any transaction, so a large live table keeps taking writes while
|
|
6
|
+
* the index builds. The applied row (and the protocol fence, when this is the
|
|
7
|
+
* first graph work) commit afterwards in their own short transaction.
|
|
8
|
+
*
|
|
9
|
+
* Every statement is `IF [NOT] EXISTS`, so a run that dies between the build
|
|
10
|
+
* and the journal row simply re-runs. A failed concurrent build leaves an
|
|
11
|
+
* INVALID index behind; it is dropped before the error surfaces, and again
|
|
12
|
+
* before the next attempt in case the process died before it could clean up.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyConcurrentIndexMigration(client: Client, migration: DiscoveredDomainMigration, recordJournal: (client: Client) => Promise<void>): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=apply-concurrent-index-migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-concurrent-index-migration.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/apply-concurrent-index-migration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMlE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAKvE;;;;;;;;;;GAUG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,yBAAyB,EACpC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/C,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MigrationBuilder } from "node-pg-migrate";
|
|
2
|
+
import { parseConcurrentIndexStatement, } from "../logic/parse-concurrent-index-statement.js";
|
|
3
|
+
import { NodePgMigrationJournalError } from "./migration-journal-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runs a `buildsIndexesConcurrently` file: its index statements one by one,
|
|
6
|
+
* outside any transaction, so a large live table keeps taking writes while
|
|
7
|
+
* the index builds. The applied row (and the protocol fence, when this is the
|
|
8
|
+
* first graph work) commit afterwards in their own short transaction.
|
|
9
|
+
*
|
|
10
|
+
* Every statement is `IF [NOT] EXISTS`, so a run that dies between the build
|
|
11
|
+
* and the journal row simply re-runs. A failed concurrent build leaves an
|
|
12
|
+
* INVALID index behind; it is dropped before the error surfaces, and again
|
|
13
|
+
* before the next attempt in case the process died before it could clean up.
|
|
14
|
+
*/
|
|
15
|
+
export async function applyConcurrentIndexMigration(client, migration, recordJournal) {
|
|
16
|
+
const statements = await readIndexStatements(migration);
|
|
17
|
+
for (const statement of statements) {
|
|
18
|
+
if (statement.kind === "drop")
|
|
19
|
+
await client.query(statement.sql);
|
|
20
|
+
else
|
|
21
|
+
await buildIndex(client, migration, statement);
|
|
22
|
+
}
|
|
23
|
+
await client.query("BEGIN");
|
|
24
|
+
try {
|
|
25
|
+
await recordJournal(client);
|
|
26
|
+
await client.query("COMMIT");
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
await client.query("ROLLBACK");
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Collects the file's SQL without a live database: `pgm.db` refuses, so the
|
|
35
|
+
* file cannot run anything the statement check never saw.
|
|
36
|
+
*/
|
|
37
|
+
async function readIndexStatements(migration) {
|
|
38
|
+
const refuseDirectQuery = () => Promise.reject(new NodePgMigrationJournalError("NODE_PG_MIGRATION_CONCURRENT_INDEX_STATEMENT_REFUSED", migration.journalName, "a buildsIndexesConcurrently migration cannot query the database directly"));
|
|
39
|
+
const builder = new MigrationBuilder({ query: refuseDirectQuery, select: refuseDirectQuery }, undefined, false, { info: () => undefined, warn: () => undefined, error: () => undefined });
|
|
40
|
+
await migration.up(builder);
|
|
41
|
+
const steps = builder.getSqlSteps();
|
|
42
|
+
if (steps.length === 0)
|
|
43
|
+
throw new NodePgMigrationJournalError("NODE_PG_MIGRATION_CONCURRENT_INDEX_STATEMENT_REFUSED", migration.journalName, "a buildsIndexesConcurrently migration must contain at least one index statement");
|
|
44
|
+
return steps.map((step) => {
|
|
45
|
+
const parsed = parseConcurrentIndexStatement(step);
|
|
46
|
+
if (!parsed.ok)
|
|
47
|
+
throw new NodePgMigrationJournalError("NODE_PG_MIGRATION_CONCURRENT_INDEX_STATEMENT_REFUSED", migration.journalName, `refused statement in a buildsIndexesConcurrently migration: ${parsed.reason}`);
|
|
48
|
+
return parsed.statement;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function buildIndex(client, migration, statement) {
|
|
52
|
+
await dropInvalidIndex(client, statement);
|
|
53
|
+
try {
|
|
54
|
+
await client.query(statement.sql);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
await dropInvalidIndex(client, statement).catch(() => undefined);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
if (!(await validIndexExists(client, statement))) {
|
|
61
|
+
await dropInvalidIndex(client, statement);
|
|
62
|
+
throw new NodePgMigrationJournalError("NODE_PG_MIGRATION_CONCURRENT_INDEX_INVALID", migration.journalName, `index ${statement.indexName} is not a valid index on ${statement.tableReference} after its build; another relation may already use the name`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function dropInvalidIndex(client, statement) {
|
|
66
|
+
const invalid = await client.query(`SELECT format('%I.%I', n.nspname, c.relname) AS qualified_name
|
|
67
|
+
FROM pg_index i
|
|
68
|
+
JOIN pg_class c ON c.oid = i.indexrelid
|
|
69
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
70
|
+
WHERE i.indrelid = to_regclass($1) AND c.relname = $2 AND NOT i.indisvalid`, [statement.tableReference, statement.indexName]);
|
|
71
|
+
for (const row of invalid.rows) {
|
|
72
|
+
await client.query(`DROP INDEX CONCURRENTLY IF EXISTS ${row.qualified_name}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function validIndexExists(client, statement) {
|
|
76
|
+
const result = await client.query(`SELECT EXISTS (
|
|
77
|
+
SELECT 1
|
|
78
|
+
FROM pg_index i
|
|
79
|
+
JOIN pg_class c ON c.oid = i.indexrelid
|
|
80
|
+
WHERE i.indrelid = to_regclass($1) AND c.relname = $2 AND i.indisvalid
|
|
81
|
+
) AS exists`, [statement.tableReference, statement.indexName]);
|
|
82
|
+
return result.rows[0]?.exists === true;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=apply-concurrent-index-migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-concurrent-index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,CAAC,CAAC,EAAE,CAAC;QACjD,MAAM,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC1C,MAAM,IAAI,2BAA2B,CACnC,4CAA4C,EAC5C,SAAS,CAAC,WAAW,EACrB,SAAS,SAAS,CAAC,SAAS,4BAA4B,SAAS,CAAC,cAAc,6DAA6D,CAC9I,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,MAAc,EACd,SAA0B;IAE1B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,KAAK,CAChC;;;;gFAI4E,EAC5E,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAChD,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,MAAM,CAAC,KAAK,CAChB,qCAAqC,GAAG,CAAC,cAAc,EAAE,CAC1D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,MAAc,EACd,SAA0B;IAE1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAC/B;;;;;iBAKa,EACb,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAChD,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PostgresClient as Client } from "../../../index.js";
|
|
2
|
+
import type { DiscoveredDomainMigration } from "./domain-migration.js";
|
|
3
|
+
/**
|
|
4
|
+
* The protocol fence, DDL, applied rows and trigger-written checksums commit
|
|
5
|
+
* together. A file exporting `ownTransaction = true` commits alone: earlier
|
|
6
|
+
* files commit before it, and a failure rolls back only the batch it is in.
|
|
7
|
+
* A file exporting `buildsIndexesConcurrently = true` also runs alone, but
|
|
8
|
+
* outside any transaction — the one exception, limited to concurrent index
|
|
9
|
+
* statements (see `applyConcurrentIndexMigration`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyGraphMigrations(client: Client, pending: readonly DiscoveredDomainMigration[], protocolApplied: boolean): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=apply-graph-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-graph-migrations.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/apply-graph-migrations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,IAAI,MAAM,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAQvE;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,SAAS,yBAAyB,EAAE,EAC7C,eAAe,EAAE,OAAO,GACvB,OAAO,CAAC,IAAI,CAAC,CAef"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MigrationBuilder } from "node-pg-migrate";
|
|
2
|
+
import { applyConcurrentIndexMigration } from "./apply-concurrent-index-migration.js";
|
|
3
|
+
import { NodePgMigrationJournalError } from "./migration-journal-error.js";
|
|
4
|
+
import { NODE_PG_APPLIED_TABLE, NODE_PG_GRAPH_PROTOCOL, NODE_PG_JOURNAL_SCHEMA, } from "./node-pg-journal.js";
|
|
5
|
+
/**
|
|
6
|
+
* The protocol fence, DDL, applied rows and trigger-written checksums commit
|
|
7
|
+
* together. A file exporting `ownTransaction = true` commits alone: earlier
|
|
8
|
+
* files commit before it, and a failure rolls back only the batch it is in.
|
|
9
|
+
* A file exporting `buildsIndexesConcurrently = true` also runs alone, but
|
|
10
|
+
* outside any transaction — the one exception, limited to concurrent index
|
|
11
|
+
* statements (see `applyConcurrentIndexMigration`).
|
|
12
|
+
*/
|
|
13
|
+
export async function applyGraphMigrations(client, pending, protocolApplied) {
|
|
14
|
+
let recordProtocol = !protocolApplied;
|
|
15
|
+
for (const batch of splitIntoTransactions(pending)) {
|
|
16
|
+
const [only] = batch;
|
|
17
|
+
if (batch.length === 1 && only?.buildsIndexesConcurrently === true) {
|
|
18
|
+
const writeProtocol = recordProtocol;
|
|
19
|
+
await applyConcurrentIndexMigration(client, only, async (journal) => {
|
|
20
|
+
if (writeProtocol)
|
|
21
|
+
await recordApplied(journal, NODE_PG_GRAPH_PROTOCOL);
|
|
22
|
+
await recordApplied(journal, only.journalName);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
await applyBatch(client, batch, recordProtocol);
|
|
27
|
+
}
|
|
28
|
+
recordProtocol = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function splitIntoTransactions(pending) {
|
|
32
|
+
const batches = [];
|
|
33
|
+
let shared;
|
|
34
|
+
for (const migration of pending) {
|
|
35
|
+
if (migration.ownTransaction === true ||
|
|
36
|
+
migration.buildsIndexesConcurrently === true) {
|
|
37
|
+
batches.push([migration]);
|
|
38
|
+
shared = undefined;
|
|
39
|
+
}
|
|
40
|
+
else if (shared === undefined) {
|
|
41
|
+
shared = [migration];
|
|
42
|
+
batches.push(shared);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
shared.push(migration);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return batches;
|
|
49
|
+
}
|
|
50
|
+
async function applyBatch(client, batch, recordProtocol) {
|
|
51
|
+
await client.query("BEGIN");
|
|
52
|
+
try {
|
|
53
|
+
if (recordProtocol)
|
|
54
|
+
await recordApplied(client, NODE_PG_GRAPH_PROTOCOL);
|
|
55
|
+
const database = {
|
|
56
|
+
query: client.query.bind(client),
|
|
57
|
+
select: async (query, values) => (await client.query(query, values)).rows,
|
|
58
|
+
};
|
|
59
|
+
for (const migration of batch) {
|
|
60
|
+
const builder = new MigrationBuilder(database, undefined, false, {
|
|
61
|
+
info: () => undefined,
|
|
62
|
+
warn: () => undefined,
|
|
63
|
+
error: () => undefined,
|
|
64
|
+
});
|
|
65
|
+
await migration.up(builder);
|
|
66
|
+
if (!builder.isUsingTransaction()) {
|
|
67
|
+
throw new NodePgMigrationJournalError("NODE_PG_MIGRATION_TRANSACTION_REQUIRED", migration.journalName, "dependency migrations must keep SQL and journal changes in one transaction");
|
|
68
|
+
}
|
|
69
|
+
for (const statement of builder.getSqlSteps()) {
|
|
70
|
+
await client.query(statement);
|
|
71
|
+
}
|
|
72
|
+
await recordApplied(client, migration.journalName);
|
|
73
|
+
}
|
|
74
|
+
await client.query("COMMIT");
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
await client.query("ROLLBACK");
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function recordApplied(client, name) {
|
|
82
|
+
await client.query(`INSERT INTO "${NODE_PG_JOURNAL_SCHEMA}"."${NODE_PG_APPLIED_TABLE}" (name, run_on) VALUES ($1, NOW())`, [name]);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=apply-graph-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-graph-migrations.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/apply-graph-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnD,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAEtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,OAA6C,EAC7C,eAAwB;IAExB,IAAI,cAAc,GAAG,CAAC,eAAe,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,qBAAqB,CAAC,OAAO,C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AAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC/B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,MAAc,EAAE,IAAY;IACvD,MAAM,MAAM,CAAC,KAAK,CAChB,gBAAgB,sBAAsB,MAAM,qBAAqB,qCAAqC,EACtG,CAAC,IAAI,CAAC,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DiscoverDomainMigrationsInput, DiscoveredDomainMigration } from "./domain-migration.js";
|
|
2
|
+
export declare function discoverDomainMigrations(input: DiscoverDomainMigrationsInput): Promise<DiscoveredDomainMigration[]>;
|
|
3
|
+
//# sourceMappingURL=discover-domain-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-domain-migrations.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/discover-domain-migrations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EAE1B,MAAM,uBAAuB,CAAC;AAwB/B,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,6BAA6B,GACnC,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAoBtC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { loadDomainMigrationModule } from "./load-domain-migration-module.js";
|
|
4
|
+
import { planMigrationOrder } from "./plan-migration-order.js";
|
|
5
|
+
import { idFromFileName, journalNameFromRelativePath, listMigrationRelativePaths, ownerFromRelativePath, } from "./shipped-migration-files.js";
|
|
6
|
+
const migrationFunctionSchema = z.custom((value) => typeof value === "function");
|
|
7
|
+
const domainMigrationModuleSchema = z.object({
|
|
8
|
+
up: migrationFunctionSchema,
|
|
9
|
+
down: z.union([migrationFunctionSchema, z.literal(false)]),
|
|
10
|
+
dependsOn: z
|
|
11
|
+
.array(z.string().regex(/^\d{14}_[a-z0-9_]+\.migration$/))
|
|
12
|
+
.optional(),
|
|
13
|
+
ownTransaction: z.literal(true).optional(),
|
|
14
|
+
buildsIndexesConcurrently: z.literal(true).optional(),
|
|
15
|
+
});
|
|
16
|
+
export async function discoverDomainMigrations(input) {
|
|
17
|
+
const relativePaths = (await listMigrationRelativePaths(input.workspace)).toSorted((left, right) => idFromFileName(left).localeCompare(idFromFileName(right)));
|
|
18
|
+
const discovered = [];
|
|
19
|
+
const seenIds = new Map();
|
|
20
|
+
for (const relativePath of relativePaths) {
|
|
21
|
+
discovered.push(await readDiscoveredMigration(input.workspace, relativePath, seenIds));
|
|
22
|
+
}
|
|
23
|
+
const appliedNames = input.appliedIds?.map((id) => resolveAppliedMigration(id, discovered));
|
|
24
|
+
return planMigrationOrder(discovered, appliedNames);
|
|
25
|
+
}
|
|
26
|
+
async function readDiscoveredMigration(workspace, relativePath, seenIds) {
|
|
27
|
+
const filePath = join(workspace.root, relativePath);
|
|
28
|
+
const fileId = idFromFileName(relativePath);
|
|
29
|
+
const pathOwner = ownerFromRelativePath(workspace, relativePath);
|
|
30
|
+
assertValidTimestampId(fileId, relativePath);
|
|
31
|
+
const loaded = domainMigrationModuleSchema.safeParse(await loadDomainMigrationModule(filePath, workspace));
|
|
32
|
+
if (!loaded.success) {
|
|
33
|
+
throw new Error(`migration ${relativePath} must export up and an explicit down function or down: false`);
|
|
34
|
+
}
|
|
35
|
+
const { ownTransaction = false, buildsIndexesConcurrently = false } = loaded.data;
|
|
36
|
+
if (loaded.data.dependsOn === undefined) {
|
|
37
|
+
assertLegacyFile(fileId, relativePath, {
|
|
38
|
+
ownTransaction,
|
|
39
|
+
buildsIndexesConcurrently,
|
|
40
|
+
}, seenIds);
|
|
41
|
+
}
|
|
42
|
+
if (ownTransaction && buildsIndexesConcurrently) {
|
|
43
|
+
throw new Error(`migration ${relativePath} exports both ownTransaction and buildsIndexesConcurrently; a concurrent index file already runs alone, outside a transaction`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
id: fileId,
|
|
47
|
+
owner: pathOwner,
|
|
48
|
+
up: loaded.data.up,
|
|
49
|
+
down: loaded.data.down,
|
|
50
|
+
filePath,
|
|
51
|
+
journalName: journalNameFromRelativePath(relativePath),
|
|
52
|
+
...(loaded.data.dependsOn === undefined
|
|
53
|
+
? {}
|
|
54
|
+
: { dependsOn: loaded.data.dependsOn }),
|
|
55
|
+
...(ownTransaction ? { ownTransaction: true } : {}),
|
|
56
|
+
...(buildsIndexesConcurrently ? { buildsIndexesConcurrently: true } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function resolveAppliedMigration(id, discovered) {
|
|
60
|
+
const matches = discovered.filter((entry) => entry.id === id || entry.journalName === id);
|
|
61
|
+
if (matches.length > 1) {
|
|
62
|
+
throw new Error(`applied migration ${id} is ambiguous; use its full journal name`);
|
|
63
|
+
}
|
|
64
|
+
const migration = matches[0];
|
|
65
|
+
if (migration === undefined) {
|
|
66
|
+
throw new Error(`applied migration ${id} is missing from the current build`);
|
|
67
|
+
}
|
|
68
|
+
return migration.journalName;
|
|
69
|
+
}
|
|
70
|
+
function assertLegacyFile(fileId, relativePath, runMode, seenIds) {
|
|
71
|
+
if (runMode.ownTransaction) {
|
|
72
|
+
throw new Error(`migration ${relativePath} exports ownTransaction but no dependsOn; only graph files can commit alone`);
|
|
73
|
+
}
|
|
74
|
+
if (runMode.buildsIndexesConcurrently) {
|
|
75
|
+
throw new Error(`migration ${relativePath} exports buildsIndexesConcurrently but no dependsOn; only graph files can build indexes concurrently`);
|
|
76
|
+
}
|
|
77
|
+
const existingPath = seenIds.get(fileId);
|
|
78
|
+
if (existingPath !== undefined) {
|
|
79
|
+
throw new Error(`migration id ${fileId} is declared by both ${existingPath} and ${relativePath}`);
|
|
80
|
+
}
|
|
81
|
+
seenIds.set(fileId, relativePath);
|
|
82
|
+
}
|
|
83
|
+
function assertValidTimestampId(id, relativePath) {
|
|
84
|
+
const year = Number(id.slice(0, 4));
|
|
85
|
+
const month = Number(id.slice(4, 6));
|
|
86
|
+
const day = Number(id.slice(6, 8));
|
|
87
|
+
const hour = Number(id.slice(8, 10));
|
|
88
|
+
const minute = Number(id.slice(10, 12));
|
|
89
|
+
const second = Number(id.slice(12, 14));
|
|
90
|
+
const utc = new Date(Date.UTC(year, month - 1, day, hour, minute, second));
|
|
91
|
+
const matches = utc.getUTCFullYear() === year &&
|
|
92
|
+
utc.getUTCMonth() + 1 === month &&
|
|
93
|
+
utc.getUTCDate() === day &&
|
|
94
|
+
utc.getUTCHours() === hour &&
|
|
95
|
+
utc.getUTCMinutes() === minute &&
|
|
96
|
+
utc.getUTCSeconds() === second;
|
|
97
|
+
if (!matches) {
|
|
98
|
+
throw new Error(`migration ${relativePath} id ${id} is not a valid UTC timestamp`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=discover-domain-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-domain-migrations.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/discover-domain-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CACtC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CACvC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,EAAE,EAAE,uBAAuB;IAC3B,IAAI,EAAE,CAAC,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M,IAAI,KAAK,CACb,aAAa,YAAY,OAAO,EAAE,+BAA+B,CAClE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MigrationWorkspace } from "./migration-workspace.js";
|
|
2
|
+
import type { MigrationBuilder } from "node-pg-migrate";
|
|
3
|
+
export type DomainMigrationFunction = (pgm: MigrationBuilder) => void | Promise<void>;
|
|
4
|
+
export type DomainMigration = {
|
|
5
|
+
id: string;
|
|
6
|
+
owner: string;
|
|
7
|
+
up: DomainMigrationFunction;
|
|
8
|
+
down: DomainMigrationFunction | false;
|
|
9
|
+
dependsOn?: readonly string[];
|
|
10
|
+
/** Commit this file alone, so its locks end with it. Graph files only. */
|
|
11
|
+
ownTransaction?: true;
|
|
12
|
+
/**
|
|
13
|
+
* Run this file alone and outside any transaction, so its indexes build
|
|
14
|
+
* with `CONCURRENTLY` and a large live table keeps taking writes. Only
|
|
15
|
+
* `CREATE [UNIQUE] INDEX CONCURRENTLY IF NOT EXISTS` and
|
|
16
|
+
* `DROP INDEX CONCURRENTLY IF EXISTS` are allowed; anything else is
|
|
17
|
+
* refused before any SQL runs. Graph files only.
|
|
18
|
+
*/
|
|
19
|
+
buildsIndexesConcurrently?: true;
|
|
20
|
+
};
|
|
21
|
+
export type DiscoveredDomainMigration = DomainMigration & {
|
|
22
|
+
filePath: string;
|
|
23
|
+
journalName: string;
|
|
24
|
+
};
|
|
25
|
+
/** One migration file this build ships, described without loading it. */
|
|
26
|
+
export type ShippedDatabaseMigrationFile = {
|
|
27
|
+
/** File name without `.ts` — the name the applied journal records. */
|
|
28
|
+
journalName: string;
|
|
29
|
+
/** The owner its migration source names (a kit part, or the app). */
|
|
30
|
+
owner: string;
|
|
31
|
+
/** Path relative to the workspace root, POSIX separators. */
|
|
32
|
+
file: string;
|
|
33
|
+
/** SHA-256 of the file's bytes, as the runner checksums it. */
|
|
34
|
+
sha256: string;
|
|
35
|
+
};
|
|
36
|
+
export type DiscoverDomainMigrationsInput = {
|
|
37
|
+
workspace: MigrationWorkspace;
|
|
38
|
+
appliedIds?: readonly string[];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=domain-migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-migration.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/domain-migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,MAAM,uBAAuB,GAAG,CACpC,GAAG,EAAE,gBAAgB,KAClB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,uBAAuB,CAAC;IAC5B,IAAI,EAAE,uBAAuB,GAAG,KAAK,CAAC;IACtC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,0EAA0E;IAC1E,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB;;;;;;OAMG;IACH,yBAAyB,CAAC,EAAE,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,yEAAyE;AACzE,MAAM,MAAM,4BAA4B,GAAG;IACzC,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,kBAAkB,CAAC;IAC9B,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-migration.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/domain-migration.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePgMigrationRunnerInput } from "./run-node-pg-migrations.js";
|
|
2
|
+
/** A consistent read-only snapshot, using the migrator's own history checks. */
|
|
3
|
+
export declare function inspectNodePgMigrations(input: NodePgMigrationRunnerInput): Promise<"legacy-pending" | "node-pg-pending" | "current">;
|
|
4
|
+
//# sourceMappingURL=inspect-node-pg-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-node-pg-migrations.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/inspect-node-pg-migrations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAE9E,gFAAgF;AAChF,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,gBAAgB,GAAG,iBAAiB,GAAG,SAAS,CAAC,CAgB3D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { connectPostgresClient } from "../../../index.js";
|
|
2
|
+
import { discoverDomainMigrations } from "./discover-domain-migrations.js";
|
|
3
|
+
import { relationExists } from "./node-pg-journal.js";
|
|
4
|
+
import { readValidatedMigrationPlan } from "./read-validated-migration-plan.js";
|
|
5
|
+
/** A consistent read-only snapshot, using the migrator's own history checks. */
|
|
6
|
+
export async function inspectNodePgMigrations(input) {
|
|
7
|
+
const discovered = await discoverDomainMigrations({
|
|
8
|
+
workspace: input.workspace,
|
|
9
|
+
});
|
|
10
|
+
const client = await connectPostgresClient(input.databaseUrl);
|
|
11
|
+
try {
|
|
12
|
+
await client.query("BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY");
|
|
13
|
+
if (await relationExists(client, "drizzle", "__drizzle_migrations"))
|
|
14
|
+
return "legacy-pending";
|
|
15
|
+
const { pending } = await readValidatedMigrationPlan(client, discovered);
|
|
16
|
+
return pending.length === 0 ? "current" : "node-pg-pending";
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
await client.end();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=inspect-node-pg-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-node-pg-migrations.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/inspect-node-pg-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAGhF,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAiC;IAEjC,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC;QAChD,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,KAAK,CAChB,6DAA6D,CAC9D,CAAC;QACF,IAAI,MAAM,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,sBAAsB,CAAC;YACjE,OAAO,gBAAgB,CAAC;QAC1B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,0BAA0B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACzE,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;IAC9D,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MigrationWorkspace } from "./migration-workspace.js";
|
|
2
|
+
/**
|
|
3
|
+
* A runner compiled to CommonJS cannot native-`import()` a `.migration.ts`
|
|
4
|
+
* file (`Unexpected token 'export'`). node-pg-migrate already loads these
|
|
5
|
+
* files through jiti, so discovery uses the same loader.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadDomainMigrationModule(filePath: string, workspace: MigrationWorkspace): Promise<unknown>;
|
|
8
|
+
//# sourceMappingURL=load-domain-migration-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-domain-migration-module.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/load-domain-migration-module.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,kBAAkB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAOlB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createJiti } from "jiti";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* A runner compiled to CommonJS cannot native-`import()` a `.migration.ts`
|
|
5
|
+
* file (`Unexpected token 'export'`). node-pg-migrate already loads these
|
|
6
|
+
* files through jiti, so discovery uses the same loader.
|
|
7
|
+
*/
|
|
8
|
+
export async function loadDomainMigrationModule(filePath, workspace) {
|
|
9
|
+
const absolutePath = resolve(filePath);
|
|
10
|
+
const jiti = createJiti(absolutePath, {
|
|
11
|
+
alias: resolvedModuleAliases(workspace),
|
|
12
|
+
jsx: { runtime: "automatic" },
|
|
13
|
+
});
|
|
14
|
+
return jiti.import(absolutePath);
|
|
15
|
+
}
|
|
16
|
+
/** The workspace's aliases, each pointing at one source file under its root. */
|
|
17
|
+
function resolvedModuleAliases(workspace) {
|
|
18
|
+
return Object.fromEntries(Object.entries(workspace.moduleAliases).map(([moduleId, file]) => [
|
|
19
|
+
moduleId,
|
|
20
|
+
resolve(workspace.root, file),
|
|
21
|
+
]));
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=load-domain-migration-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-domain-migration-module.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/load-domain-migration-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,QAAgB,EAChB,SAA6B;IAE7B,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,EAAE;QACpC,KAAK,EAAE,qBAAqB,CAAC,SAAS,CAAC;QACvC,GAAG,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;KAC9B,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AACnC,CAAC;AAED,gFAAgF;AAChF,SAAS,qBAAqB,CAC5B,SAA6B;IAE7B,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;QAChE,QAAQ;QACR,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;KAC9B,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-checksum.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/migration-checksum.ts"],"names":[],"mappings":"AAGA,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGlE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
export async function fileSha256(filePath) {
|
|
4
|
+
const bytes = await readFile(filePath);
|
|
5
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=migration-checksum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-checksum.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/migration-checksum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAgB;IAC/C,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-journal-error.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/migration-journal-error.ts"],"names":[],"mappings":"AAAA,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,YAAY,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAK7D;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class NodePgMigrationJournalError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
migrationId;
|
|
4
|
+
constructor(code, migrationId, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "NodePgMigrationJournalError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.migrationId = migrationId;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=migration-journal-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-journal-error.js","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/migration-journal-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,IAAI,CAAS;IACb,WAAW,CAAS;IAE7B,YAAY,IAAY,EAAE,WAAmB,EAAE,OAAe;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a workspace keeps its migration files, and what a migration file may
|
|
3
|
+
* import. The runner never guesses a layout: the caller names every folder it
|
|
4
|
+
* walks and every module alias a migration resolves, so one runner serves this
|
|
5
|
+
* repository's kit parts and an application's own folder alike.
|
|
6
|
+
*/
|
|
7
|
+
/** One folder the runner walks for `<utcTimestamp>_<slug>.migration.ts` files. */
|
|
8
|
+
export type MigrationSource = {
|
|
9
|
+
/** Folder to walk, relative to the workspace root, POSIX separators. */
|
|
10
|
+
readonly root: string;
|
|
11
|
+
/**
|
|
12
|
+
* Which walked files are migrations, matched against the path relative to
|
|
13
|
+
* the workspace root. Capture group 1 is the owner unless `owner` is set.
|
|
14
|
+
*/
|
|
15
|
+
readonly files: RegExp;
|
|
16
|
+
/** A fixed owner for every file this source finds. */
|
|
17
|
+
readonly owner?: string;
|
|
18
|
+
/**
|
|
19
|
+
* A missing required root throws: a folder that moved must not read as a
|
|
20
|
+
* folder with nothing to apply. A missing optional root is skipped.
|
|
21
|
+
*/
|
|
22
|
+
readonly required: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type MigrationWorkspace = {
|
|
25
|
+
/** Absolute path every source and alias is relative to. */
|
|
26
|
+
readonly root: string;
|
|
27
|
+
readonly sources: readonly MigrationSource[];
|
|
28
|
+
/**
|
|
29
|
+
* Module ids a migration file may import, each mapped to one source file
|
|
30
|
+
* relative to `root`. A deployed image can ship sources without packages.
|
|
31
|
+
*/
|
|
32
|
+
readonly moduleAliases: Readonly<Record<string, string>>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* This repository's layout: every server part's
|
|
36
|
+
* `src/lib/**\/migrations/` folder, owned by the part, plus an optional
|
|
37
|
+
* top-level `migrations/` folder owned by the application.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defaultMigrationWorkspace(root: string): MigrationWorkspace;
|
|
40
|
+
//# sourceMappingURL=migration-workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-workspace.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/node-pg/migration-workspace.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAmB1E"}
|