okmodel 0.5.1 → 0.7.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 +100 -1116
- package/dist/adapters/capabilities.d.ts +3 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +14 -1
- package/dist/adapters/pg/cursor.d.ts +17 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +20 -0
- package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
- package/dist/adapters/pg/nodepostgres.d.ts +12 -0
- package/dist/adapters/pg/pglite-wire.d.ts +24 -0
- package/dist/adapters/pg/pglite.d.ts +10 -0
- package/dist/adapters/pg/postgres-extra.d.ts +41 -3
- package/dist/adapters/pg/reserved.d.ts +42 -0
- package/dist/adapters/pg/session.d.ts +0 -18
- package/dist/contracts/catalog/document.d.ts +19 -5
- package/dist/contracts/catalog/object.d.ts +2 -1
- package/dist/contracts/catalog/policy.d.ts +48 -0
- package/dist/contracts/catalog/types.d.ts +25 -1
- package/dist/contracts/catalog/view.d.ts +2 -0
- package/dist/contracts/connection.d.ts +7 -6
- package/dist/contracts/internal.js +1 -1
- package/dist/contracts/location.d.ts +10 -0
- package/dist/dialects/pg/column.d.ts +13 -2
- package/dist/dialects/pg/ddl.d.ts +37 -1
- package/dist/dialects/pg/emit.d.ts +19 -1
- package/dist/dialects/pg/errors.d.ts +32 -1
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/pg-trgm.js +1 -1
- package/dist/dialects/pg/filter-parse.d.ts +5 -4
- package/dist/dialects/pg/floor.d.ts +68 -0
- package/dist/dialects/pg/fn/index.js +2 -2
- package/dist/dialects/pg/index.d.ts +8 -2
- package/dist/dialects/pg/index.js +67 -171
- package/dist/dialects/pg/introspect.d.ts +7 -0
- package/dist/dialects/pg/keys.d.ts +11 -8
- package/dist/dialects/pg/model.d.ts +47 -2
- package/dist/dialects/pg/morph.d.ts +43 -0
- package/dist/dialects/pg/operator-fit.d.ts +2 -2
- package/dist/dialects/pg/operators.d.ts +14 -7
- package/dist/dialects/pg/ops/bucket.d.ts +65 -0
- package/dist/dialects/pg/ops/inc.d.ts +2 -2
- package/dist/dialects/pg/ops/matches.d.ts +9 -12
- package/dist/dialects/pg/ops/relevance.d.ts +13 -0
- package/dist/dialects/pg/ops/search-query.d.ts +22 -0
- package/dist/dialects/pg/ops/window.d.ts +103 -0
- package/dist/dialects/pg/owner.d.ts +42 -0
- package/dist/dialects/pg/path-endpoint.d.ts +20 -0
- package/dist/dialects/pg/preset.d.ts +1 -1
- package/dist/dialects/pg/relations.d.ts +100 -3
- package/dist/dialects/pg/role/check.d.ts +3 -0
- package/dist/dialects/pg/role/index.d.ts +71 -6
- package/dist/dialects/pg/role/sql.d.ts +11 -0
- package/dist/dialects/pg/schema.d.ts +33 -3
- package/dist/dialects/pg/table.d.ts +25 -3
- package/dist/dialects/pg/tenancy.d.ts +45 -3
- package/dist/dialects/pg/view/client.d.ts +19 -1
- package/dist/dialects/pg/view/index.d.ts +4 -0
- package/dist/dialects/pg/view/index.js +21 -178
- package/dist/dialects/pg/view/refresh.d.ts +24 -0
- package/dist/runtime/aggregate.d.ts +8 -2
- package/dist/runtime/batch.d.ts +1 -1
- package/dist/runtime/bucket-group.d.ts +70 -0
- package/dist/runtime/conflict.d.ts +24 -6
- package/dist/runtime/drift.d.ts +9 -0
- package/dist/runtime/include.d.ts +0 -8
- package/dist/runtime/inflight.d.ts +14 -0
- package/dist/runtime/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -5
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.d.ts +1 -0
- package/dist/runtime/pg/pglite.js +9 -8
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +113 -15
- package/dist/runtime/predicate.d.ts +19 -0
- package/dist/runtime/read-stream.d.ts +13 -16
- package/dist/runtime/result-name.d.ts +17 -0
- package/dist/runtime/safety/index.js +1 -1
- package/dist/runtime/server-check.d.ts +3 -3
- package/dist/runtime/sort-bind.d.ts +21 -0
- package/dist/runtime/sort.d.ts +56 -0
- package/dist/runtime/sync.d.ts +70 -0
- package/dist/runtime/tenancy/composite.d.ts +26 -0
- package/dist/runtime/tenancy/context.d.ts +16 -0
- package/dist/runtime/tenancy/index.d.ts +9 -5
- package/dist/runtime/tenancy/index.js +1511 -38
- package/dist/runtime/tenancy/path.d.ts +87 -0
- package/dist/runtime/tenancy/rls.d.ts +67 -0
- package/dist/runtime/tenancy/via.d.ts +22 -0
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +187 -17
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +231 -23
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/version.d.ts +39 -0
- package/dist/runtime/window.d.ts +21 -0
- package/dist/runtime/write.d.ts +55 -3
- package/dist/shared/{krxx77g0.js → 14vx95q4.js} +12 -18
- package/dist/shared/1est4ezg.js +313 -0
- package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
- package/dist/shared/1w508jbr.js +1611 -0
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/2d3xq4ps.js +9 -0
- package/dist/shared/2shdbn8q.js +23 -0
- package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
- package/dist/shared/3v7t1yrv.js +208 -0
- package/dist/shared/5e3tf63j.js +220 -0
- package/dist/shared/5fe3kbsh.js +10 -0
- package/dist/shared/5v3xf80k.js +37 -0
- package/dist/shared/{51mvgj8w.js → 63qtkrca.js} +130 -3
- package/dist/shared/{gbtcc2d7.js → 67txcrcw.js} +62 -66
- package/dist/shared/79dt02vc.js +12 -0
- package/dist/shared/{v36c5g6p.js → 7k9grvf6.js} +407 -14
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7mnme5tn.js +8 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/{87jvvhnt.js → 81ebdx9p.js} +48 -68
- package/dist/shared/{szm0cksa.js → 8skf0cam.js} +34 -6
- package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
- package/dist/shared/9y3mmmh1.js +436 -0
- package/dist/shared/ab9gmbwy.js +213 -0
- package/dist/shared/{sycnx8gt.js → ax7qv55k.js} +18 -8
- package/dist/shared/{f5cw5q5r.js → aytqh5y2.js} +6 -4
- package/dist/shared/{fancm5pt.js → b5pftnn2.js} +138 -15
- package/dist/shared/{efmy2gcg.js → b76b8d95.js} +2 -2
- package/dist/shared/bdk4sty6.js +58 -0
- package/dist/shared/{32zqc1dw.js → bg3rym3g.js} +63 -32
- package/dist/shared/{0t22wwh1.js → bm22fvzr.js} +16 -14
- package/dist/shared/bz84tkzm.js +342 -0
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/cn957f8d.js +179 -0
- package/dist/shared/{pf0d8f77.js → cnkky55j.js} +25 -14
- package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
- package/dist/shared/{nkaxvt9q.js → dkxgzaqd.js} +224 -19
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
- package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/g6evj1j3.js +66 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{qv2ydck9.js → gs74dbj5.js} +651 -76
- package/dist/shared/gzaveazc.js +285 -0
- package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
- package/dist/shared/{dyj86cmj.js → hyh73qk6.js} +3 -3
- package/dist/shared/je4axnm8.js +22 -0
- package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
- package/dist/shared/{6qd27mx0.js → jvd0mqag.js} +5 -5
- package/dist/shared/jznfax0y.js +155 -0
- package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
- package/dist/shared/{ps7a6h14.js → kr0jzbw2.js} +12 -8
- package/dist/shared/{janx09m5.js → ktz42yez.js} +20 -8
- package/dist/shared/{gde73es6.js → m6p12kbr.js} +56 -55
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{nxdp2ze3.js → mtaszv5a.js} +144 -12
- package/dist/shared/n816peh1.js +45 -0
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/{cctw17hj.js → p6qc5gcp.js} +38 -34
- package/dist/shared/{6rk2gen5.js → pbp1ss85.js} +20 -17
- package/dist/shared/pt94kz7f.js +6 -0
- package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
- package/dist/shared/q5c6ngn3.js +13 -0
- package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
- package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
- package/dist/shared/rhs3xe4k.js +7 -0
- package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
- package/dist/shared/{sdc7r2ww.js → rs73fca9.js} +8 -8
- package/dist/shared/{tm5ab8we.js → sfz1ksn6.js} +7 -4
- package/dist/shared/{6mnp99hx.js → svncdeh5.js} +16 -12
- package/dist/shared/{hf22e0wt.js → tbrvgw6z.js} +62 -42
- package/dist/shared/te5as7z7.js +622 -0
- package/dist/shared/{ga3sfy93.js → tsvww22q.js} +535 -200
- package/dist/shared/{47x8x9ze.js → ttsqgp4p.js} +20 -13
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/vb6qfyve.js +152 -0
- package/dist/shared/{r2sp8hrc.js → vczs8gd4.js} +22 -13
- package/dist/shared/{1g0drakv.js → vqrjpcqn.js} +145 -3
- package/dist/shared/{2pqx26h8.js → w72kgg4q.js} +31 -22
- package/dist/shared/{96qcj21c.js → w79hsckn.js} +16 -51
- package/dist/shared/wa07eas9.js +730 -0
- package/dist/shared/{k8v5v5wj.js → x933k9a3.js} +75 -34
- package/dist/shared/{cr74e96e.js → xhfsfkgk.js} +62 -28
- package/dist/shared/xjk7hnn5.js +272 -0
- package/dist/shared/{5enne4ma.js → xnxsed62.js} +66 -113
- package/dist/shared/xqve9598.js +53 -0
- package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
- package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
- package/dist/shared/y6njgyda.js +249 -0
- package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
- package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
- package/dist/shared/z7s6fpxv.js +62 -0
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
- package/dist/shared/zm0ptry0.js +40 -0
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zp9fmend.js +145 -0
- package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
- package/dist/tooling/cli.js +41 -15
- package/dist/tooling/migrate/apply.d.ts +14 -0
- package/dist/tooling/migrate/check.d.ts +3 -4
- package/dist/tooling/migrate/classify.d.ts +4 -0
- package/dist/tooling/migrate/config.d.ts +3 -2
- package/dist/tooling/migrate/engine.d.ts +3 -2
- package/dist/tooling/migrate/files.d.ts +11 -1
- package/dist/tooling/migrate/index.js +14 -14
- package/dist/tooling/migrate/lint.d.ts +1 -1
- package/dist/tooling/migrate/lost.d.ts +28 -0
- package/dist/tooling/migrate/paths.d.ts +14 -0
- package/dist/tooling/migrate/plan.d.ts +6 -3
- package/dist/tooling/migrate/runner.d.ts +25 -0
- package/dist/tooling/migrate/sandbox.d.ts +57 -0
- package/dist/tooling/migrate/sql-lex.d.ts +20 -3
- package/dist/tooling/migrate/text.d.ts +42 -0
- package/dist/tooling/node-version.d.ts +21 -0
- package/dist/tooling/testing/facts.d.ts +33 -5
- package/dist/tooling/testing/index.d.ts +1 -1
- package/dist/tooling/testing/index.js +3 -3
- package/dist/tooling/testing/isolation.d.ts +11 -5
- package/package.json +8 -3
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/7zwwyh0v.js +0 -448
- package/dist/shared/aj2qxyhj.js +0 -90
- package/dist/shared/caw8b9d8.js +0 -204
- package/dist/shared/jwtxdj06.js +0 -76
- package/dist/shared/kfjp0gck.js +0 -212
- package/dist/shared/q58y17hy.js +0 -21
- package/dist/shared/qm7cdtvr.js +0 -912
- package/dist/shared/r8x5qhd7.js +0 -86
- package/dist/shared/zqrnhwsq.js +0 -31
package/dist/shared/7zwwyh0v.js
DELETED
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseCatalog2
|
|
3
|
-
} from "./8bwbwy8h.js";
|
|
4
|
-
import"./krxx77g0.js";
|
|
5
|
-
import"./n442h54c.js";
|
|
6
|
-
import {
|
|
7
|
-
applyTarget2,
|
|
8
|
-
backfillTiming2
|
|
9
|
-
} from "./cctw17hj.js";
|
|
10
|
-
import {
|
|
11
|
-
sealViews,
|
|
12
|
-
catalogQuery2,
|
|
13
|
-
managedRoleOptions2
|
|
14
|
-
} from "./sycnx8gt.js";
|
|
15
|
-
import {
|
|
16
|
-
loadMigrations,
|
|
17
|
-
catalogsEqual,
|
|
18
|
-
snapshotDifference
|
|
19
|
-
} from "./gde73es6.js";
|
|
20
|
-
import"./szm0cksa.js";
|
|
21
|
-
import {
|
|
22
|
-
introspectSchema
|
|
23
|
-
} from "./fancm5pt.js";
|
|
24
|
-
import {
|
|
25
|
-
lintMigrationDirectory,
|
|
26
|
-
hasError,
|
|
27
|
-
lintRefusal,
|
|
28
|
-
openProject
|
|
29
|
-
} from "./qv2ydck9.js";
|
|
30
|
-
import {
|
|
31
|
-
canonicalTypeName,
|
|
32
|
-
classOf,
|
|
33
|
-
strictestClass,
|
|
34
|
-
planMigration,
|
|
35
|
-
parsePlan,
|
|
36
|
-
assertDirectConnection,
|
|
37
|
-
assertStableBackend,
|
|
38
|
-
selectTarget
|
|
39
|
-
} from "./ga3sfy93.js";
|
|
40
|
-
import {
|
|
41
|
-
quoteIdent
|
|
42
|
-
} from "./8xsbagad.js";
|
|
43
|
-
import {
|
|
44
|
-
catalog,
|
|
45
|
-
isDomain
|
|
46
|
-
} from "./g7ez901n.js";
|
|
47
|
-
import {
|
|
48
|
-
identityKey2
|
|
49
|
-
} from "./t4tbsy9h.js";
|
|
50
|
-
import {
|
|
51
|
-
OkmError2
|
|
52
|
-
} from "./52szzakm.js";
|
|
53
|
-
|
|
54
|
-
// src/tooling/migrate/check.ts
|
|
55
|
-
import { readFileSync } from "node:fs";
|
|
56
|
-
import { join } from "node:path";
|
|
57
|
-
import postgres from "postgres";
|
|
58
|
-
var CHECK_SCHEMA_PREFIX = "okm_check_";
|
|
59
|
-
var HISTORY_CODE = "OKM1547";
|
|
60
|
-
var PREVIOUS_CODE = "OKM1548";
|
|
61
|
-
var STALE_CODE = "OKM1549";
|
|
62
|
-
var HISTORY_FIX = "Regenerate the migration so the stored catalog matches the schema the SQL applies.";
|
|
63
|
-
var FORK_FIX = "Generate the later migration from the previous migration's catalog, not from an older parent.";
|
|
64
|
-
var PREVIOUS_FIX = "Keep every table, column, constraint, and type the previous catalog relies on, or classify the migration as contract.";
|
|
65
|
-
var STALE_FIX = "Run okm generate.";
|
|
66
|
-
async function checkMigrations(cwd, flags, options) {
|
|
67
|
-
const opened = await openProject(cwd);
|
|
68
|
-
const target = selectTarget(opened.config, flags.target);
|
|
69
|
-
const allowPooler = flags.allowPooler || opened.config.allowPooler === true;
|
|
70
|
-
assertDirectConnection(target.url, allowPooler);
|
|
71
|
-
if (target.protected) {
|
|
72
|
-
throw new OkmError2("OKM1850", `okm migrate check writes a scratch schema and refuses protected target ${target.name}. Point it at a throwaway Postgres.`, {
|
|
73
|
-
kind: "forbidden",
|
|
74
|
-
fix: {
|
|
75
|
-
summary: "Point okm migrate check at a throwaway Postgres. --allow-protected does not apply."
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
const directory = join(cwd, opened.config.migrations ?? "migrations");
|
|
80
|
-
const history = readHistory(directory);
|
|
81
|
-
if (options?.provision === true) {
|
|
82
|
-
const equivalence = await proveSnapshot(opened.config, target.url, target.name, flags, history);
|
|
83
|
-
if (equivalence !== undefined)
|
|
84
|
-
throwFailure([equivalence]);
|
|
85
|
-
}
|
|
86
|
-
const previous = previousFailures(history);
|
|
87
|
-
const stale = staleFailure(history, opened.built.catalog);
|
|
88
|
-
const lint = lintFailure(directory, history, opened.config.lintFrom);
|
|
89
|
-
const replayed = await replayHistory(opened.config, target.url, target.name, flags, history);
|
|
90
|
-
const failures = [...replayed, ...previous, ...stale, ...lint];
|
|
91
|
-
if (failures.length > 0)
|
|
92
|
-
throwFailure(failures);
|
|
93
|
-
return `ok ${String(history.length)} migrations
|
|
94
|
-
`;
|
|
95
|
-
}
|
|
96
|
-
function previousCatalogGaps(before, after) {
|
|
97
|
-
const afterBy = new Map(after.objects.map((object) => [identityKey2(object.identity), object]));
|
|
98
|
-
const gaps = [];
|
|
99
|
-
for (const object of before.objects) {
|
|
100
|
-
if (!checkedKind(object.kind))
|
|
101
|
-
continue;
|
|
102
|
-
const next = afterBy.get(identityKey2(object.identity));
|
|
103
|
-
if (next === undefined || next.kind !== object.kind) {
|
|
104
|
-
gaps.push(`${objectLabel(object)} is missing`);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (object.kind === "column" && next.kind === "column") {
|
|
108
|
-
gaps.push(...columnGaps(object, next));
|
|
109
|
-
}
|
|
110
|
-
if (object.kind === "type" && next.kind === "type" && !sameType(object.definition, next.definition)) {
|
|
111
|
-
gaps.push(`${objectLabel(object)} changed`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return gaps;
|
|
115
|
-
}
|
|
116
|
-
function recomputedMigrationClass(plan, before, after) {
|
|
117
|
-
if (plan.steps.length === 0)
|
|
118
|
-
return "expand";
|
|
119
|
-
if (plan.steps.some((step) => step.kind === undefined)) {
|
|
120
|
-
return planMigration({ before, after, name: plan.name }).class;
|
|
121
|
-
}
|
|
122
|
-
return strictestClass(plan.steps.map((step) => classOf(step.kind ?? "raw-sql")));
|
|
123
|
-
}
|
|
124
|
-
function migrationAllowsPreviousGaps(plan, before, after) {
|
|
125
|
-
return recomputedMigrationClass(plan, before, after) === "contract" && plan.class !== "expand";
|
|
126
|
-
}
|
|
127
|
-
function previousFailures(history) {
|
|
128
|
-
const failures = [];
|
|
129
|
-
let before = catalog([]);
|
|
130
|
-
for (const migration of history) {
|
|
131
|
-
const gaps = previousCatalogGaps(before, migration.catalog);
|
|
132
|
-
if (gaps.length > 0 && !migrationAllowsPreviousGaps(migration.plan, before, migration.catalog)) {
|
|
133
|
-
const stated = migration.plan.class === "expand" ? "expand" : recomputedMigrationClass(migration.plan, before, migration.catalog);
|
|
134
|
-
failures.push({
|
|
135
|
-
code: PREVIOUS_CODE,
|
|
136
|
-
message: `${migration.id}: previous catalog is not satisfied (${gaps.join("; ")}). The migration is classified ${stated}.`,
|
|
137
|
-
fix: PREVIOUS_FIX
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
before = migration.catalog;
|
|
141
|
-
}
|
|
142
|
-
return failures;
|
|
143
|
-
}
|
|
144
|
-
function staleFailure(history, head) {
|
|
145
|
-
const last = history.at(-1)?.catalog ?? catalog([]);
|
|
146
|
-
if (catalogsEqual(last, head))
|
|
147
|
-
return [];
|
|
148
|
-
return [
|
|
149
|
-
{
|
|
150
|
-
code: STALE_CODE,
|
|
151
|
-
message: "The last migration's catalog does not match the schema.",
|
|
152
|
-
fix: STALE_FIX
|
|
153
|
-
}
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
|
-
function lintFailure(directory, history, lintFrom) {
|
|
157
|
-
const findings = lintMigrationDirectory(directory, lintIds(history, lintFrom));
|
|
158
|
-
if (!hasError(findings))
|
|
159
|
-
return [];
|
|
160
|
-
const refusal = lintRefusal(findings);
|
|
161
|
-
return [{ code: refusal.code, message: refusal.message, fix: refusal.fix.summary }];
|
|
162
|
-
}
|
|
163
|
-
function lintIds(history, lintFrom) {
|
|
164
|
-
if (lintFrom === undefined)
|
|
165
|
-
return;
|
|
166
|
-
const ids = history.map((migration) => migration.id);
|
|
167
|
-
const start = ids.indexOf(lintFrom);
|
|
168
|
-
if (start < 0) {
|
|
169
|
-
throw new OkmError2("invalid", `lintFrom ${lintFrom} is not a migration id.`, {
|
|
170
|
-
fix: {
|
|
171
|
-
summary: "Set lintFrom to a migration id. Files before that id are the adoption baseline and are not linted."
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return new Set(ids.slice(start));
|
|
176
|
-
}
|
|
177
|
-
async function proveSnapshot(config, url, target, flags, history) {
|
|
178
|
-
const head = history.at(-1);
|
|
179
|
-
if (head === undefined)
|
|
180
|
-
return;
|
|
181
|
-
const sql = postgres(url, {
|
|
182
|
-
max: 1,
|
|
183
|
-
connect_timeout: 5,
|
|
184
|
-
idle_timeout: 1,
|
|
185
|
-
onnotice: () => {}
|
|
186
|
-
});
|
|
187
|
-
const allowPooler = flags.allowPooler || config.allowPooler === true;
|
|
188
|
-
const provided = `${CHECK_SCHEMA_PREFIX}p${crypto.randomUUID().replaceAll("-", "")}`;
|
|
189
|
-
const replayed = `${CHECK_SCHEMA_PREFIX}r${crypto.randomUUID().replaceAll("-", "")}`;
|
|
190
|
-
const timing = {
|
|
191
|
-
...flags.lockTimeoutMs !== undefined ? { lockTimeoutMs: flags.lockTimeoutMs } : config.timeouts?.lock !== undefined ? { lockTimeoutMs: config.timeouts.lock } : {},
|
|
192
|
-
...flags.statementTimeoutMs !== undefined ? { statementTimeoutMs: flags.statementTimeoutMs } : config.timeouts?.statement !== undefined ? { statementTimeoutMs: config.timeouts.statement } : {},
|
|
193
|
-
...backfillTiming2(config.backfill)
|
|
194
|
-
};
|
|
195
|
-
try {
|
|
196
|
-
await assertStableBackend(async () => {
|
|
197
|
-
const rows = await sql`select pg_backend_pid()::text as pid`;
|
|
198
|
-
return rows[0]?.pid ?? "";
|
|
199
|
-
}, allowPooler);
|
|
200
|
-
await sql.unsafe(`create schema ${quoteIdent(provided)}`);
|
|
201
|
-
await sql.unsafe(`create schema ${quoteIdent(replayed)}`);
|
|
202
|
-
const role = config.roles === undefined ? {} : { migrationRole: config.roles.migration, schema: provided };
|
|
203
|
-
await applyTarget2({
|
|
204
|
-
url,
|
|
205
|
-
target,
|
|
206
|
-
protected: false,
|
|
207
|
-
allowProtected: false,
|
|
208
|
-
allowPooler: flags.allowPooler || config.allowPooler === true,
|
|
209
|
-
searchPath: provided,
|
|
210
|
-
...timing,
|
|
211
|
-
migrations: history.map((migration) => ({
|
|
212
|
-
id: migration.id,
|
|
213
|
-
catalogHash: migration.catalogHash,
|
|
214
|
-
steps: migration.steps
|
|
215
|
-
})),
|
|
216
|
-
snapshot: {
|
|
217
|
-
catalog: head.catalog,
|
|
218
|
-
migrationId: head.id,
|
|
219
|
-
catalogHash: head.catalogHash,
|
|
220
|
-
reference: [],
|
|
221
|
-
only: true
|
|
222
|
-
},
|
|
223
|
-
...role
|
|
224
|
-
});
|
|
225
|
-
await applyTarget2({
|
|
226
|
-
url,
|
|
227
|
-
target,
|
|
228
|
-
protected: false,
|
|
229
|
-
allowProtected: false,
|
|
230
|
-
allowPooler: flags.allowPooler || config.allowPooler === true,
|
|
231
|
-
searchPath: replayed,
|
|
232
|
-
...timing,
|
|
233
|
-
migrations: history.map((migration) => ({
|
|
234
|
-
id: migration.id,
|
|
235
|
-
catalogHash: migration.catalogHash,
|
|
236
|
-
steps: retargetSteps(migration.steps, replayed)
|
|
237
|
-
})),
|
|
238
|
-
...config.roles !== undefined ? { migrationRole: config.roles.migration, schema: replayed } : {}
|
|
239
|
-
});
|
|
240
|
-
const liveProvided = await introspectScratch(sql, provided, config);
|
|
241
|
-
const liveReplayed = await introspectScratch(sql, replayed, config);
|
|
242
|
-
const difference = snapshotDifference(liveProvided, liveReplayed);
|
|
243
|
-
if (difference === undefined)
|
|
244
|
-
return;
|
|
245
|
-
return {
|
|
246
|
-
code: "OKM1521",
|
|
247
|
-
message: `Provisioning from the snapshot does not match the replayed history.
|
|
248
|
-
${difference}`,
|
|
249
|
-
fix: "Regenerate the snapshot from the history. okm migrate check --provision is the command that reports this."
|
|
250
|
-
};
|
|
251
|
-
} finally {
|
|
252
|
-
await sql.unsafe(`drop schema if exists ${quoteIdent(provided)} cascade`).catch(() => {
|
|
253
|
-
return;
|
|
254
|
-
});
|
|
255
|
-
await sql.unsafe(`drop schema if exists ${quoteIdent(replayed)} cascade`).catch(() => {
|
|
256
|
-
return;
|
|
257
|
-
});
|
|
258
|
-
await sql.end({ timeout: 5 });
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function replayHistory(config, url, target, flags, history) {
|
|
262
|
-
if (history.length === 0)
|
|
263
|
-
return [];
|
|
264
|
-
const sql = postgres(url, {
|
|
265
|
-
max: 1,
|
|
266
|
-
connect_timeout: 5,
|
|
267
|
-
idle_timeout: 1,
|
|
268
|
-
onnotice: () => {}
|
|
269
|
-
});
|
|
270
|
-
const allowPooler = flags.allowPooler || config.allowPooler === true;
|
|
271
|
-
const scratch = `${CHECK_SCHEMA_PREFIX}${crypto.randomUUID().replaceAll("-", "")}`;
|
|
272
|
-
const failures = [];
|
|
273
|
-
try {
|
|
274
|
-
await assertStableBackend(async () => {
|
|
275
|
-
const rows = await sql`select pg_backend_pid()::text as pid`;
|
|
276
|
-
return rows[0]?.pid ?? "";
|
|
277
|
-
}, allowPooler);
|
|
278
|
-
await sql.unsafe(`create schema ${quoteIdent(scratch)}`);
|
|
279
|
-
const runner = catalogQuery2(sql);
|
|
280
|
-
for (let index = 0;index < history.length; index += 1) {
|
|
281
|
-
const migration = history[index];
|
|
282
|
-
if (migration === undefined)
|
|
283
|
-
continue;
|
|
284
|
-
await applyTarget2({
|
|
285
|
-
url,
|
|
286
|
-
target,
|
|
287
|
-
protected: false,
|
|
288
|
-
allowProtected: false,
|
|
289
|
-
allowPooler: flags.allowPooler || config.allowPooler === true,
|
|
290
|
-
searchPath: scratch,
|
|
291
|
-
...flags.lockTimeoutMs !== undefined ? { lockTimeoutMs: flags.lockTimeoutMs } : config.timeouts?.lock !== undefined ? { lockTimeoutMs: config.timeouts.lock } : {},
|
|
292
|
-
...flags.statementTimeoutMs !== undefined ? { statementTimeoutMs: flags.statementTimeoutMs } : config.timeouts?.statement !== undefined ? { statementTimeoutMs: config.timeouts.statement } : {},
|
|
293
|
-
...backfillTiming2(config.backfill),
|
|
294
|
-
migrations: [
|
|
295
|
-
{
|
|
296
|
-
id: migration.id,
|
|
297
|
-
catalogHash: migration.catalogHash,
|
|
298
|
-
steps: retargetSteps(migration.steps, scratch)
|
|
299
|
-
}
|
|
300
|
-
],
|
|
301
|
-
...config.roles !== undefined ? { migrationRole: config.roles.migration, schema: scratch } : {}
|
|
302
|
-
});
|
|
303
|
-
const live = await introspectScratch(sql, scratch, config);
|
|
304
|
-
const sealed = await sealViews(runner, migration.catalog);
|
|
305
|
-
const back = planMigration({ before: live, after: sealed, name: migration.id });
|
|
306
|
-
if (back.steps.length === 0)
|
|
307
|
-
continue;
|
|
308
|
-
failures.push(historyFailure(history, index, back));
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
} finally {
|
|
312
|
-
await sql.unsafe(`drop schema if exists ${quoteIdent(scratch)} cascade`).catch(() => {
|
|
313
|
-
return;
|
|
314
|
-
});
|
|
315
|
-
await sql.end({ timeout: 5 });
|
|
316
|
-
}
|
|
317
|
-
return failures;
|
|
318
|
-
}
|
|
319
|
-
async function introspectScratch(sql, schema, config) {
|
|
320
|
-
const previous = await sql`select current_setting('search_path') as path`;
|
|
321
|
-
const saved = previous[0]?.path ?? "public";
|
|
322
|
-
try {
|
|
323
|
-
await sql.unsafe(`set search_path to ${quoteIdent(schema)}`);
|
|
324
|
-
return await introspectSchema(catalogQuery2(sql), schema, "public", managedRoleOptions2(config.roles));
|
|
325
|
-
} finally {
|
|
326
|
-
await sql`select set_config('search_path', ${saved}, false)`.catch(() => {
|
|
327
|
-
return;
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function historyFailure(history, index, back) {
|
|
332
|
-
const migration = history[index];
|
|
333
|
-
const id = migration?.id ?? "migration";
|
|
334
|
-
const fork = migration === undefined ? undefined : forkMessage(history, index);
|
|
335
|
-
if (fork !== undefined)
|
|
336
|
-
return { code: HISTORY_CODE, message: fork, fix: FORK_FIX };
|
|
337
|
-
const steps = back.steps.map((step) => step.sql).join(`
|
|
338
|
-
`);
|
|
339
|
-
return {
|
|
340
|
-
code: HISTORY_CODE,
|
|
341
|
-
message: `${id}: history differs from the stored catalog
|
|
342
|
-
${steps}`,
|
|
343
|
-
fix: HISTORY_FIX
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
function forkMessage(history, index) {
|
|
347
|
-
const current = history[index];
|
|
348
|
-
const previous = history[index - 1];
|
|
349
|
-
if (current === undefined || previous === undefined)
|
|
350
|
-
return;
|
|
351
|
-
if (samePlan(previous.catalog, current.catalog, current.plan))
|
|
352
|
-
return;
|
|
353
|
-
for (let parentIndex = 0;parentIndex < index; parentIndex += 1) {
|
|
354
|
-
const parent = parentIndex === 0 ? catalog([]) : history[parentIndex - 1]?.catalog;
|
|
355
|
-
if (parent === undefined)
|
|
356
|
-
continue;
|
|
357
|
-
if (!samePlan(parent, current.catalog, current.plan))
|
|
358
|
-
continue;
|
|
359
|
-
return `migration ${current.id} was generated from a different parent than ${previous.id}`;
|
|
360
|
-
}
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
function samePlan(before, after, file) {
|
|
364
|
-
try {
|
|
365
|
-
return sameSql(planMigration({ before, after, name: "parent" }), file);
|
|
366
|
-
} catch (error) {
|
|
367
|
-
if (error instanceof OkmError2 && error.code === "OKM1530")
|
|
368
|
-
return false;
|
|
369
|
-
throw error;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
function sameSql(planned, file) {
|
|
373
|
-
if (planned.steps.length !== file.steps.length)
|
|
374
|
-
return false;
|
|
375
|
-
return planned.steps.every((step, index) => step.sql === file.steps[index]?.sql);
|
|
376
|
-
}
|
|
377
|
-
function retargetSteps(steps, schema) {
|
|
378
|
-
const from = `${quoteIdent("public")}.`;
|
|
379
|
-
const to = `${quoteIdent(schema)}.`;
|
|
380
|
-
const fromDefaults = `in schema ${quoteIdent("public")} `;
|
|
381
|
-
const toDefaults = `in schema ${quoteIdent(schema)} `;
|
|
382
|
-
return steps.map((step) => ({
|
|
383
|
-
...step,
|
|
384
|
-
sql: step.sql.replaceAll(from, to).replaceAll(fromDefaults, toDefaults),
|
|
385
|
-
...step.backfill === undefined ? {} : { backfill: { ...step.backfill, table: step.backfill.table.replaceAll(from, to) } }
|
|
386
|
-
}));
|
|
387
|
-
}
|
|
388
|
-
function readHistory(directory) {
|
|
389
|
-
return loadMigrations(directory).map((migration) => ({
|
|
390
|
-
id: migration.id,
|
|
391
|
-
catalogHash: migration.catalogHash,
|
|
392
|
-
steps: migration.steps,
|
|
393
|
-
plan: parsePlan(readFileSync(join(directory, `${migration.id}.sql`), "utf8")),
|
|
394
|
-
catalog: parseCatalog2(readFileSync(join(directory, `${migration.id}.catalog.json`), "utf8"))
|
|
395
|
-
}));
|
|
396
|
-
}
|
|
397
|
-
function throwFailure(failures) {
|
|
398
|
-
const first = failures[0];
|
|
399
|
-
if (first === undefined)
|
|
400
|
-
throw new Error("okm migrate check has no failure to report.");
|
|
401
|
-
const message = failures.length === 1 ? first.message : failures.map((failure) => `${failure.code} ${failure.message}`).join(`
|
|
402
|
-
`);
|
|
403
|
-
throw new OkmError2(first.code, message, { fix: { summary: first.fix } });
|
|
404
|
-
}
|
|
405
|
-
function checkedKind(kind) {
|
|
406
|
-
return kind === "table" || kind === "column" || kind === "constraint" || kind === "type";
|
|
407
|
-
}
|
|
408
|
-
function columnGaps(before, after) {
|
|
409
|
-
const gaps = [];
|
|
410
|
-
const place = objectLabel(before);
|
|
411
|
-
if (canonicalTypeName(before.definition.dataType) !== canonicalTypeName(after.definition.dataType)) {
|
|
412
|
-
gaps.push(`${place} changed type from ${before.definition.dataType} to ${after.definition.dataType}`);
|
|
413
|
-
}
|
|
414
|
-
if (before.definition.nullable && !after.definition.nullable && !columnHasDefault(after)) {
|
|
415
|
-
gaps.push(`${place} nullability tightened without a default`);
|
|
416
|
-
}
|
|
417
|
-
return gaps;
|
|
418
|
-
}
|
|
419
|
-
function columnHasDefault(column) {
|
|
420
|
-
return column.definition.defaultExpression !== undefined || column.definition.identity !== undefined || column.definition.generated !== undefined;
|
|
421
|
-
}
|
|
422
|
-
function sameType(before, after) {
|
|
423
|
-
const beforeDomain = isDomain(before);
|
|
424
|
-
const afterDomain = isDomain(after);
|
|
425
|
-
if (beforeDomain !== afterDomain)
|
|
426
|
-
return false;
|
|
427
|
-
if (beforeDomain && afterDomain) {
|
|
428
|
-
return canonicalTypeName(before.base) === canonicalTypeName(after.base) && before.check === after.check;
|
|
429
|
-
}
|
|
430
|
-
if (!beforeDomain && !afterDomain) {
|
|
431
|
-
if (before.labels.length !== after.labels.length)
|
|
432
|
-
return false;
|
|
433
|
-
return before.labels.every((label, index) => label === after.labels[index]);
|
|
434
|
-
}
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
function objectLabel(object) {
|
|
438
|
-
if (object.kind === "column" || object.kind === "constraint") {
|
|
439
|
-
return `${object.kind} ${object.identity.parent.name}.${object.identity.name}`;
|
|
440
|
-
}
|
|
441
|
-
if (object.kind === "table" || object.kind === "type") {
|
|
442
|
-
return `${object.kind} ${object.identity.name}`;
|
|
443
|
-
}
|
|
444
|
-
return object.kind;
|
|
445
|
-
}
|
|
446
|
-
export {
|
|
447
|
-
checkMigrations
|
|
448
|
-
};
|
package/dist/shared/aj2qxyhj.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runWrite
|
|
3
|
-
} from "./n4jqhpqz.js";
|
|
4
|
-
import {
|
|
5
|
-
withHttp,
|
|
6
|
-
settleCall
|
|
7
|
-
} from "./hf22e0wt.js";
|
|
8
|
-
import {
|
|
9
|
-
rejectKeys,
|
|
10
|
-
isRecord,
|
|
11
|
-
fail
|
|
12
|
-
} from "./gbtcc2d7.js";
|
|
13
|
-
import {
|
|
14
|
-
OkmError2
|
|
15
|
-
} from "./52szzakm.js";
|
|
16
|
-
|
|
17
|
-
// src/runtime/batch.ts
|
|
18
|
-
async function batch(session, ops, options, replica) {
|
|
19
|
-
try {
|
|
20
|
-
if (replica !== undefined) {
|
|
21
|
-
throw new OkmError2("OKM1840", "batch() needs the primary. .replica() is not allowed on a batch.", withHttp(session.http, {
|
|
22
|
-
fix: { summary: "Remove .replica(). A batch always runs on the primary." }
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
if (!Array.isArray(ops))
|
|
26
|
-
fail("OKM1121", "batch expects a list of write operations.");
|
|
27
|
-
const record = options ?? {};
|
|
28
|
-
if (!isRecord(record))
|
|
29
|
-
fail("OKM1121", "batch options must be an object.");
|
|
30
|
-
rejectKeys(record, ["signal", "timeout"], "batch");
|
|
31
|
-
const prepared = [];
|
|
32
|
-
for (const op of ops) {
|
|
33
|
-
const plan = typeof op === "object" && op !== null ? op["~plan"] : undefined;
|
|
34
|
-
if (plan === undefined) {
|
|
35
|
-
fail("OKM1121", "batch takes write operations: insert, update, delete, and archive. Pass them without awaiting.");
|
|
36
|
-
}
|
|
37
|
-
const item = await plan();
|
|
38
|
-
if (item.checked !== undefined) {
|
|
39
|
-
fail("OKM1121", item.checked === "restore" ? "batch does not take restore: it is refused while its parent is archived, and a batch cannot report that after it commits. Use tx()." : "batch does not take a write with expect: the count is checked after the statement ran, and a batch cannot report that after it commits. Use tx().");
|
|
40
|
-
}
|
|
41
|
-
prepared.push(item);
|
|
42
|
-
}
|
|
43
|
-
return await run(session, prepared, record);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
return settleCall(session, error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function run(session, prepared, options) {
|
|
49
|
-
await session.connected;
|
|
50
|
-
const statements = [];
|
|
51
|
-
const starts = [];
|
|
52
|
-
for (const item of prepared) {
|
|
53
|
-
starts.push(statements.length);
|
|
54
|
-
statements.push(...item.statements);
|
|
55
|
-
}
|
|
56
|
-
if (statements.length === 0)
|
|
57
|
-
return prepared.map((item) => item.finish([]));
|
|
58
|
-
let results;
|
|
59
|
-
try {
|
|
60
|
-
results = await runWrite(session, statements, call(options), true);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
throw at(error, starts);
|
|
63
|
-
}
|
|
64
|
-
return prepared.map((item, index) => {
|
|
65
|
-
const from = starts[index] ?? 0;
|
|
66
|
-
return item.finish(results.slice(from, from + item.statements.length));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function call(options) {
|
|
70
|
-
const { signal, timeout } = options;
|
|
71
|
-
if (signal === undefined && timeout === undefined)
|
|
72
|
-
return;
|
|
73
|
-
return {
|
|
74
|
-
...signal !== undefined ? { signal } : {},
|
|
75
|
-
...typeof timeout === "number" ? { timeout } : {}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function at(error, starts) {
|
|
79
|
-
const failed = error?.batchIndex;
|
|
80
|
-
const move = error?.at;
|
|
81
|
-
if (typeof failed !== "number" || typeof move !== "function")
|
|
82
|
-
return error;
|
|
83
|
-
let index = 0;
|
|
84
|
-
while (index + 1 < starts.length && (starts[index + 1] ?? Infinity) <= failed)
|
|
85
|
-
index += 1;
|
|
86
|
-
return index === failed ? error : move.call(error, index);
|
|
87
|
-
}
|
|
88
|
-
export {
|
|
89
|
-
batch
|
|
90
|
-
};
|