@intentius/sql-yodeler 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 +28 -26
- package/dist/bin.js +15 -0
- package/dist/bin.js.map +1 -1
- package/dist/chant/apply.d.ts +9 -1
- package/dist/chant/apply.js +13 -1
- package/dist/chant/apply.js.map +1 -1
- package/dist/chant/build.js +7 -0
- package/dist/chant/build.js.map +1 -1
- package/dist/chant/drift.d.ts +69 -1
- package/dist/chant/drift.js +152 -5
- package/dist/chant/drift.js.map +1 -1
- package/dist/chant/runnable.d.ts +19 -0
- package/dist/chant/runnable.js +47 -0
- package/dist/chant/runnable.js.map +1 -0
- package/dist/ci/render.d.ts +289 -0
- package/dist/ci/render.js +688 -0
- package/dist/ci/render.js.map +1 -0
- package/dist/ci/replay.d.ts +17 -0
- package/dist/ci/replay.js +69 -0
- package/dist/ci/replay.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +40 -0
- package/dist/cli.js.map +1 -1
- package/dist/command.d.ts +6 -0
- package/dist/command.js.map +1 -1
- package/dist/commands/apply.d.ts +113 -0
- package/dist/commands/apply.js +376 -49
- package/dist/commands/apply.js.map +1 -1
- package/dist/commands/approve.d.ts +5 -0
- package/dist/commands/approve.js +155 -0
- package/dist/commands/approve.js.map +1 -0
- package/dist/commands/checkpoint.d.ts +3 -0
- package/dist/commands/checkpoint.js +78 -0
- package/dist/commands/checkpoint.js.map +1 -0
- package/dist/commands/ci.d.ts +3 -0
- package/dist/commands/ci.js +118 -0
- package/dist/commands/ci.js.map +1 -0
- package/dist/commands/docs.d.ts +11 -0
- package/dist/commands/docs.js +108 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/commands/drift.d.ts +23 -0
- package/dist/commands/drift.js +263 -18
- package/dist/commands/drift.js.map +1 -1
- package/dist/commands/index.js +16 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +15 -11
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.js +25 -8
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.js +50 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.js +134 -10
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/override.d.ts +3 -0
- package/dist/commands/override.js +150 -0
- package/dist/commands/override.js.map +1 -0
- package/dist/commands/plan.js +43 -27
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/repair.d.ts +11 -0
- package/dist/commands/repair.js +15 -7
- package/dist/commands/repair.js.map +1 -1
- package/dist/commands/report.d.ts +13 -0
- package/dist/commands/report.js +121 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/revert.d.ts +20 -0
- package/dist/commands/revert.js +246 -0
- package/dist/commands/revert.js.map +1 -0
- package/dist/commands/status.js +44 -17
- package/dist/commands/status.js.map +1 -1
- package/dist/config/base.d.ts +69 -0
- package/dist/config/base.js +121 -0
- package/dist/config/base.js.map +1 -0
- package/dist/config/define.d.ts +223 -3
- package/dist/config/define.js +3 -1
- package/dist/config/define.js.map +1 -1
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/load.d.ts +1 -1
- package/dist/config/load.js +150 -5
- package/dist/config/load.js.map +1 -1
- package/dist/config/settings.d.ts +18 -2
- package/dist/config/settings.js +40 -6
- package/dist/config/settings.js.map +1 -1
- package/dist/env-args.d.ts +6 -0
- package/dist/env-args.js +31 -1
- package/dist/env-args.js.map +1 -1
- package/dist/exit.d.ts +20 -0
- package/dist/exit.js +28 -0
- package/dist/exit.js.map +1 -0
- package/dist/history/client.d.ts +8 -0
- package/dist/history/client.js +24 -1
- package/dist/history/client.js.map +1 -1
- package/dist/history/lock.d.ts +5 -1
- package/dist/history/lock.js +8 -2
- package/dist/history/lock.js.map +1 -1
- package/dist/history/postgres/ddl.d.ts +18 -0
- package/dist/history/postgres/ddl.js +27 -2
- package/dist/history/postgres/ddl.js.map +1 -1
- package/dist/history/postgres/store.d.ts +2 -0
- package/dist/history/postgres/store.js +7 -1
- package/dist/history/postgres/store.js.map +1 -1
- package/dist/history/rows.d.ts +16 -3
- package/dist/history/rows.js +30 -1
- package/dist/history/rows.js.map +1 -1
- package/dist/history/store.d.ts +2 -0
- package/dist/history/store.js +2 -2
- package/dist/history/store.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/init/adopt.js +8 -3
- package/dist/init/adopt.js.map +1 -1
- package/dist/init/live.d.ts +11 -0
- package/dist/init/live.js +25 -2
- package/dist/init/live.js.map +1 -1
- package/dist/lint/check.d.ts +8 -1
- package/dist/lint/check.js +38 -4
- package/dist/lint/check.js.map +1 -1
- package/dist/lint/report.js +1 -1
- package/dist/lint/report.js.map +1 -1
- package/dist/lint/routines.d.ts +26 -0
- package/dist/lint/routines.js +65 -0
- package/dist/lint/routines.js.map +1 -0
- package/dist/lint/rules.d.ts +16 -4
- package/dist/lint/rules.js +9 -4
- package/dist/lint/rules.js.map +1 -1
- package/dist/mcp/server.d.ts +40 -0
- package/dist/mcp/server.js +106 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +72 -0
- package/dist/mcp/tools.js +178 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/migrations/checkpoint.d.ts +45 -0
- package/dist/migrations/checkpoint.js +110 -0
- package/dist/migrations/checkpoint.js.map +1 -0
- package/dist/migrations/checks.d.ts +28 -0
- package/dist/migrations/checks.js +97 -0
- package/dist/migrations/checks.js.map +1 -0
- package/dist/migrations/create.d.ts +3 -1
- package/dist/migrations/create.js +3 -0
- package/dist/migrations/create.js.map +1 -1
- package/dist/migrations/directory.js +4 -0
- package/dist/migrations/directory.js.map +1 -1
- package/dist/migrations/document.d.ts +33 -0
- package/dist/migrations/document.js +2 -0
- package/dist/migrations/document.js.map +1 -1
- package/dist/migrations/index.d.ts +3 -0
- package/dist/migrations/index.js +3 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/routines.d.ts +31 -0
- package/dist/migrations/routines.js +55 -0
- package/dist/migrations/routines.js.map +1 -0
- package/dist/notify/index.d.ts +124 -0
- package/dist/notify/index.js +210 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/verify.d.ts +53 -0
- package/dist/notify/verify.js +71 -0
- package/dist/notify/verify.js.map +1 -0
- package/dist/pr/forge.d.ts +4 -0
- package/dist/pr/forge.js +21 -7
- package/dist/pr/forge.js.map +1 -1
- package/dist/pr/issue.d.ts +68 -0
- package/dist/pr/issue.js +107 -0
- package/dist/pr/issue.js.map +1 -0
- package/dist/pr/model.d.ts +12 -1
- package/dist/pr/model.js +44 -6
- package/dist/pr/model.js.map +1 -1
- package/dist/pr/render.d.ts +3 -1
- package/dist/pr/render.js +63 -4
- package/dist/pr/render.js.map +1 -1
- package/dist/project.d.ts +19 -2
- package/dist/project.js +33 -1
- package/dist/project.js.map +1 -1
- package/dist/replay/index.d.ts +3 -0
- package/dist/replay/index.js +3 -0
- package/dist/replay/index.js.map +1 -1
- package/dist/replay/replay.d.ts +9 -1
- package/dist/replay/replay.js +63 -32
- package/dist/replay/replay.js.map +1 -1
- package/dist/replay/report.js +1 -1
- package/dist/replay/report.js.map +1 -1
- package/dist/replay/shared.d.ts +28 -0
- package/dist/replay/shared.js +77 -0
- package/dist/replay/shared.js.map +1 -0
- package/dist/report/audit.d.ts +138 -0
- package/dist/report/audit.js +202 -0
- package/dist/report/audit.js.map +1 -0
- package/dist/report/jsonl.d.ts +21 -0
- package/dist/report/jsonl.js +52 -0
- package/dist/report/jsonl.js.map +1 -0
- package/dist/report/model.d.ts +68 -0
- package/dist/report/model.js +127 -0
- package/dist/report/model.js.map +1 -0
- package/dist/report/render.d.ts +18 -0
- package/dist/report/render.js +127 -0
- package/dist/report/render.js.map +1 -0
- package/dist/schema-docs/render.d.ts +49 -0
- package/dist/schema-docs/render.js +359 -0
- package/dist/schema-docs/render.js.map +1 -0
- package/dist/schemas.d.ts +37 -0
- package/dist/schemas.js +41 -0
- package/dist/schemas.js.map +1 -0
- package/dist/server.d.ts +40 -0
- package/dist/server.js +87 -0
- package/dist/server.js.map +1 -0
- package/dist/sources/ddl.d.ts +53 -0
- package/dist/sources/ddl.js +347 -0
- package/dist/sources/ddl.js.map +1 -0
- package/dist/sources/index.d.ts +69 -0
- package/dist/sources/index.js +170 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/steps/backfill.d.ts +21 -17
- package/dist/steps/backfill.js +20 -20
- package/dist/steps/backfill.js.map +1 -1
- package/dist/steps/index.d.ts +2 -2
- package/dist/steps/index.js +3 -3
- package/dist/steps/index.js.map +1 -1
- package/dist/steps/postgres-migration.d.ts +35 -25
- package/dist/steps/postgres-migration.js +42 -29
- package/dist/steps/postgres-migration.js.map +1 -1
- package/dist/steps/rebuild.d.ts +15 -15
- package/dist/steps/rebuild.js +17 -24
- package/dist/steps/rebuild.js.map +1 -1
- package/dist/tenants/index.d.ts +40 -0
- package/dist/tenants/index.js +122 -0
- package/dist/tenants/index.js.map +1 -0
- package/dist/tenants/target.d.ts +23 -0
- package/dist/tenants/target.js +29 -0
- package/dist/tenants/target.js.map +1 -0
- package/dist/versioned/checks.d.ts +29 -0
- package/dist/versioned/checks.js +54 -0
- package/dist/versioned/checks.js.map +1 -0
- package/dist/versioned/clickhouse.js +8 -0
- package/dist/versioned/clickhouse.js.map +1 -1
- package/dist/versioned/driver.d.ts +10 -0
- package/dist/versioned/engine.d.ts +61 -1
- package/dist/versioned/engine.js +109 -6
- package/dist/versioned/engine.js.map +1 -1
- package/dist/versioned/explain.js +7 -2
- package/dist/versioned/explain.js.map +1 -1
- package/dist/versioned/index.d.ts +10 -0
- package/dist/versioned/index.js +25 -1
- package/dist/versioned/index.js.map +1 -1
- package/dist/versioned/op.d.ts +16 -1
- package/dist/versioned/op.js +43 -6
- package/dist/versioned/op.js.map +1 -1
- package/dist/versioned/policy.d.ts +98 -0
- package/dist/versioned/policy.js +212 -0
- package/dist/versioned/policy.js.map +1 -0
- package/dist/versioned/postgres/driver.d.ts +3 -1
- package/dist/versioned/postgres/driver.js +30 -3
- package/dist/versioned/postgres/driver.js.map +1 -1
- package/dist/versioned/postgres/waits.d.ts +46 -0
- package/dist/versioned/postgres/waits.js +78 -0
- package/dist/versioned/postgres/waits.js.map +1 -0
- package/dist/versioned/report.d.ts +3 -0
- package/dist/versioned/report.js +13 -1
- package/dist/versioned/report.js.map +1 -1
- package/dist/versioned/revert.d.ts +128 -0
- package/dist/versioned/revert.js +251 -0
- package/dist/versioned/revert.js.map +1 -0
- package/dist/versioned/stand-down.d.ts +30 -0
- package/dist/versioned/stand-down.js +56 -0
- package/dist/versioned/stand-down.js.map +1 -0
- package/dist/versioned/state.d.ts +25 -0
- package/dist/versioned/state.js +36 -3
- package/dist/versioned/state.js.map +1 -1
- package/dist/waves/index.d.ts +179 -0
- package/dist/waves/index.js +268 -0
- package/dist/waves/index.js.map +1 -0
- package/dist/waves/promotion.d.ts +56 -0
- package/dist/waves/promotion.js +108 -0
- package/dist/waves/promotion.js.map +1 -0
- package/dist/waves/record.d.ts +24 -0
- package/dist/waves/record.js +20 -0
- package/dist/waves/record.js.map +1 -0
- package/package.json +22 -8
- package/schemas/apply.schema.json +428 -0
- package/schemas/checkpoint.schema.json +19 -0
- package/schemas/common.schema.json +213 -0
- package/schemas/drift.schema.json +61 -0
- package/schemas/event.schema.json +36 -0
- package/schemas/init.schema.json +31 -0
- package/schemas/lint-rules.schema.json +54 -0
- package/schemas/lint.schema.json +294 -0
- package/schemas/mcp.schema.json +70 -0
- package/schemas/new.schema.json +71 -0
- package/schemas/plan.schema.json +489 -0
- package/schemas/rebase.schema.json +54 -0
- package/schemas/repair.schema.json +20 -0
- package/schemas/report.schema.json +114 -0
- package/schemas/revert.schema.json +69 -0
- package/schemas/status.schema.json +371 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `yodel apply --stand-down` (`YODEL_STAND_DOWN=1`): an apply that a newer
|
|
3
|
+
* commit will make anyway steps aside instead of queueing for the lock.
|
|
4
|
+
*
|
|
5
|
+
* The branch is the one the run is for: `GITHUB_REF_NAME` (GitHub and
|
|
6
|
+
* Forgejo Actions), `CI_COMMIT_BRANCH` (GitLab CI), else the checked-out
|
|
7
|
+
* branch. Its tip is fetched from `origin`; when that tip is a different
|
|
8
|
+
* commit that contains this one, a newer commit is on the branch, and its
|
|
9
|
+
* own apply job applies the same environment, this run included. Anything
|
|
10
|
+
* that cannot be told (no branch, no origin, a fetch that fails, a tip that
|
|
11
|
+
* does not contain this commit, as after a force-push) is not a newer
|
|
12
|
+
* commit: the apply goes ahead.
|
|
13
|
+
*/
|
|
14
|
+
import { execFile } from "node:child_process";
|
|
15
|
+
import { promisify } from "node:util";
|
|
16
|
+
const exec = promisify(execFile);
|
|
17
|
+
export const STAND_DOWN_ENV = "YODEL_STAND_DOWN";
|
|
18
|
+
/** Whether the environment asks for stand-down: `YODEL_STAND_DOWN=1` (or `true`). */
|
|
19
|
+
export const standDownFromEnv = (env) => env[STAND_DOWN_ENV] === "1" || env[STAND_DOWN_ENV] === "true";
|
|
20
|
+
async function git(dir, args) {
|
|
21
|
+
try {
|
|
22
|
+
const { stdout } = await exec("git", args, { cwd: dir, timeout: 60_000 });
|
|
23
|
+
return stdout.trim();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The branch a run is for; see the module comment. */
|
|
30
|
+
export async function runBranch(dir, env) {
|
|
31
|
+
const named = env.GITHUB_REF_NAME || env.CI_COMMIT_BRANCH;
|
|
32
|
+
if (named)
|
|
33
|
+
return named;
|
|
34
|
+
return (await git(dir, ["symbolic-ref", "--quiet", "--short", "HEAD"])) || undefined;
|
|
35
|
+
}
|
|
36
|
+
/** The newer commit on the run's branch, or `undefined` when there is none or it cannot be told. */
|
|
37
|
+
export async function newerCommit(dir, env = process.env) {
|
|
38
|
+
const branch = await runBranch(dir, env);
|
|
39
|
+
if (!branch)
|
|
40
|
+
return undefined;
|
|
41
|
+
const head = await git(dir, ["rev-parse", "HEAD"]);
|
|
42
|
+
if (!head)
|
|
43
|
+
return undefined;
|
|
44
|
+
if ((await git(dir, ["fetch", "--quiet", "--no-tags", "origin", `refs/heads/${branch}`])) === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const tip = await git(dir, ["rev-parse", "FETCH_HEAD"]);
|
|
47
|
+
if (!tip || tip === head)
|
|
48
|
+
return undefined;
|
|
49
|
+
// A tip that contains this commit is newer; one that does not (a force-push, another line) is not.
|
|
50
|
+
if ((await git(dir, ["merge-base", "--is-ancestor", head, tip])) === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
return { branch, head, tip };
|
|
53
|
+
}
|
|
54
|
+
/** What a run that stands down says. */
|
|
55
|
+
export const standDownLine = (env, n) => `standing down: ${n.branch} on origin is at ${n.tip.slice(0, 12)}, newer than this run's ${n.head.slice(0, 12)}, and its own apply applies ${env}. Nothing was applied by this run.`;
|
|
56
|
+
//# sourceMappingURL=stand-down.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stand-down.js","sourceRoot":"","sources":["../../src/versioned/stand-down.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEjD,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAsB,EAAW,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC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K,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1H,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC3C,mGAAmG;IACnG,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACjG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAC/B,CAAC;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,CAAc,EAAU,EAAE,CACnE,kBAAkB,CAAC,CAAC,MAAM,oBAAoB,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,2BAA2B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,+BAA+B,GAAG,oCAAoC,CAAC"}
|
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
* migration that failed part way may be edited before it resumes (to fix
|
|
22
22
|
* the statement that failed), as long as every statement that already
|
|
23
23
|
* succeeded is unchanged: those are compared statement by statement.
|
|
24
|
+
*
|
|
25
|
+
* ## Checkpoints (#63)
|
|
26
|
+
*
|
|
27
|
+
* A checkpoint creates its parent's recorded schema from nothing. An
|
|
28
|
+
* environment whose history is empty starts at the newest checkpoint: the
|
|
29
|
+
* migrations before it are skipped, never run there. An environment whose
|
|
30
|
+
* history records a checkpoint started there, and skips the migrations
|
|
31
|
+
* before it the same way. Any other checkpoint is skipped: the environment
|
|
32
|
+
* ran (or started past) the migrations it stands for. A skipped migration
|
|
33
|
+
* is neither applied nor pending, so it is never out of order either.
|
|
24
34
|
*/
|
|
25
35
|
import type { MigrationStep } from "@intentius/chant-lexicon-sql/migration-statements";
|
|
26
36
|
import { type Migration } from "../migrations/index.js";
|
|
@@ -59,6 +69,11 @@ export interface PendingMigration {
|
|
|
59
69
|
/** Before a migration the history records applied. */
|
|
60
70
|
outOfOrder: boolean;
|
|
61
71
|
partWay: PartWay | undefined;
|
|
72
|
+
/** It was applied, then `yodel revert` (#55) undid it: who reverted it and when. Applied again, every statement runs again. */
|
|
73
|
+
reverted?: {
|
|
74
|
+
by: string;
|
|
75
|
+
at: string;
|
|
76
|
+
};
|
|
62
77
|
/** Its Op steps `apply` runs: a ClickHouse rebuild, a backfill (#12). */
|
|
63
78
|
opSteps: Array<{
|
|
64
79
|
index: number;
|
|
@@ -93,12 +108,22 @@ export type Mismatch = {
|
|
|
93
108
|
recorded: string;
|
|
94
109
|
message: string;
|
|
95
110
|
};
|
|
111
|
+
/** A migration this environment never runs, because of a checkpoint (#63). */
|
|
112
|
+
export interface SkippedMigration {
|
|
113
|
+
id: string;
|
|
114
|
+
/** `covered`: it comes before the checkpoint the environment starts from. `checkpoint`: a checkpoint the environment does not start from. */
|
|
115
|
+
reason: "covered" | "checkpoint";
|
|
116
|
+
/** `covered`: the checkpoint the environment starts from. */
|
|
117
|
+
checkpoint?: string;
|
|
118
|
+
}
|
|
96
119
|
export interface VersionedStatus {
|
|
97
120
|
/** In chain order; then any the directory no longer has, in the order they were applied. */
|
|
98
121
|
applied: AppliedMigration[];
|
|
99
122
|
/** In chain order. */
|
|
100
123
|
pending: PendingMigration[];
|
|
101
124
|
mismatches: Mismatch[];
|
|
125
|
+
/** In chain order: the migrations a checkpoint leaves out here. Absent when there are none. */
|
|
126
|
+
skipped?: SkippedMigration[];
|
|
102
127
|
}
|
|
103
128
|
export declare const outOfOrder: (s: VersionedStatus) => PendingMigration[];
|
|
104
129
|
export declare const partWay: (s: VersionedStatus) => PendingMigration[];
|
package/dist/versioned/state.js
CHANGED
|
@@ -21,9 +21,19 @@
|
|
|
21
21
|
* migration that failed part way may be edited before it resumes (to fix
|
|
22
22
|
* the statement that failed), as long as every statement that already
|
|
23
23
|
* succeeded is unchanged: those are compared statement by statement.
|
|
24
|
+
*
|
|
25
|
+
* ## Checkpoints (#63)
|
|
26
|
+
*
|
|
27
|
+
* A checkpoint creates its parent's recorded schema from nothing. An
|
|
28
|
+
* environment whose history is empty starts at the newest checkpoint: the
|
|
29
|
+
* migrations before it are skipped, never run there. An environment whose
|
|
30
|
+
* history records a checkpoint started there, and skips the migrations
|
|
31
|
+
* before it the same way. Any other checkpoint is skipped: the environment
|
|
32
|
+
* ran (or started past) the migrations it stands for. A skipped migration
|
|
33
|
+
* is neither applied nor pending, so it is never out of order either.
|
|
24
34
|
*/
|
|
25
|
-
import { computeChecksum } from "../migrations/index.js";
|
|
26
|
-
import { isApplied, statementDone } from "../history/index.js";
|
|
35
|
+
import { computeChecksum, isCheckpoint } from "../migrations/index.js";
|
|
36
|
+
import { isApplied, isReverted, statementDone } from "../history/index.js";
|
|
27
37
|
import { planStep, stepSha } from "../steps/index.js";
|
|
28
38
|
export const outOfOrder = (s) => s.pending.filter((p) => p.outOfOrder);
|
|
29
39
|
export const partWay = (s) => s.pending.filter((p) => p.partWay !== undefined);
|
|
@@ -125,13 +135,36 @@ export function compareHistory(ordered, state) {
|
|
|
125
135
|
message: `${r.id} is recorded applied, but the migrations directory no longer has it; restore it, or ${repair(r.id)}`,
|
|
126
136
|
});
|
|
127
137
|
}
|
|
138
|
+
// The checkpoint this environment starts from: the newest one its history records, or, for an empty history, the newest one in the chain.
|
|
139
|
+
let start = -1;
|
|
140
|
+
for (const [i, m] of ordered.entries())
|
|
141
|
+
if (isCheckpoint(m) && state.byId.has(m.id))
|
|
142
|
+
start = i;
|
|
143
|
+
if (start < 0 && state.migrations.length === 0)
|
|
144
|
+
for (const [i, m] of ordered.entries())
|
|
145
|
+
if (isCheckpoint(m))
|
|
146
|
+
start = i;
|
|
147
|
+
const startId = start < 0 ? undefined : ordered[start]?.id;
|
|
148
|
+
const skipped = [];
|
|
128
149
|
const pending = [];
|
|
129
150
|
for (const [i, m] of ordered.entries()) {
|
|
130
151
|
const rec = state.byId.get(m.id);
|
|
131
152
|
if (isApplied(rec))
|
|
132
153
|
continue;
|
|
154
|
+
if (!rec && i < start) {
|
|
155
|
+
skipped.push({ id: m.id, reason: "covered", ...(startId ? { checkpoint: startId } : {}) });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!rec && i !== start && isCheckpoint(m)) {
|
|
159
|
+
skipped.push({ id: m.id, reason: "checkpoint" });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
133
162
|
const actual = computeChecksum(m.files);
|
|
134
163
|
let pw;
|
|
164
|
+
if (rec && isReverted(rec)) {
|
|
165
|
+
pending.push({ id: m.id, index: i, checksum: actual, outOfOrder: i < lastApplied, partWay: undefined, reverted: { by: rec.appliedBy, at: rec.recordedAt }, ...classifySteps(m), migration: m });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
135
168
|
if (rec) {
|
|
136
169
|
const r = partWayOf(m, rec, actual);
|
|
137
170
|
pw = r.partWay;
|
|
@@ -148,6 +181,6 @@ export function compareHistory(ordered, state) {
|
|
|
148
181
|
migration: m,
|
|
149
182
|
});
|
|
150
183
|
}
|
|
151
|
-
return { applied, pending, mismatches };
|
|
184
|
+
return { applied, pending, mismatches, ...(skipped.length > 0 ? { skipped } : {}) };
|
|
152
185
|
}
|
|
153
186
|
//# sourceMappingURL=state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/versioned/state.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/versioned/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,eAAe,EAAE,YAAY,EAAkB,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,UAA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R,KAAK,EAAE,CAAC;YACR,QAAQ,EAAE,MAAM;YAChB,UAAU,EAAE,CAAC,GAAG,WAAW;YAC3B,OAAO,EAAE,EAAE;YACX,GAAG,aAAa,CAAC,CAAC,CAAC;YACnB,SAAS,EAAE,CAAC;SACb,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment waves (#42): the apply pipeline as chant's Op waves, one wave
|
|
3
|
+
* per environment, each behind a gate policy of its own.
|
|
4
|
+
*
|
|
5
|
+
* The project's CI script renders `yodel.config.ts` `waves` as a chant Op
|
|
6
|
+
* waves spec, {@link WAVES_SPEC_FILE}, and the pipeline from it (`chant run
|
|
7
|
+
* --generate <forge> --spec`, or `generateOpWavesPipeline`). Every wave's
|
|
8
|
+
* job runs `chant run wave`, which calls back into yodel twice per
|
|
9
|
+
* environment:
|
|
10
|
+
*
|
|
11
|
+
* - `yodel apply <env> --wave-plan <file>` ({@link writeWavePlan}): the
|
|
12
|
+
* plan file chant binds the wave's gate to. Its `planDigest` covers the
|
|
13
|
+
* migrations' plan digest (what `--digest` prints), the environment's gate
|
|
14
|
+
* policy as the base commit's `yodel.config.ts` has it, and whether a
|
|
15
|
+
* pending step is destructive, which is what `on-destructive` waits on.
|
|
16
|
+
* - `yodel apply <env> --wave-apply <file>` ({@link applyWave}): applies
|
|
17
|
+
* that plan, under the lock, only when chant's decision for the wave lets
|
|
18
|
+
* it through: an approval of the wave's set digest in the gate ledger, or
|
|
19
|
+
* a policy at the base commit that needs none. The plan is computed again
|
|
20
|
+
* under the lock and must be the one the decision was made on.
|
|
21
|
+
*
|
|
22
|
+
* chant reads the policy from the spec file at the first parent, so a pull
|
|
23
|
+
* request that loosens its own environment's gate merges under the old one.
|
|
24
|
+
*/
|
|
25
|
+
import { type ConfigAtBase } from "../config/base.js";
|
|
26
|
+
import type { WaveGate, YodelConfig } from "../config/define.js";
|
|
27
|
+
import type { Migration } from "../migrations/index.js";
|
|
28
|
+
import { type Project } from "../project.js";
|
|
29
|
+
import { type VersionedEnv } from "../versioned/engine.js";
|
|
30
|
+
import type { PendingMigration } from "../versioned/state.js";
|
|
31
|
+
import { type WaveRecord } from "./record.js";
|
|
32
|
+
import { type Promotion } from "./promotion.js";
|
|
33
|
+
export * from "./promotion.js";
|
|
34
|
+
export * from "./record.js";
|
|
35
|
+
/** The waves spec the CI script writes and every wave job reads. */
|
|
36
|
+
export declare const WAVES_SPEC_FILE = "yodel-waves.json";
|
|
37
|
+
export declare const WAVE_PLAN_KIND = "yodel-wave";
|
|
38
|
+
/** The gate policy an environment no wave names gets. */
|
|
39
|
+
export declare const DEFAULT_WAVE_GATE: WaveGate;
|
|
40
|
+
/** `env`'s wave gate in `config`; a tenant's is its environment's. */
|
|
41
|
+
export declare function waveGate(config: YodelConfig | undefined, env: string): {
|
|
42
|
+
gate: WaveGate;
|
|
43
|
+
declared: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** A pending step `on-destructive` waits on, and why. */
|
|
46
|
+
export interface DestructiveStep {
|
|
47
|
+
migration: string;
|
|
48
|
+
step: number;
|
|
49
|
+
what: string;
|
|
50
|
+
/** The lint rule that classes it, or `op-step` / `manual-step`. */
|
|
51
|
+
why: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The steps of `pending` that `on-destructive` waits on: a destructive
|
|
55
|
+
* statement or Op step, a Postgres rewrite or lock-heavy statement, a
|
|
56
|
+
* ClickHouse mutation or rebuild (lint's statement rules, whatever their
|
|
57
|
+
* level or silences), and any Op or manual step.
|
|
58
|
+
*/
|
|
59
|
+
export declare function destructiveSteps(dialect: "clickhouse" | "postgres", pending: ReadonlyArray<Pick<PendingMigration, "id"> & {
|
|
60
|
+
migration: Pick<Migration, "document">;
|
|
61
|
+
}>): DestructiveStep[];
|
|
62
|
+
/** What `--wave-plan` writes: chant's plan file, and what yodel needs to apply exactly it. */
|
|
63
|
+
export interface WavePlanFile {
|
|
64
|
+
/** chant's: what the wave's set digest is taken over. */
|
|
65
|
+
planDigest: string;
|
|
66
|
+
destructive: boolean;
|
|
67
|
+
empty: boolean;
|
|
68
|
+
environment: string;
|
|
69
|
+
/** The migrations' plan digest, as `yodel apply --digest` prints it; the history records it. */
|
|
70
|
+
migrations: string;
|
|
71
|
+
/** The gate policy at the base commit, and that commit. */
|
|
72
|
+
gate: WaveGate;
|
|
73
|
+
base: string;
|
|
74
|
+
pending: string[];
|
|
75
|
+
destructiveSteps: DestructiveStep[];
|
|
76
|
+
/** Each environment this one requires, and the pending migrations its history records applied. */
|
|
77
|
+
requires: Array<{
|
|
78
|
+
env: string;
|
|
79
|
+
applied: Array<{
|
|
80
|
+
id: string;
|
|
81
|
+
checksum: string;
|
|
82
|
+
}>;
|
|
83
|
+
}>;
|
|
84
|
+
}
|
|
85
|
+
/** The wave plan's digest: over what the run would do and the policy it is gated under. */
|
|
86
|
+
export declare function wavePlanDigest(subject: {
|
|
87
|
+
environment: string;
|
|
88
|
+
migrations: string;
|
|
89
|
+
gate: WaveGate;
|
|
90
|
+
destructive: boolean;
|
|
91
|
+
requires?: ReadonlyArray<{
|
|
92
|
+
env: string;
|
|
93
|
+
applied: ReadonlyArray<{
|
|
94
|
+
id: string;
|
|
95
|
+
checksum: string;
|
|
96
|
+
}>;
|
|
97
|
+
}>;
|
|
98
|
+
}): Promise<string>;
|
|
99
|
+
/** The gate policy for `env` at the base commit. */
|
|
100
|
+
export declare function gateAtBase(project: Project, env: string): Promise<{
|
|
101
|
+
gate: WaveGate;
|
|
102
|
+
at: ConfigAtBase;
|
|
103
|
+
declared: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
/** The wave plan for one environment, now. A refusal (out of order, a checksum) throws, as `--digest` does. */
|
|
106
|
+
export declare function planWave(project: Project, venv: VersionedEnv, ordered: readonly Migration[], options: {
|
|
107
|
+
allowOutOfOrder: boolean;
|
|
108
|
+
}): Promise<WavePlanFile>;
|
|
109
|
+
/** `--wave-plan <file>`: writes the plan file. */
|
|
110
|
+
export declare function writeWavePlan(project: Project, venv: VersionedEnv, ordered: readonly Migration[], file: string, options: {
|
|
111
|
+
allowOutOfOrder: boolean;
|
|
112
|
+
}): Promise<WavePlanFile>;
|
|
113
|
+
/**
|
|
114
|
+
* Throws unless chant's decision for `env`'s wave lets `planDigest` apply:
|
|
115
|
+
* the decision names this plan for `env`, and either the gate ledger holds
|
|
116
|
+
* an approval of the wave's set digest, or the wave's policy at the base
|
|
117
|
+
* commit needs no approval for these plans.
|
|
118
|
+
*/
|
|
119
|
+
export declare function verifyWaveDecision(cwd: string, specFile: string, env: string, planDigest: string): Promise<{
|
|
120
|
+
line: string;
|
|
121
|
+
wave: WaveRecord;
|
|
122
|
+
}>;
|
|
123
|
+
/** chant's decision for a wave, as `chant run wave` will make it once this plan is written. */
|
|
124
|
+
export interface WaveForecast {
|
|
125
|
+
wave: number;
|
|
126
|
+
name: string;
|
|
127
|
+
gate: string;
|
|
128
|
+
digest: string;
|
|
129
|
+
policy: string;
|
|
130
|
+
base: string;
|
|
131
|
+
/** No approval of `digest` stands and the policy asks for one: chant exits 3. */
|
|
132
|
+
waits: boolean;
|
|
133
|
+
/** `chant approve <op> <gate> --plan <digest>`. */
|
|
134
|
+
approve: string;
|
|
135
|
+
}
|
|
136
|
+
/** Where chant run wave writes a run's plan file (chant's opWavePlanPath). */
|
|
137
|
+
export declare const wavePlanPath: (op: string, wave: number, target: string) => string;
|
|
138
|
+
/**
|
|
139
|
+
* The decision chant makes for `plan`'s wave right after `--wave-plan`,
|
|
140
|
+
* made the same way and from the same sources: the policy from the spec at
|
|
141
|
+
* yodel's base, chant's own rule, and the gate ledger for an approval of
|
|
142
|
+
* the wave's set digest. A tenant set's wave (#56) has a run per tenant,
|
|
143
|
+
* which chant plans in order: the forecast is made at the last run, from
|
|
144
|
+
* the plan files the runs before it wrote; at any other run it is
|
|
145
|
+
* undefined.
|
|
146
|
+
*/
|
|
147
|
+
export declare function forecastWave(cwd: string, specFile: string, plan: WavePlanFile): Promise<WaveForecast | undefined>;
|
|
148
|
+
/** Reads a plan file `--wave-plan` wrote. */
|
|
149
|
+
export declare function readWavePlan(file: string): WavePlanFile;
|
|
150
|
+
/** What `yodel plan` and the pull request comment show of an environment's wave. */
|
|
151
|
+
export interface WaveView {
|
|
152
|
+
/** 1-based, in yodel.config.ts `waves`. */
|
|
153
|
+
wave: number;
|
|
154
|
+
gate: WaveGate;
|
|
155
|
+
/** The base commit the gate was read at, and how it was chosen. */
|
|
156
|
+
base: string;
|
|
157
|
+
baseSource: string;
|
|
158
|
+
destructiveSteps: DestructiveStep[];
|
|
159
|
+
/** Under the gate at the base, the wave waits for an approval of this plan. */
|
|
160
|
+
waits: boolean;
|
|
161
|
+
/** The wave plan digest and the set digest the wave's gate binds. */
|
|
162
|
+
planDigest: string;
|
|
163
|
+
digest: string;
|
|
164
|
+
/** `chant approve yodel-apply yodel-apply-wave-<k> --plan <digest>`. */
|
|
165
|
+
approve: string;
|
|
166
|
+
/** What each required environment's history records of the pending migrations. */
|
|
167
|
+
promotions: Promotion[];
|
|
168
|
+
/** A pending migration has not run where it must first: the wave refuses until it has, so there is nothing to approve yet. */
|
|
169
|
+
blocked: boolean;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `env`'s wave, as the apply pipeline will plan it after the merge, when
|
|
173
|
+
* yodel.config.ts declares waves and names `env`; undefined otherwise. The
|
|
174
|
+
* gate is the base commit's: on a pull request, the merge base with the
|
|
175
|
+
* target branch.
|
|
176
|
+
*/
|
|
177
|
+
export declare function waveView(project: Project, env: string, ordered: readonly Migration[], pending: readonly PendingMigration[], migrations: string): Promise<WaveView | undefined>;
|
|
178
|
+
/** One line on the wave, for text and markdown. */
|
|
179
|
+
export declare function describeWave(w: WaveView, code?: (s: string) => string): string;
|