@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,128 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { CATALOG_STATE, USER_SCHEMAS, } from "./compatibility-catalog-queries.js";
|
|
3
|
+
const READ_FORMAT = {
|
|
4
|
+
search_path: "pg_catalog",
|
|
5
|
+
TimeZone: "UTC",
|
|
6
|
+
DateStyle: "ISO, YMD",
|
|
7
|
+
IntervalStyle: "iso_8601",
|
|
8
|
+
extra_float_digits: "3",
|
|
9
|
+
bytea_output: "hex",
|
|
10
|
+
row_security: "off",
|
|
11
|
+
};
|
|
12
|
+
export class UnsupportedMigrationCompatibilityReplicationStateError extends Error {
|
|
13
|
+
reason;
|
|
14
|
+
code = "MIGRATION_COMPATIBILITY_UNSUPPORTED_REPLICATION_STATE";
|
|
15
|
+
constructor(reason) {
|
|
16
|
+
super(reason === "subscriptions"
|
|
17
|
+
? "Database subscriptions require a dedicated-cluster migration rehearsal; external replication and slot state cannot be compared safely in cloned databases."
|
|
18
|
+
: "Publication-aware migration comparison requires PostgreSQL 15 or newer.");
|
|
19
|
+
this.reason = reason;
|
|
20
|
+
this.name = "UnsupportedMigrationCompatibilityReplicationStateError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compares quiescent private fixture databases using the catalog objects above
|
|
25
|
+
* and every retained value. This is evidence, not a proof arbitrary SQL commutes.
|
|
26
|
+
* Physical OIDs and table-column positions are absent; generated internal FK
|
|
27
|
+
* trigger names are represented by their constraint and trigger behavior.
|
|
28
|
+
*/
|
|
29
|
+
export async function readMigrationCompatibilityState(client) {
|
|
30
|
+
let failure;
|
|
31
|
+
try {
|
|
32
|
+
await refuseUnsupportedReplicationState(client);
|
|
33
|
+
return await withReadFormat(client, () => readCanonicalState(client));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof UnsupportedMigrationCompatibilityReplicationStateError)
|
|
37
|
+
throw error;
|
|
38
|
+
failure = error;
|
|
39
|
+
}
|
|
40
|
+
// Driver errors can contain input values; compatibility evidence never does,
|
|
41
|
+
// so only the SQLSTATE leaves this function, never the driver error itself.
|
|
42
|
+
throw new Error(`Migration compatibility state could not be read deterministically${sqlStateSuffix(failure)}`);
|
|
43
|
+
}
|
|
44
|
+
async function refuseUnsupportedReplicationState(client) {
|
|
45
|
+
const replication = await client.query(`
|
|
46
|
+
SELECT pg_catalog.to_regclass('pg_catalog.pg_publication_namespace') IS NOT NULL AS supports_publication_membership,
|
|
47
|
+
EXISTS (
|
|
48
|
+
SELECT 1 FROM pg_catalog.pg_subscription
|
|
49
|
+
WHERE subdbid = (SELECT oid FROM pg_catalog.pg_database WHERE datname = current_database())
|
|
50
|
+
) AS has_subscriptions
|
|
51
|
+
`);
|
|
52
|
+
for (const state of replication.rows) {
|
|
53
|
+
if (!state.supports_publication_membership) {
|
|
54
|
+
throw new UnsupportedMigrationCompatibilityReplicationStateError("publication-catalog-version");
|
|
55
|
+
}
|
|
56
|
+
if (state.has_subscriptions) {
|
|
57
|
+
throw new UnsupportedMigrationCompatibilityReplicationStateError("subscriptions");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Runs `read` under READ_FORMAT's settings, restoring the previous ones after. */
|
|
62
|
+
async function withReadFormat(client, read) {
|
|
63
|
+
const previous = await client.query("SELECT name, current_setting(name) AS value FROM unnest($1::text[]) settings(name)", [Object.keys(READ_FORMAT)]);
|
|
64
|
+
try {
|
|
65
|
+
for (const [name, value] of Object.entries(READ_FORMAT)) {
|
|
66
|
+
await client.query("SELECT pg_catalog.set_config($1, $2, false)", [
|
|
67
|
+
name,
|
|
68
|
+
value,
|
|
69
|
+
]);
|
|
70
|
+
}
|
|
71
|
+
return await read();
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
for (const { name, value } of previous.rows) {
|
|
75
|
+
await client.query("SELECT pg_catalog.set_config($1, $2, false)", [
|
|
76
|
+
name,
|
|
77
|
+
value,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function readCanonicalState(client) {
|
|
83
|
+
const schema = hashRows(await readCanonicalRows(client, CATALOG_STATE)).sha256;
|
|
84
|
+
const relations = await client.query(`
|
|
85
|
+
SELECT n.nspname AS schema_name, c.relname AS relation_name, c.relkind AS relation_kind
|
|
86
|
+
FROM pg_catalog.pg_class c JOIN (${USER_SCHEMAS}) n ON n.oid = c.relnamespace
|
|
87
|
+
WHERE c.relkind IN ('r', 'p', 'm', 'f', 'S')
|
|
88
|
+
AND NOT (n.nspname = 'public' AND c.relname = 'audit_log')
|
|
89
|
+
ORDER BY n.nspname COLLATE "C", c.relname COLLATE "C"
|
|
90
|
+
`);
|
|
91
|
+
const data = {};
|
|
92
|
+
for (const relation of relations.rows) {
|
|
93
|
+
const name = `${quoteIdentifier(relation.schema_name)}.${quoteIdentifier(relation.relation_name)}`;
|
|
94
|
+
const query = relation.relation_kind === "S"
|
|
95
|
+
? `SELECT jsonb_build_object('last_value', last_value::text, 'is_called', is_called)::text AS canonical FROM ${name}`
|
|
96
|
+
: `SELECT to_jsonb(retained_row)::text AS canonical FROM ${name} retained_row ORDER BY to_jsonb(retained_row)::text COLLATE "C"`;
|
|
97
|
+
data[name] = hashRows(await readCanonicalRows(client, query));
|
|
98
|
+
}
|
|
99
|
+
return { schema, data };
|
|
100
|
+
}
|
|
101
|
+
function sqlStateSuffix(error) {
|
|
102
|
+
return typeof error === "object" &&
|
|
103
|
+
error !== null &&
|
|
104
|
+
"code" in error &&
|
|
105
|
+
typeof error.code === "string" &&
|
|
106
|
+
/^[0-9A-Z]{5}$/.test(error.code)
|
|
107
|
+
? ` (PostgreSQL ${error.code})`
|
|
108
|
+
: "";
|
|
109
|
+
}
|
|
110
|
+
async function readCanonicalRows(client, query) {
|
|
111
|
+
const result = await client.query(query);
|
|
112
|
+
return result.rows.map(({ canonical }) => canonical);
|
|
113
|
+
}
|
|
114
|
+
function hashRows(rows) {
|
|
115
|
+
const hash = createHash("sha256");
|
|
116
|
+
for (const row of rows) {
|
|
117
|
+
hash
|
|
118
|
+
.update(String(Buffer.byteLength(row)))
|
|
119
|
+
.update(":")
|
|
120
|
+
.update(row)
|
|
121
|
+
.update("\n");
|
|
122
|
+
}
|
|
123
|
+
return { rows: rows.length, sha256: hash.digest("hex") };
|
|
124
|
+
}
|
|
125
|
+
function quoteIdentifier(value) {
|
|
126
|
+
return `"${value.replaceAll('"', '""')}"`;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=read-migration-compatibility-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-migration-compatibility-state.js","sourceRoot":"","sources":["../../../src/migrations/compatibility/read-migration-compatibility-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EACL,aAAa,EACb,YAAY,GACb,MAAM,oCAAoC,CAAC;AAE5C,MAAM,WAAW,GAAG;IAClB,WAAW,EAAE,YAAY;IACzB,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,UAAU;IACrB,aAAa,EAAE,UAAU;IACzB,kBAAkB,EAAE,GAAG;IACvB,YAAY,EAAE,KAAK;IACnB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AE,CAAC;AAC3D,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DiscoveredDomainMigration, MigrationWorkspace } from "../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The bytes of every migration and support file, read once from the real
|
|
4
|
+
* workspace, and written into throwaway workspaces one migration at a time so
|
|
5
|
+
* each arrival order sees exactly the files that order has received.
|
|
6
|
+
*/
|
|
7
|
+
export declare class RehearsalSources {
|
|
8
|
+
private readonly workspace;
|
|
9
|
+
private readonly byName;
|
|
10
|
+
private readonly supports;
|
|
11
|
+
private readonly files;
|
|
12
|
+
private constructor();
|
|
13
|
+
static read(workspace: MigrationWorkspace, migrations: readonly DiscoveredDomainMigration[]): Promise<RehearsalSources>;
|
|
14
|
+
/** An empty workspace with every source root, the dependencies, and support files. */
|
|
15
|
+
prepareWorkspace(target: string): Promise<void>;
|
|
16
|
+
addMigration(name: string, root: string): Promise<void>;
|
|
17
|
+
private writeSource;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=rehearsal-sources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehearsal-sources.d.ts","sourceRoot":"","sources":["../../../src/migrations/compatibility/rehearsal-sources.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAIrB;;;;GAIG;AACH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,eAKH;IAEJ,OAAa,IAAI,CACf,SAAS,EAAE,kBAAkB,EAC7B,UAAU,EAAE,SAAS,yBAAyB,EAAE,GAC/C,OAAO,CAAC,gBAAgB,CAAC,CAoB3B;IAED,sFAAsF;IAChF,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQpD;IAEK,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5D;YAEa,WAAW;CAU1B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
4
|
+
import { migrationSupportFiles } from "./migration-support-files.js";
|
|
5
|
+
/**
|
|
6
|
+
* The bytes of every migration and support file, read once from the real
|
|
7
|
+
* workspace, and written into throwaway workspaces one migration at a time so
|
|
8
|
+
* each arrival order sees exactly the files that order has received.
|
|
9
|
+
*/
|
|
10
|
+
export class RehearsalSources {
|
|
11
|
+
workspace;
|
|
12
|
+
byName;
|
|
13
|
+
supports;
|
|
14
|
+
files;
|
|
15
|
+
constructor(workspace, byName, supports, files) {
|
|
16
|
+
this.workspace = workspace;
|
|
17
|
+
this.byName = byName;
|
|
18
|
+
this.supports = supports;
|
|
19
|
+
this.files = files;
|
|
20
|
+
}
|
|
21
|
+
static async read(workspace, migrations) {
|
|
22
|
+
const migrationPaths = migrations.map((migration) => relative(workspace.root, migration.filePath));
|
|
23
|
+
const supports = await migrationSupportFiles(workspace, migrationPaths);
|
|
24
|
+
const files = new Map(await Promise.all([...migrationPaths, ...supports].map(async (path) => [path, await readFile(join(workspace.root, path))])));
|
|
25
|
+
const byName = new Map(migrations.map((migration) => [migration.journalName, migration]));
|
|
26
|
+
return new RehearsalSources(workspace, byName, supports, files);
|
|
27
|
+
}
|
|
28
|
+
/** An empty workspace with every source root, the dependencies, and support files. */
|
|
29
|
+
async prepareWorkspace(target) {
|
|
30
|
+
for (const source of this.workspace.sources)
|
|
31
|
+
await mkdir(join(target, source.root), { recursive: true });
|
|
32
|
+
const modules = join(this.workspace.root, "node_modules");
|
|
33
|
+
if (existsSync(modules))
|
|
34
|
+
await symlink(modules, join(target, "node_modules"), "dir");
|
|
35
|
+
for (const support of this.supports)
|
|
36
|
+
await this.writeSource(support, target);
|
|
37
|
+
}
|
|
38
|
+
async addMigration(name, root) {
|
|
39
|
+
const migration = this.byName.get(name);
|
|
40
|
+
if (migration === undefined)
|
|
41
|
+
throw new Error(`missing rehearsal migration ${name}`);
|
|
42
|
+
await this.writeSource(relative(this.workspace.root, migration.filePath), root);
|
|
43
|
+
}
|
|
44
|
+
async writeSource(path, root) {
|
|
45
|
+
if (path.startsWith("..") || isAbsolute(path))
|
|
46
|
+
throw new Error("migration source is outside the selected workspace");
|
|
47
|
+
const bytes = this.files.get(path);
|
|
48
|
+
if (bytes === undefined)
|
|
49
|
+
throw new Error(`missing rehearsal source ${path}`);
|
|
50
|
+
const target = join(root, path);
|
|
51
|
+
await mkdir(dirname(target), { recursive: true });
|
|
52
|
+
await writeFile(target, bytes);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=rehearsal-sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehearsal-sources.js","sourceRoot":"","sources":["../../../src/migrations/compatibility/rehearsal-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAOhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAER,SAAS;IACT,MAAM;IACN,Q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,MAAM,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MigrationWorkspace } from "../index.js";
|
|
2
|
+
import type { RehearsalPostgres } from "../../testing/index.js";
|
|
3
|
+
export type MigrationCompatibilityResult = {
|
|
4
|
+
orders: number;
|
|
5
|
+
pending: number;
|
|
6
|
+
baselineMs: number;
|
|
7
|
+
replayMs: number;
|
|
8
|
+
baselineRowsByRelation: Readonly<Record<string, number>>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Applies the baseline once, then replays every arrival order of the pending
|
|
12
|
+
* migrations on a copy of it, and refuses when two orders leave a different
|
|
13
|
+
* schema or different retained data, or when any order changes cluster roles.
|
|
14
|
+
*/
|
|
15
|
+
export declare function rehearseMigrationCompatibility(input: {
|
|
16
|
+
workspace: MigrationWorkspace;
|
|
17
|
+
baselineNames: readonly string[];
|
|
18
|
+
postgres: RehearsalPostgres;
|
|
19
|
+
}): Promise<MigrationCompatibilityResult>;
|
|
20
|
+
//# sourceMappingURL=rehearse-migration-compatibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehearse-migration-compatibility.d.ts","sourceRoot":"","sources":["../../../src/migrations/compatibility/rehearse-migration-compatibility.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAKrB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMhE,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC1D,CAAC;AAUF;;;;GAIG;AACH,wBAAsB,8BAA8B,CAAC,KAAK,EAAE;IAC1D,SAAS,EAAE,kBAAkB,CAAC;IAC9B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAkCxC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { connectPostgresClient } from "../../index.js";
|
|
5
|
+
import { discoverDomainMigrations, runNodePgMigrations, } from "../index.js";
|
|
6
|
+
import { planMigrationCompatibility } from "./plan-migration-compatibility.js";
|
|
7
|
+
import { readMigrationCompatibilityState } from "./read-migration-compatibility-state.js";
|
|
8
|
+
import { RehearsalSources } from "./rehearsal-sources.js";
|
|
9
|
+
const NOTHING_PENDING = {
|
|
10
|
+
orders: 0,
|
|
11
|
+
pending: 0,
|
|
12
|
+
baselineMs: 0,
|
|
13
|
+
replayMs: 0,
|
|
14
|
+
baselineRowsByRelation: {},
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Applies the baseline once, then replays every arrival order of the pending
|
|
18
|
+
* migrations on a copy of it, and refuses when two orders leave a different
|
|
19
|
+
* schema or different retained data, or when any order changes cluster roles.
|
|
20
|
+
*/
|
|
21
|
+
export async function rehearseMigrationCompatibility(input) {
|
|
22
|
+
const migrations = await discoverDomainMigrations({
|
|
23
|
+
workspace: input.workspace,
|
|
24
|
+
});
|
|
25
|
+
const plan = planMigrationCompatibility(migrations, input.baselineNames);
|
|
26
|
+
if (plan.orders.length === 0)
|
|
27
|
+
return NOTHING_PENDING;
|
|
28
|
+
const sources = await RehearsalSources.read(input.workspace, migrations);
|
|
29
|
+
const scratch = await mkdtemp(join(tmpdir(), "dads-migration-rehearsal-"));
|
|
30
|
+
try {
|
|
31
|
+
const started = performance.now();
|
|
32
|
+
const baseline = await applyBaseline(input, sources, plan.baseline, scratch);
|
|
33
|
+
const baselineMs = performance.now() - started;
|
|
34
|
+
const replayStarted = performance.now();
|
|
35
|
+
await replayEveryOrder(input, sources, plan, baseline, scratch);
|
|
36
|
+
return {
|
|
37
|
+
orders: plan.orders.length,
|
|
38
|
+
pending: plan.orders[0]?.length ?? 0,
|
|
39
|
+
baselineMs,
|
|
40
|
+
replayMs: performance.now() - replayStarted,
|
|
41
|
+
baselineRowsByRelation: Object.fromEntries(Object.entries(baseline.state.data).map(([name, result]) => [
|
|
42
|
+
name,
|
|
43
|
+
result.rows,
|
|
44
|
+
])),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await rm(scratch, { recursive: true, force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function applyBaseline(input, sources, baselineNames, scratch) {
|
|
52
|
+
const root = join(scratch, "baseline");
|
|
53
|
+
await sources.prepareWorkspace(root);
|
|
54
|
+
for (const name of baselineNames)
|
|
55
|
+
await sources.addMigration(name, root);
|
|
56
|
+
const database = await input.postgres.createDatabase();
|
|
57
|
+
await runNodePgMigrations({
|
|
58
|
+
databaseUrl: database.url,
|
|
59
|
+
workspace: { ...input.workspace, root },
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
name: database.name,
|
|
63
|
+
state: await readState(database.url),
|
|
64
|
+
cluster: await input.postgres.clusterFingerprint(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function replayEveryOrder(input, sources, plan, baseline, scratch) {
|
|
68
|
+
let reference;
|
|
69
|
+
for (const [index, order] of plan.orders.entries()) {
|
|
70
|
+
const root = join(scratch, `order-${index}`);
|
|
71
|
+
await sources.prepareWorkspace(root);
|
|
72
|
+
for (const name of plan.baseline)
|
|
73
|
+
await sources.addMigration(name, root);
|
|
74
|
+
const database = await input.postgres.createDatabase(baseline.name);
|
|
75
|
+
for (const name of order) {
|
|
76
|
+
await sources.addMigration(name, root);
|
|
77
|
+
await runNodePgMigrations({
|
|
78
|
+
databaseUrl: database.url,
|
|
79
|
+
workspace: { ...input.workspace, root },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if ((await input.postgres.clusterFingerprint()) !== baseline.cluster)
|
|
83
|
+
throw new Error("pending migrations change cluster roles/settings; use a dedicated fresh-cluster rehearsal before deployment");
|
|
84
|
+
const state = await readState(database.url);
|
|
85
|
+
if (reference !== undefined &&
|
|
86
|
+
JSON.stringify(reference) !== JSON.stringify(state))
|
|
87
|
+
throw new Error(`migration compatibility differs for arrival order ${order.join(" -> ")}; declare the actual prerequisite and verify retained data`);
|
|
88
|
+
reference = state;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function readState(databaseUrl) {
|
|
92
|
+
const client = await connectPostgresClient(databaseUrl);
|
|
93
|
+
try {
|
|
94
|
+
return await readMigrationCompatibilityState(client);
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
await client.end();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=rehearse-migration-compatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehearse-migration-compatibility.js","sourceRoot":"","sources":["../../../src/migrations/compatibility/rehearse-migration-compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EACL,wBAAwB,EAExB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,yCAAyC,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC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;IACpB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,WAAmB;IAC1C,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC;QACH,OAAO,MAAM,+BAA+B,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { describeMigrationFailure, type MigrationFailure, } from "./lib/logic/describe-migration-failure.js";
|
|
2
|
+
export { parseMigrationEnvironment, type MigrationEnvironment, } from "./lib/logic/parse-migration-environment.js";
|
|
3
|
+
export { discoverDomainMigrations } from "./lib/node-pg/discover-domain-migrations.js";
|
|
4
|
+
export type { DiscoverDomainMigrationsInput, DiscoveredDomainMigration, DomainMigration, DomainMigrationFunction, } from "./lib/node-pg/domain-migration.js";
|
|
5
|
+
export { fileSha256 } from "./lib/node-pg/migration-checksum.js";
|
|
6
|
+
export { inspectNodePgMigrations } from "./lib/node-pg/inspect-node-pg-migrations.js";
|
|
7
|
+
export { planMigrationOrder } from "./lib/node-pg/plan-migration-order.js";
|
|
8
|
+
export { NODE_PG_APPLIED_TABLE, NODE_PG_CHECKSUM_TABLE, NODE_PG_JOURNAL_SCHEMA, NodePgMigrationJournalError, runNodePgMigrations, stampNodePgJournalAsApplied, } from "./lib/node-pg/run-node-pg-migrations.js";
|
|
9
|
+
export { runDatabaseMigrations, type MigrationLog, type RunDatabaseMigrationsInput, } from "./lib/run-database-migrations.js";
|
|
10
|
+
export { defaultMigrationWorkspace, type MigrationSource, type MigrationWorkspace, } from "./lib/node-pg/migration-workspace.js";
|
|
11
|
+
export { EquivalentSchemaMismatchError, stampJournalWhenSchemaMatches, } from "./lib/stamp-journal-when-schema-matches.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,KAAK,gBAAgB,GACtB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AACvF,YAAY,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,uBAAuB,GACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,0BAA0B,GAChC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,EACzB,KAAK,eAAe,EACpB,KAAK,kBAAkB,GACxB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,4CAA4C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { describeMigrationFailure, } from "./lib/logic/describe-migration-failure.js";
|
|
2
|
+
export { parseMigrationEnvironment, } from "./lib/logic/parse-migration-environment.js";
|
|
3
|
+
export { discoverDomainMigrations } from "./lib/node-pg/discover-domain-migrations.js";
|
|
4
|
+
export { fileSha256 } from "./lib/node-pg/migration-checksum.js";
|
|
5
|
+
export { inspectNodePgMigrations } from "./lib/node-pg/inspect-node-pg-migrations.js";
|
|
6
|
+
export { planMigrationOrder } from "./lib/node-pg/plan-migration-order.js";
|
|
7
|
+
export { NODE_PG_APPLIED_TABLE, NODE_PG_CHECKSUM_TABLE, NODE_PG_JOURNAL_SCHEMA, NodePgMigrationJournalError, runNodePgMigrations, stampNodePgJournalAsApplied, } from "./lib/node-pg/run-node-pg-migrations.js";
|
|
8
|
+
export { runDatabaseMigrations, } from "./lib/run-database-migrations.js";
|
|
9
|
+
export { defaultMigrationWorkspace, } from "./lib/node-pg/migration-workspace.js";
|
|
10
|
+
export { EquivalentSchemaMismatchError, stampJournalWhenSchemaMatches, } from "./lib/stamp-journal-when-schema-matches.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,yBAAyB,GAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6CAA6C,CAAC;AAOvF,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,qBAAqB,GAGtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,yBAAyB,GAG1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,4CAA4C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only view of what a build ships and what a database ran, for
|
|
3
|
+
* reporting (`@dads-framework/postgres/migrations/journal-status`). A separate
|
|
4
|
+
* entry so a reader such as the API never bundles the runner: nothing behind
|
|
5
|
+
* it imports node-pg-migrate or the migration module loader.
|
|
6
|
+
*/
|
|
7
|
+
export type { ShippedDatabaseMigrationFile } from "./lib/node-pg/domain-migration.js";
|
|
8
|
+
export { type AppliedNodePgMigration, type NodePgJournalQueryClient, readAppliedNodePgJournal, } from "./lib/node-pg/node-pg-journal.js";
|
|
9
|
+
export { listShippedDatabaseMigrations } from "./lib/node-pg/shipped-migration-files.js";
|
|
10
|
+
export { defaultMigrationWorkspace, type MigrationWorkspace, } from "./lib/node-pg/migration-workspace.js";
|
|
11
|
+
//# sourceMappingURL=journal-status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-status.d.ts","sourceRoot":"","sources":["../../src/migrations/journal-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACtF,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EACL,yBAAyB,EACzB,KAAK,kBAAkB,GACxB,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { readAppliedNodePgJournal, } from "./lib/node-pg/node-pg-journal.js";
|
|
2
|
+
export { listShippedDatabaseMigrations } from "./lib/node-pg/shipped-migration-files.js";
|
|
3
|
+
export { defaultMigrationWorkspace, } from "./lib/node-pg/migration-workspace.js";
|
|
4
|
+
//# sourceMappingURL=journal-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-status.js","sourceRoot":"","sources":["../../src/migrations/journal-status.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EACL,yBAAyB,GAE1B,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type MigrationFailure = {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly driverCode?: string;
|
|
4
|
+
};
|
|
5
|
+
/** Keeps operational discriminants while excluding messages and connection data. */
|
|
6
|
+
export declare function describeMigrationFailure(error: unknown): MigrationFailure;
|
|
7
|
+
//# sourceMappingURL=describe-migration-failure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe-migration-failure.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/describe-migration-failure.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAWzE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const migrationFailureSchema = z.object({
|
|
3
|
+
name: z.string().optional(),
|
|
4
|
+
code: z.union([z.string(), z.number()]).optional(),
|
|
5
|
+
});
|
|
6
|
+
/** Keeps operational discriminants while excluding messages and connection data. */
|
|
7
|
+
export function describeMigrationFailure(error) {
|
|
8
|
+
const parsed = migrationFailureSchema.safeParse(error);
|
|
9
|
+
if (!parsed.success) {
|
|
10
|
+
return { name: "UnknownError" };
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
name: parsed.data.name ?? "Error",
|
|
14
|
+
...(parsed.data.code === undefined
|
|
15
|
+
? {}
|
|
16
|
+
: { driverCode: String(parsed.data.code) }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=describe-migration-failure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe-migration-failure.js","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/describe-migration-failure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC;AAOH,oFAAoF;AACpF,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,MAAM,MAAM,GAAG,sBAAsB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IAClC,CAAC;IACD,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO;QACjC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;YAChC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-stamp-decision.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/journal-stamp-decision.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,qBAAqB,CAAC;AAElE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GAAG,oBAAoB,CAQvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"journal-stamp-decision.js","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/journal-stamp-decision.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,KAGpC;IACC,IAAI,KAAK,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The only statements a `buildsIndexesConcurrently` migration may run. Those
|
|
3
|
+
* files run outside a transaction, so anything else they could carry would
|
|
4
|
+
* lose the all-or-nothing guarantee every other migration keeps.
|
|
5
|
+
*/
|
|
6
|
+
export type ConcurrentIndexStatement = {
|
|
7
|
+
kind: "create";
|
|
8
|
+
sql: string;
|
|
9
|
+
/** The index's name as PostgreSQL stores it (unquoted, case-folded). */
|
|
10
|
+
indexName: string;
|
|
11
|
+
/** The table as written, for `to_regclass` to resolve. */
|
|
12
|
+
tableReference: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "drop";
|
|
15
|
+
sql: string;
|
|
16
|
+
};
|
|
17
|
+
export type ConcurrentIndexStatementParse = {
|
|
18
|
+
ok: true;
|
|
19
|
+
statement: ConcurrentIndexStatement;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
reason: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Accepts one statement — a `pgm.sql` step or a `pgm.createIndex` /
|
|
26
|
+
* `pgm.dropIndex` with `concurrently` and `ifNotExists` / `ifExists`.
|
|
27
|
+
* A `;` anywhere but the end, or any comment, is refused: a second statement
|
|
28
|
+
* hidden behind one would run outside the transaction too.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseConcurrentIndexStatement(step: string): ConcurrentIndexStatementParse;
|
|
31
|
+
//# sourceMappingURL=parse-concurrent-index-statement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-concurrent-index-statement.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/parse-concurrent-index-statement.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAChC;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,MAAM,MAAM,6BAA6B,GACrC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,wBAAwB,CAAA;CAAE,GACjD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAwBlC;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,GACX,6BAA6B,CA0B/B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const IDENTIFIER = String.raw `(?:"(?:[^"]|"")+"|[A-Za-z_][A-Za-z0-9_$]*)`;
|
|
2
|
+
const QUALIFIED = String.raw `${IDENTIFIER}(?:\s*\.\s*${IDENTIFIER})?`;
|
|
3
|
+
const CREATE_PATTERN = new RegExp(String.raw `^CREATE\s+(?:UNIQUE\s+)?INDEX\s+CONCURRENTLY\s+IF\s+NOT\s+EXISTS\s+(${IDENTIFIER})\s+ON\s+(?:ONLY\s+)?(${QUALIFIED})[\s(]`, "i");
|
|
4
|
+
const DROP_PATTERN = new RegExp(String.raw `^DROP\s+INDEX\s+CONCURRENTLY\s+IF\s+EXISTS\s+${QUALIFIED}(?:\s+RESTRICT)?$`, "i");
|
|
5
|
+
/**
|
|
6
|
+
* NAMEDATALEN - 1. PostgreSQL silently truncates a longer identifier, so the
|
|
7
|
+
* runner's post-build lookup by the written name would never find the index
|
|
8
|
+
* (node-pg-migrate's generated `<table>_<columns>_index` names can pass it).
|
|
9
|
+
*/
|
|
10
|
+
const MAX_IDENTIFIER_BYTES = 63;
|
|
11
|
+
const ALLOWED = "only CREATE [UNIQUE] INDEX CONCURRENTLY IF NOT EXISTS <name> ON <table> ... and DROP INDEX CONCURRENTLY IF EXISTS <name> are allowed";
|
|
12
|
+
/**
|
|
13
|
+
* Accepts one statement — a `pgm.sql` step or a `pgm.createIndex` /
|
|
14
|
+
* `pgm.dropIndex` with `concurrently` and `ifNotExists` / `ifExists`.
|
|
15
|
+
* A `;` anywhere but the end, or any comment, is refused: a second statement
|
|
16
|
+
* hidden behind one would run outside the transaction too.
|
|
17
|
+
*/
|
|
18
|
+
export function parseConcurrentIndexStatement(step) {
|
|
19
|
+
const sql = step.trim().replace(/;\s*$/, "").trim();
|
|
20
|
+
if (sql.includes(";"))
|
|
21
|
+
return { ok: false, reason: `one statement per step; ${ALLOWED}` };
|
|
22
|
+
if (sql.includes("--") || sql.includes("/*"))
|
|
23
|
+
return { ok: false, reason: `comments are not allowed; ${ALLOWED}` };
|
|
24
|
+
const create = CREATE_PATTERN.exec(sql);
|
|
25
|
+
if (create !== null) {
|
|
26
|
+
const [, rawName, tableReference] = create;
|
|
27
|
+
if (rawName === undefined || tableReference === undefined)
|
|
28
|
+
return { ok: false, reason: ALLOWED };
|
|
29
|
+
const indexName = storedIdentifier(rawName);
|
|
30
|
+
if (Buffer.byteLength(indexName, "utf8") > MAX_IDENTIFIER_BYTES)
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
reason: `index name ${indexName} is longer than ${MAX_IDENTIFIER_BYTES} bytes, so PostgreSQL would truncate it and the build could not be checked; pass an explicit short name (pgm.createIndex(..., { name: "<name>" }))`,
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
statement: { kind: "create", sql, indexName, tableReference },
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (DROP_PATTERN.test(sql))
|
|
41
|
+
return { ok: true, statement: { kind: "drop", sql } };
|
|
42
|
+
return { ok: false, reason: ALLOWED };
|
|
43
|
+
}
|
|
44
|
+
/** `"Mixed""Name"` becomes `Mixed"Name`; `Plain` becomes `plain`, as PostgreSQL folds it. */
|
|
45
|
+
function storedIdentifier(raw) {
|
|
46
|
+
return raw.startsWith('"')
|
|
47
|
+
? raw.slice(1, -1).replaceAll('""', '"')
|
|
48
|
+
: raw.toLowerCase();
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=parse-concurrent-index-statement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-concurrent-index-statement.js","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/parse-concurrent-index-statement.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAA,4CAA4C,CAAC;AAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAA,GAAG,UAAU,cAAc,UAAU,IAAI,CAAC;AAEtE,MAAM,cAAc,GAAG,IAAI,MAAM,CAC/B,MAAM,CAAC,GAAG,CAAA,uEAAuE,UAAU,yBAAyB,SAAS,QAAQ,EACrI,GAAG,CACJ,CAAC;AACF,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,MAAM,CAAC,GAAG,CAAA,gDAAgD,SAAS,mBAAmB,EACtF,GAAG,CACJ,CAAC;AAEF;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC,MAAM,OAAO,GACX,sIAAsI,CAAC;AAEzI;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAY;IAEZ,MA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M,EAAE,GAAG,EAAE,EAAE,CAAC;IACxD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACxC,CAAC;AAED,6FAA6F;AAC7F,SAAS,gBAAgB,CAAC,GAAW;IACnC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QACxB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC;QACxC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const migrationEnvironmentSchema: z.ZodPipe<z.ZodObject<{
|
|
3
|
+
DATABASE_URL: z.ZodString;
|
|
4
|
+
WORKSPACE_ROOT: z.ZodDefault<z.ZodString>;
|
|
5
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
6
|
+
databaseUrl: string;
|
|
7
|
+
workspaceRoot: string;
|
|
8
|
+
}, {
|
|
9
|
+
DATABASE_URL: string;
|
|
10
|
+
WORKSPACE_ROOT: string;
|
|
11
|
+
}>>;
|
|
12
|
+
export type MigrationEnvironment = z.infer<typeof migrationEnvironmentSchema>;
|
|
13
|
+
/** Parses the complete environment contract needed by the migration process. */
|
|
14
|
+
export declare function parseMigrationEnvironment(input: unknown): MigrationEnvironment;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=parse-migration-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-migration-environment.d.ts","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/parse-migration-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,0BAA0B;;;;;;;;;GAQ3B,CAAC;AAEN,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E,gFAAgF;AAChF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GACb,oBAAoB,CAEtB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const migrationEnvironmentSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
DATABASE_URL: z.string().min(1),
|
|
5
|
+
WORKSPACE_ROOT: z.string().min(1).default("."),
|
|
6
|
+
})
|
|
7
|
+
.transform((environment) => ({
|
|
8
|
+
databaseUrl: environment.DATABASE_URL,
|
|
9
|
+
workspaceRoot: environment.WORKSPACE_ROOT,
|
|
10
|
+
}));
|
|
11
|
+
/** Parses the complete environment contract needed by the migration process. */
|
|
12
|
+
export function parseMigrationEnvironment(input) {
|
|
13
|
+
return migrationEnvironmentSchema.parse(input);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=parse-migration-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-migration-environment.js","sourceRoot":"","sources":["../../../../src/migrations/lib/logic/parse-migration-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,0BAA0B,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;CAC/C,CAAC;KACD,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC3B,WAAW,EAAE,WAAW,CAAC,YAAY;IACrC,aAAa,EAAE,WAAW,CAAC,cAAc;CAC1C,CAAC,CAAC,CAAC;AAIN,gFAAgF;AAChF,MAAM,UAAU,yBAAyB,CACvC,KAAc;IAEd,OAAO,0BAA0B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC"}
|