@intentius/sql-yodeler 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +110 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +14 -0
- package/dist/bin.js.map +1 -0
- package/dist/chant/apply.d.ts +51 -0
- package/dist/chant/apply.js +104 -0
- package/dist/chant/apply.js.map +1 -0
- package/dist/chant/build.d.ts +34 -0
- package/dist/chant/build.js +48 -0
- package/dist/chant/build.js.map +1 -0
- package/dist/chant/drift.d.ts +44 -0
- package/dist/chant/drift.js +91 -0
- package/dist/chant/drift.js.map +1 -0
- package/dist/chant/plan.d.ts +45 -0
- package/dist/chant/plan.js +61 -0
- package/dist/chant/plan.js.map +1 -0
- package/dist/chant/process.d.ts +41 -0
- package/dist/chant/process.js +87 -0
- package/dist/chant/process.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.d.ts +17 -0
- package/dist/command.js +13 -0
- package/dist/command.js.map +1 -0
- package/dist/commands/apply.d.ts +3 -0
- package/dist/commands/apply.js +306 -0
- package/dist/commands/apply.js.map +1 -0
- package/dist/commands/drift.d.ts +3 -0
- package/dist/commands/drift.js +38 -0
- package/dist/commands/drift.js.map +1 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +22 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +135 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/lint.d.ts +3 -0
- package/dist/commands/lint.js +193 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.js +168 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/plan.d.ts +3 -0
- package/dist/commands/plan.js +171 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/rebase.d.ts +3 -0
- package/dist/commands/rebase.js +167 -0
- package/dist/commands/rebase.js.map +1 -0
- package/dist/commands/repair.d.ts +3 -0
- package/dist/commands/repair.js +117 -0
- package/dist/commands/repair.js.map +1 -0
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +54 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config/define.d.ts +50 -0
- package/dist/config/define.js +20 -0
- package/dist/config/define.js.map +1 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/config/index.js +12 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +17 -0
- package/dist/config/load.js +102 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/settings.d.ts +40 -0
- package/dist/config/settings.js +88 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/env-args.d.ts +18 -0
- package/dist/env-args.js +62 -0
- package/dist/env-args.js.map +1 -0
- package/dist/history/client.d.ts +17 -0
- package/dist/history/client.js +19 -0
- package/dist/history/client.js.map +1 -0
- package/dist/history/ddl.d.ts +58 -0
- package/dist/history/ddl.js +100 -0
- package/dist/history/ddl.js.map +1 -0
- package/dist/history/index.d.ts +25 -0
- package/dist/history/index.js +26 -0
- package/dist/history/index.js.map +1 -0
- package/dist/history/lock.d.ts +100 -0
- package/dist/history/lock.js +224 -0
- package/dist/history/lock.js.map +1 -0
- package/dist/history/postgres/ddl.d.ts +22 -0
- package/dist/history/postgres/ddl.js +47 -0
- package/dist/history/postgres/ddl.js.map +1 -0
- package/dist/history/postgres/index.d.ts +12 -0
- package/dist/history/postgres/index.js +13 -0
- package/dist/history/postgres/index.js.map +1 -0
- package/dist/history/postgres/lock.d.ts +48 -0
- package/dist/history/postgres/lock.js +95 -0
- package/dist/history/postgres/lock.js.map +1 -0
- package/dist/history/postgres/store.d.ts +39 -0
- package/dist/history/postgres/store.js +68 -0
- package/dist/history/postgres/store.js.map +1 -0
- package/dist/history/rows.d.ts +96 -0
- package/dist/history/rows.js +73 -0
- package/dist/history/rows.js.map +1 -0
- package/dist/history/store.d.ts +72 -0
- package/dist/history/store.js +134 -0
- package/dist/history/store.js.map +1 -0
- package/dist/history/topology.d.ts +41 -0
- package/dist/history/topology.js +54 -0
- package/dist/history/topology.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/init/adopt.d.ts +70 -0
- package/dist/init/adopt.js +138 -0
- package/dist/init/adopt.js.map +1 -0
- package/dist/init/baseline.d.ts +61 -0
- package/dist/init/baseline.js +88 -0
- package/dist/init/baseline.js.map +1 -0
- package/dist/init/files.d.ts +23 -0
- package/dist/init/files.js +77 -0
- package/dist/init/files.js.map +1 -0
- package/dist/init/index.d.ts +16 -0
- package/dist/init/index.js +17 -0
- package/dist/init/index.js.map +1 -0
- package/dist/init/live.d.ts +28 -0
- package/dist/init/live.js +45 -0
- package/dist/init/live.js.map +1 -0
- package/dist/lint/check.d.ts +81 -0
- package/dist/lint/check.js +208 -0
- package/dist/lint/check.js.map +1 -0
- package/dist/lint/config.d.ts +21 -0
- package/dist/lint/config.js +43 -0
- package/dist/lint/config.js.map +1 -0
- package/dist/lint/index.d.ts +31 -0
- package/dist/lint/index.js +43 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/lint/project-rules.d.ts +19 -0
- package/dist/lint/project-rules.js +32 -0
- package/dist/lint/project-rules.js.map +1 -0
- package/dist/lint/report.d.ts +7 -0
- package/dist/lint/report.js +48 -0
- package/dist/lint/report.js.map +1 -0
- package/dist/lint/rules.d.ts +53 -0
- package/dist/lint/rules.js +42 -0
- package/dist/lint/rules.js.map +1 -0
- package/dist/lint/silences.d.ts +49 -0
- package/dist/lint/silences.js +91 -0
- package/dist/lint/silences.js.map +1 -0
- package/dist/lint/statements.d.ts +38 -0
- package/dist/lint/statements.js +120 -0
- package/dist/lint/statements.js.map +1 -0
- package/dist/migrations/checksum.d.ts +56 -0
- package/dist/migrations/checksum.js +72 -0
- package/dist/migrations/checksum.js.map +1 -0
- package/dist/migrations/create.d.ts +73 -0
- package/dist/migrations/create.js +119 -0
- package/dist/migrations/create.js.map +1 -0
- package/dist/migrations/directory.d.ts +119 -0
- package/dist/migrations/directory.js +225 -0
- package/dist/migrations/directory.js.map +1 -0
- package/dist/migrations/document.d.ts +83 -0
- package/dist/migrations/document.js +82 -0
- package/dist/migrations/document.js.map +1 -0
- package/dist/migrations/index.d.ts +20 -0
- package/dist/migrations/index.js +21 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/pr/comment.d.ts +32 -0
- package/dist/pr/comment.js +99 -0
- package/dist/pr/comment.js.map +1 -0
- package/dist/pr/forge.d.ts +50 -0
- package/dist/pr/forge.js +105 -0
- package/dist/pr/forge.js.map +1 -0
- package/dist/pr/model.d.ts +91 -0
- package/dist/pr/model.js +113 -0
- package/dist/pr/model.js.map +1 -0
- package/dist/pr/render.d.ts +27 -0
- package/dist/pr/render.js +246 -0
- package/dist/pr/render.js.map +1 -0
- package/dist/project.d.ts +62 -0
- package/dist/project.js +92 -0
- package/dist/project.js.map +1 -0
- package/dist/rebase/index.d.ts +121 -0
- package/dist/rebase/index.js +390 -0
- package/dist/rebase/index.js.map +1 -0
- package/dist/rebase/repair.d.ts +41 -0
- package/dist/rebase/repair.js +68 -0
- package/dist/rebase/repair.js.map +1 -0
- package/dist/replay/clickhouse.d.ts +33 -0
- package/dist/replay/clickhouse.js +106 -0
- package/dist/replay/clickhouse.js.map +1 -0
- package/dist/replay/index.d.ts +36 -0
- package/dist/replay/index.js +54 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/replay/postgres.d.ts +31 -0
- package/dist/replay/postgres.js +140 -0
- package/dist/replay/postgres.js.map +1 -0
- package/dist/replay/replay.d.ts +114 -0
- package/dist/replay/replay.js +98 -0
- package/dist/replay/replay.js.map +1 -0
- package/dist/replay/report.d.ts +18 -0
- package/dist/replay/report.js +72 -0
- package/dist/replay/report.js.map +1 -0
- package/dist/steps/backfill.d.ts +128 -0
- package/dist/steps/backfill.js +307 -0
- package/dist/steps/backfill.js.map +1 -0
- package/dist/steps/index.d.ts +52 -0
- package/dist/steps/index.js +52 -0
- package/dist/steps/index.js.map +1 -0
- package/dist/steps/kinds.d.ts +101 -0
- package/dist/steps/kinds.js +143 -0
- package/dist/steps/kinds.js.map +1 -0
- package/dist/steps/postgres-migration.d.ts +95 -0
- package/dist/steps/postgres-migration.js +149 -0
- package/dist/steps/postgres-migration.js.map +1 -0
- package/dist/steps/rebuild.d.ts +97 -0
- package/dist/steps/rebuild.js +162 -0
- package/dist/steps/rebuild.js.map +1 -0
- package/dist/steps/run.d.ts +45 -0
- package/dist/steps/run.js +72 -0
- package/dist/steps/run.js.map +1 -0
- package/dist/topology/render.d.ts +17 -0
- package/dist/topology/render.js +17 -0
- package/dist/topology/render.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +11 -0
- package/dist/version.js.map +1 -0
- package/dist/versioned/approval.d.ts +35 -0
- package/dist/versioned/approval.js +53 -0
- package/dist/versioned/approval.js.map +1 -0
- package/dist/versioned/clickhouse.d.ts +24 -0
- package/dist/versioned/clickhouse.js +34 -0
- package/dist/versioned/clickhouse.js.map +1 -0
- package/dist/versioned/digest.d.ts +77 -0
- package/dist/versioned/digest.js +69 -0
- package/dist/versioned/digest.js.map +1 -0
- package/dist/versioned/driver.d.ts +41 -0
- package/dist/versioned/driver.js +13 -0
- package/dist/versioned/driver.js.map +1 -0
- package/dist/versioned/engine.d.ts +152 -0
- package/dist/versioned/engine.js +277 -0
- package/dist/versioned/engine.js.map +1 -0
- package/dist/versioned/explain.d.ts +123 -0
- package/dist/versioned/explain.js +289 -0
- package/dist/versioned/explain.js.map +1 -0
- package/dist/versioned/index.d.ts +37 -0
- package/dist/versioned/index.js +54 -0
- package/dist/versioned/index.js.map +1 -0
- package/dist/versioned/op.d.ts +62 -0
- package/dist/versioned/op.js +153 -0
- package/dist/versioned/op.js.map +1 -0
- package/dist/versioned/postgres/catalog.d.ts +33 -0
- package/dist/versioned/postgres/catalog.js +34 -0
- package/dist/versioned/postgres/catalog.js.map +1 -0
- package/dist/versioned/postgres/driver.d.ts +69 -0
- package/dist/versioned/postgres/driver.js +113 -0
- package/dist/versioned/postgres/driver.js.map +1 -0
- package/dist/versioned/postgres/executor.d.ts +104 -0
- package/dist/versioned/postgres/executor.js +172 -0
- package/dist/versioned/postgres/executor.js.map +1 -0
- package/dist/versioned/postgres/index.d.ts +11 -0
- package/dist/versioned/postgres/index.js +12 -0
- package/dist/versioned/postgres/index.js.map +1 -0
- package/dist/versioned/report.d.ts +22 -0
- package/dist/versioned/report.js +81 -0
- package/dist/versioned/report.js.map +1 -0
- package/dist/versioned/state.d.ts +108 -0
- package/dist/versioned/state.js +153 -0
- package/dist/versioned/state.js.map +1 -0
- package/package.json +51 -4
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { guarded } from "../env-args.js";
|
|
3
|
+
import { loadProject, resolveEnvironment, YodelError } from "../project.js";
|
|
4
|
+
import { buildSchema } from "../chant/build.js";
|
|
5
|
+
import { declaredChanges, planEnvironment, planExitCode, planJson, renderPlan, PLAN_NEEDS_OP } from "../chant/plan.js";
|
|
6
|
+
import { findApplyOp, GATED, runApplyOp } from "../chant/apply.js";
|
|
7
|
+
import { readMigrations } from "../migrations/index.js";
|
|
8
|
+
import { migrationSilences } from "../lint/index.js";
|
|
9
|
+
import { askedAgainLine, describeMove, explainAgainst, latestApproval } from "../versioned/explain.js";
|
|
10
|
+
import { declarativeTopologyRefusal } from "../config/settings.js";
|
|
11
|
+
import { ALLOW_OUT_OF_ORDER_ENV, APPROVED_PLAN_ENV, currentDigest, executeApply, findMigrateOp, gitLedger, verifyApproval, hasMigrations, inspect, migrationsDir, closeVersioned, openVersioned, renderStatus, runMigrateOp, selectToApply, statusJson, statusReport, } from "../versioned/index.js";
|
|
12
|
+
/** When the gate's newest approval does not hold: what moved since (or that approval was asked for again), in one line. */
|
|
13
|
+
async function movedSinceApproval(project, venv, ordered, op, digest) {
|
|
14
|
+
try {
|
|
15
|
+
const latest = await latestApproval(await gitLedger(project.dir), op, digest);
|
|
16
|
+
if (!latest?.digest || latest.holds)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (latest.sameDigest) {
|
|
19
|
+
return {
|
|
20
|
+
moved: { approved: latest.digest, by: latest.by, at: latest.at, confirmed: true, changes: [], ...(latest.askedAgain ? { askedAgain: latest.askedAgain } : {}) },
|
|
21
|
+
line: `Nothing was applied. The approval of ${latest.digest} (by ${latest.by} at ${latest.at}) ${askedAgainLine(latest)}.`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const moved = await explainAgainst(venv, ordered, { approvedDigest: latest.digest, approvedAt: latest.at });
|
|
25
|
+
return {
|
|
26
|
+
moved: { approved: latest.digest, by: latest.by, at: latest.at, confirmed: moved.confirmed, changes: moved.changes },
|
|
27
|
+
line: `Nothing was applied. The approval of ${latest.digest} (by ${latest.by} at ${latest.at}) does not hold: the plan moved since. ${moved.confirmed ? "What moved" : "What moved, as far as yodel can tell"}: ${describeMove(moved)}.`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const usage = "usage: yodel apply <env> [--json] [--dir <project>] [--op <name>] [--allow-out-of-order] [--plan]";
|
|
35
|
+
const help = `${usage}
|
|
36
|
+
|
|
37
|
+
Two paths, chosen by the project:
|
|
38
|
+
|
|
39
|
+
- Versioned: the project has a migrations/ directory holding a migration.
|
|
40
|
+
Applies the pending migrations in chain order, statement by statement,
|
|
41
|
+
recording each in the history table (yodel.config.ts history.database,
|
|
42
|
+
else YODEL_HISTORY_DATABASE, default yodeler) under the apply lock. Each
|
|
43
|
+
statement is rendered for the environment's topology (yodel.config.ts
|
|
44
|
+
topology, else sql.profiles.<env>.topology, else YODEL_TOPOLOGY, default
|
|
45
|
+
single) as it is sent. Runs the project's migrations Op for the
|
|
46
|
+
environment (chant run <op>), whose gate is bound to the plan digest: the
|
|
47
|
+
pending migrations' checksums, the topology, the history and the live
|
|
48
|
+
schema. A run that stops at the gate prints the chant approve command;
|
|
49
|
+
approve, then run yodel apply again. If anything the digest covers changes after
|
|
50
|
+
approval, the gate asks again.
|
|
51
|
+
|
|
52
|
+
A migration that failed part way resumes at the statement that failed; a
|
|
53
|
+
statement that succeeded is never sent again. An Op step (a ClickHouse
|
|
54
|
+
rebuild, a backfill) runs in its place among the statements, under the
|
|
55
|
+
same lock and approval; one that failed or was stopped runs again and
|
|
56
|
+
resumes from its receipts, skipping the partitions or batches that
|
|
57
|
+
finished. Every applied migration's
|
|
58
|
+
checksum is checked against its files first, and a mismatch refuses. A
|
|
59
|
+
pending migration the chain puts before an applied one is out of order
|
|
60
|
+
and is refused unless --allow-out-of-order; it is never skipped.
|
|
61
|
+
|
|
62
|
+
- Declarative: no migrations. Plans the declared schema against the live
|
|
63
|
+
database, then runs the project's ApplyOp for the environment behind its
|
|
64
|
+
plan-bound gate.
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
--json print the outcome as JSON
|
|
68
|
+
--op <name> the Op to run, when more than one applies <env>
|
|
69
|
+
--allow-out-of-order versioned: apply out-of-order migrations too
|
|
70
|
+
--plan versioned: print the pending migrations and the plan
|
|
71
|
+
digest, apply nothing
|
|
72
|
+
-C, --dir <dir> the project directory (default: the working directory)
|
|
73
|
+
|
|
74
|
+
The migrations Op runs two steps of its own, not for direct use:
|
|
75
|
+
--digest print the plan digest alone (the Op's Plan step)
|
|
76
|
+
--execute apply under the lock, if the digest is still the one in ${APPROVED_PLAN_ENV}
|
|
77
|
+
and chant's gate ledger holds an approval of the Op's gate for it
|
|
78
|
+
(the Op's Apply step)
|
|
79
|
+
|
|
80
|
+
Exit codes:
|
|
81
|
+
0 applied, or nothing to apply
|
|
82
|
+
2 a change needs its own Op (declarative), or a pending migration has a
|
|
83
|
+
manual step or an Op step apply does not run (versioned: it runs
|
|
84
|
+
ClickHouseRebuildOp in materialized-view mode and backfill steps on
|
|
85
|
+
ClickHouse, PostgresMigrationOp on Postgres);
|
|
86
|
+
nothing was applied
|
|
87
|
+
3 stopped at the gate, waiting for approval of this plan
|
|
88
|
+
4 versioned: refused, nothing applied: a checksum mismatch, an applied
|
|
89
|
+
migration gone from the directory, or an out-of-order migration
|
|
90
|
+
without --allow-out-of-order
|
|
91
|
+
5 versioned: another apply holds the lock
|
|
92
|
+
1 anything else failed: a statement (the history records where; rerun to
|
|
93
|
+
resume), a plan that moved since approval, a bad config
|
|
94
|
+
`;
|
|
95
|
+
function parseApplyArgs(args) {
|
|
96
|
+
let parsed;
|
|
97
|
+
try {
|
|
98
|
+
parsed = parseArgs({
|
|
99
|
+
args,
|
|
100
|
+
allowPositionals: true,
|
|
101
|
+
strict: true,
|
|
102
|
+
options: {
|
|
103
|
+
json: { type: "boolean" },
|
|
104
|
+
dir: { type: "string", short: "C" },
|
|
105
|
+
op: { type: "string" },
|
|
106
|
+
"allow-out-of-order": { type: "boolean" },
|
|
107
|
+
plan: { type: "boolean" },
|
|
108
|
+
digest: { type: "boolean" },
|
|
109
|
+
execute: { type: "boolean" },
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
throw new YodelError(`${e instanceof Error ? e.message : String(e)}\n${usage}`);
|
|
115
|
+
}
|
|
116
|
+
const { values, positionals } = parsed;
|
|
117
|
+
const [env, ...rest] = positionals;
|
|
118
|
+
if (env === undefined || rest.length > 0)
|
|
119
|
+
throw new YodelError(usage);
|
|
120
|
+
const flag = (k) => values[k] === true;
|
|
121
|
+
const modes = ["plan", "digest", "execute"].filter(flag);
|
|
122
|
+
if (modes.length > 1)
|
|
123
|
+
throw new YodelError(`--${modes.join(" and --")} cannot be combined\n${usage}`);
|
|
124
|
+
return {
|
|
125
|
+
env,
|
|
126
|
+
json: flag("json"),
|
|
127
|
+
dir: typeof values.dir === "string" ? values.dir : process.cwd(),
|
|
128
|
+
op: typeof values.op === "string" ? values.op : undefined,
|
|
129
|
+
allowOutOfOrder: flag("allow-out-of-order") || process.env[ALLOW_OUT_OF_ORDER_ENV] === "1",
|
|
130
|
+
plan: flag("plan"),
|
|
131
|
+
digest: flag("digest"),
|
|
132
|
+
execute: flag("execute"),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** `yodel apply <env>`; the exit codes are in `help`. */
|
|
136
|
+
export const apply = {
|
|
137
|
+
name: "apply",
|
|
138
|
+
summary: "bring an environment to the declared schema or the pending migrations",
|
|
139
|
+
implemented: true,
|
|
140
|
+
run: (args, io) => guarded("apply", io, args, help, async () => {
|
|
141
|
+
const a = parseApplyArgs(args);
|
|
142
|
+
const project = await loadProject(a.dir);
|
|
143
|
+
const env = resolveEnvironment(project, a.env);
|
|
144
|
+
if (hasMigrations(project))
|
|
145
|
+
return versionedApply(project, env, a, io);
|
|
146
|
+
if (a.plan || a.digest || a.execute || a.allowOutOfOrder) {
|
|
147
|
+
throw new YodelError(`--plan, --digest, --execute and --allow-out-of-order are for versioned migrations, and ${project.dir} has no migrations/ directory with a migration`);
|
|
148
|
+
}
|
|
149
|
+
const refusal = project.dialect === "clickhouse" ? declarativeTopologyRefusal(project, env.name) : undefined;
|
|
150
|
+
if (refusal)
|
|
151
|
+
throw refusal;
|
|
152
|
+
return declarativeApply(project, env, a, io);
|
|
153
|
+
}),
|
|
154
|
+
};
|
|
155
|
+
async function versionedApply(project, env, a, io) {
|
|
156
|
+
const ordered = readMigrations(migrationsDir(project));
|
|
157
|
+
const venv = await openVersioned(project, env);
|
|
158
|
+
try {
|
|
159
|
+
return await versionedApplyWith(project, env, a, io, ordered, venv);
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
await closeVersioned(venv);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function versionedApplyWith(project, env, a, io, ordered, venv) {
|
|
166
|
+
if (a.digest) {
|
|
167
|
+
const { status } = await inspect(venv, ordered);
|
|
168
|
+
const toApply = selectToApply(status, a.allowOutOfOrder);
|
|
169
|
+
io.out(`${await currentDigest(venv, status, toApply)}\n`);
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
if (a.execute) {
|
|
173
|
+
const approved = process.env[APPROVED_PLAN_ENV];
|
|
174
|
+
if (!approved)
|
|
175
|
+
throw new YodelError(`--execute applies only the plan its Op's gate approved, and ${APPROVED_PLAN_ENV} is not set; run yodel apply ${env.name}`);
|
|
176
|
+
// The env var is only the Op's hand-off; the approval itself is checked in chant's gate ledger, under the lock.
|
|
177
|
+
const op = await findMigrateOp(project, env, a.op);
|
|
178
|
+
const ledger = await gitLedger(project.dir);
|
|
179
|
+
const result = await executeApply(venv, ordered, {
|
|
180
|
+
approvedDigest: approved,
|
|
181
|
+
allowOutOfOrder: a.allowOutOfOrder,
|
|
182
|
+
approve: async (digest) => {
|
|
183
|
+
const by = await verifyApproval(ledger, op, digest);
|
|
184
|
+
io.err(`approval: ${op.name} / ${op.gate} for ${digest}, by ${by.resolvedBy} at ${by.timestamp}\n`);
|
|
185
|
+
},
|
|
186
|
+
log: (l) => { io.err(`${l}\n`); },
|
|
187
|
+
silences: migrationSilences,
|
|
188
|
+
});
|
|
189
|
+
if (a.json)
|
|
190
|
+
io.out(`${JSON.stringify({ environment: env.name, status: "applied", planDigest: approved, ...result }, null, 2)}\n`);
|
|
191
|
+
else
|
|
192
|
+
io.out(result.applied.length === 0 ? "Nothing to apply.\n" : `Applied: ${result.applied.join(", ")}\n`);
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
const report = await statusReport(venv, ordered, { allowOutOfOrder: a.allowOutOfOrder });
|
|
196
|
+
const emit = (doc, code) => {
|
|
197
|
+
if (a.json)
|
|
198
|
+
io.out(`${JSON.stringify({ ...statusJson(report), mode: "versioned", ...doc }, null, 2)}\n`);
|
|
199
|
+
return code;
|
|
200
|
+
};
|
|
201
|
+
if (a.plan) {
|
|
202
|
+
if (!a.json)
|
|
203
|
+
io.out(renderStatus(report));
|
|
204
|
+
return emit({ status: report.refusal ? "refused" : report.status.pending.length === 0 ? "unchanged" : "planned" }, report.refusal?.exitCode ?? 0);
|
|
205
|
+
}
|
|
206
|
+
if (report.refusal) {
|
|
207
|
+
if (!a.json)
|
|
208
|
+
io.err(`yodel apply: ${report.refusal.message}\n`);
|
|
209
|
+
return emit({ status: "refused" }, report.refusal.exitCode);
|
|
210
|
+
}
|
|
211
|
+
if (report.status.pending.length === 0) {
|
|
212
|
+
if (!a.json)
|
|
213
|
+
io.out(`${env.name} is up to date: every migration is applied.\n`);
|
|
214
|
+
return emit({ status: "unchanged" }, 0);
|
|
215
|
+
}
|
|
216
|
+
if (!a.json)
|
|
217
|
+
io.out(renderStatus(report));
|
|
218
|
+
const op = await findMigrateOp(project, env, a.op);
|
|
219
|
+
if (!a.json)
|
|
220
|
+
io.out(`\nRunning ${op.name} (${op.filePath})\n`);
|
|
221
|
+
const run = await runMigrateOp(project, op, { allowOutOfOrder: a.allowOutOfOrder, onOutput: (t) => { io.err(t); } });
|
|
222
|
+
if (run.status === "gated") {
|
|
223
|
+
const stale = await movedSinceApproval(project, venv, ordered, op, run.planDigest ?? report.digest);
|
|
224
|
+
if (stale && !a.json)
|
|
225
|
+
io.out(`\n${stale.line}\n`);
|
|
226
|
+
if (!a.json) {
|
|
227
|
+
io.out(`\n${op.name} is waiting at gate "${op.gate}" for approval of this plan${run.planDigest ? ` (${run.planDigest})` : ""}.\n`);
|
|
228
|
+
if (run.approve)
|
|
229
|
+
io.out(`Approve it with:\n ${run.approve}\nthen run yodel apply ${env.name} again.\n`);
|
|
230
|
+
}
|
|
231
|
+
return emit({ status: "gated", op: op.name, gate: op.gate, ...(stale ? { moved: stale.moved } : {}), ...(run.approve ? { approve: run.approve } : {}), ...(run.planDigest ? { gatePlanDigest: run.planDigest } : {}) }, GATED);
|
|
232
|
+
}
|
|
233
|
+
const after = await statusReport(venv, ordered, { allowOutOfOrder: a.allowOutOfOrder });
|
|
234
|
+
if (run.status === "failed") {
|
|
235
|
+
if (!a.json) {
|
|
236
|
+
io.err(`yodel apply: chant run ${op.name} failed (exit ${String(run.code)})\n`);
|
|
237
|
+
io.out(`\n${renderStatus(after)}`);
|
|
238
|
+
}
|
|
239
|
+
if (a.json)
|
|
240
|
+
io.out(`${JSON.stringify({ ...statusJson(after), mode: "versioned", status: "failed", op: op.name, exitCode: run.code }, null, 2)}\n`);
|
|
241
|
+
return 1;
|
|
242
|
+
}
|
|
243
|
+
if (a.json) {
|
|
244
|
+
io.out(`${JSON.stringify({ ...statusJson(after), mode: "versioned", status: "applied", op: op.name, appliedNow: report.status.pending.map((p) => p.id) }, null, 2)}\n`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
io.out(`\nApplied: ${report.status.pending.map((p) => p.id).join(", ")}.\n`);
|
|
248
|
+
}
|
|
249
|
+
return after.status.pending.length === 0 ? 0 : 1;
|
|
250
|
+
}
|
|
251
|
+
async function declarativeApply(project, env, a, io) {
|
|
252
|
+
const json = a.json;
|
|
253
|
+
const op = await findApplyOp(project, env, a.op);
|
|
254
|
+
const report = (doc, code) => {
|
|
255
|
+
if (json)
|
|
256
|
+
io.out(`${JSON.stringify({ environment: env.name, dialect: project.dialect, op: op.name, ...doc }, null, 2)}\n`);
|
|
257
|
+
return code;
|
|
258
|
+
};
|
|
259
|
+
const build = await buildSchema(project);
|
|
260
|
+
try {
|
|
261
|
+
const before = await planEnvironment(project, env, build);
|
|
262
|
+
if (!json)
|
|
263
|
+
io.out(`${await renderPlan(before, `Plan for ${env.name} (${project.dialect}, sql.profiles.${env.name})`)}\n`);
|
|
264
|
+
if (planExitCode(before) === PLAN_NEEDS_OP) {
|
|
265
|
+
if (!json)
|
|
266
|
+
io.err(`yodel apply: refused: ${String(before.refused.length)} change(s) need their own Op; nothing was applied\n`);
|
|
267
|
+
return report({ status: "refused", plan: planJson(before) }, PLAN_NEEDS_OP);
|
|
268
|
+
}
|
|
269
|
+
if (declaredChanges(before, build).length === 0) {
|
|
270
|
+
if (!json)
|
|
271
|
+
io.out(`${env.name} already matches the declared schema; nothing to apply.\n`);
|
|
272
|
+
return report({ status: "unchanged", plan: planJson(before) }, 0);
|
|
273
|
+
}
|
|
274
|
+
if (!json)
|
|
275
|
+
io.out(`\nRunning ${op.name} (${op.filePath})\n`);
|
|
276
|
+
const run = await runApplyOp(project, op, { onOutput: (t) => { io.err(t); } });
|
|
277
|
+
if (run.status === "gated") {
|
|
278
|
+
if (!json) {
|
|
279
|
+
io.out(`\n${op.name} is waiting at gate "${op.gate}" for approval of this plan.\n`);
|
|
280
|
+
if (run.approve)
|
|
281
|
+
io.out(`Approve it with:\n ${run.approve}\nthen run yodel apply ${env.name} again.\n`);
|
|
282
|
+
}
|
|
283
|
+
return report({ status: "gated", gate: op.gate, ...(run.approve ? { approve: run.approve } : {}), ...(run.planDigest ? { planDigest: run.planDigest } : {}), plan: planJson(before) }, GATED);
|
|
284
|
+
}
|
|
285
|
+
if (run.status === "failed") {
|
|
286
|
+
if (!json)
|
|
287
|
+
io.err(`yodel apply: chant run ${op.name} failed (exit ${String(run.code)})\n`);
|
|
288
|
+
return report({ status: "failed", exitCode: run.code, plan: planJson(before) }, 1);
|
|
289
|
+
}
|
|
290
|
+
// The Op completed: check the server now matches, so a change the applier did not attempt is not reported as applied.
|
|
291
|
+
const after = await planEnvironment(project, env, build);
|
|
292
|
+
const remaining = declaredChanges(after, build);
|
|
293
|
+
if (remaining.length > 0) {
|
|
294
|
+
if (!json)
|
|
295
|
+
io.err(`yodel apply: ${op.name} completed but ${String(remaining.length)} change(s) to declared objects are still planned (a drop the Op's delete mode withholds, or a change it did not attempt):\n${await renderPlan(after, `Plan for ${env.name} after apply`)}\n`);
|
|
296
|
+
return report({ status: "incomplete", plan: planJson(before), remaining: planJson(after) }, 1);
|
|
297
|
+
}
|
|
298
|
+
if (!json)
|
|
299
|
+
io.out(`\nApplied: ${env.name} matches the declared schema.\n`);
|
|
300
|
+
return report({ status: "applied", plan: planJson(before) }, 0);
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
build.dispose();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/commands/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAkC,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACvH,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAkB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvG,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,aAAa,EACb,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,GAGb,MAAM,uBAAuB,CAAC;AAE/B,2HAA2H;AAC3H,KAAK,UAAU,kBAAkB,CAAC,OAAgB,EAAE,IAAkB,EAAE,OAA6B,EAAE,EAAgB,EAAE,MAA0B;I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QAED,sHAAsH;QACtH,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAChD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI;gBAAE,EAAE,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,IAAI,kBAAkB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,8HAA8H,MAAM,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;YAClR,OAAO,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,CAAC,IAAI;YAAE,EAAE,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,IAAI,iCAAiC,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { guarded, parseEnvArgs, usage } from "../env-args.js";
|
|
2
|
+
import { loadProject, resolveEnvironment } from "../project.js";
|
|
3
|
+
import { driftExitCode, readDrift, renderDrift } from "../chant/drift.js";
|
|
4
|
+
const help = `${usage("drift")}
|
|
5
|
+
|
|
6
|
+
Reports the declared objects changed out of band or gone from the
|
|
7
|
+
environment, from chant lifecycle diff <env> --live. Objects the project does
|
|
8
|
+
not declare are never reported.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--json print the drift as JSON
|
|
12
|
+
-C, --dir <dir> the project directory (default: the working directory)
|
|
13
|
+
|
|
14
|
+
Exit codes:
|
|
15
|
+
0 no drift
|
|
16
|
+
2 a declared object changed out of band, or is gone
|
|
17
|
+
1 the drift could not be read, or there is none but a declared object
|
|
18
|
+
could not be read (its state is unknown, not clean)
|
|
19
|
+
`;
|
|
20
|
+
/** `yodel drift <env>`; the exit codes are in `help`. */
|
|
21
|
+
export const drift = {
|
|
22
|
+
name: "drift",
|
|
23
|
+
summary: "report declared objects changed out of band or gone from an environment",
|
|
24
|
+
implemented: true,
|
|
25
|
+
run: (args, io) => guarded("drift", io, args, help, async () => {
|
|
26
|
+
const { env: name, json, dir } = parseEnvArgs("drift", args);
|
|
27
|
+
const project = await loadProject(dir);
|
|
28
|
+
const env = resolveEnvironment(project, name);
|
|
29
|
+
const result = await readDrift(project, env);
|
|
30
|
+
const code = driftExitCode(result);
|
|
31
|
+
if (json)
|
|
32
|
+
io.out(`${JSON.stringify({ ...result, dialect: project.dialect, drifted: code === 2 }, null, 2)}\n`);
|
|
33
|
+
else
|
|
34
|
+
io.out(renderDrift(result));
|
|
35
|
+
return code;
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=drift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../../src/commands/drift.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;CAe7B,CAAC;AAEF,yDAAyD;AACzD,MAAM,CAAC,MAAM,KAAK,GAAY;IAC5B,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,yEAAyE;IAClF,WAAW,EAAE,IAAI;IACjB,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAChB,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC7D,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,IAAI;YAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;;YAC1G,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { apply } from "./apply.js";
|
|
2
|
+
import { drift } from "./drift.js";
|
|
3
|
+
import { init } from "./init.js";
|
|
4
|
+
import { lint } from "./lint.js";
|
|
5
|
+
import { newCommand } from "./new.js";
|
|
6
|
+
import { plan } from "./plan.js";
|
|
7
|
+
import { rebase } from "./rebase.js";
|
|
8
|
+
import { repair } from "./repair.js";
|
|
9
|
+
import { status } from "./status.js";
|
|
10
|
+
/** Every verb, in the order `yodel --help` lists them. */
|
|
11
|
+
export const commands = [
|
|
12
|
+
init,
|
|
13
|
+
plan,
|
|
14
|
+
apply,
|
|
15
|
+
newCommand,
|
|
16
|
+
lint,
|
|
17
|
+
status,
|
|
18
|
+
drift,
|
|
19
|
+
rebase,
|
|
20
|
+
repair,
|
|
21
|
+
];
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,0DAA0D;AAC1D,MAAM,CAAC,MAAM,QAAQ,GAAuB;IAC1C,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,UAAU;IACV,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;CACP,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { guarded } from "../env-args.js";
|
|
3
|
+
import { loadProject, resolveEnvironment, YodelError } from "../project.js";
|
|
4
|
+
import { migrationId } from "../migrations/index.js";
|
|
5
|
+
import { adopt, BASELINE_NAME } from "../init/index.js";
|
|
6
|
+
const usage = "usage: yodel init --from <env> [--json] [--dir <project>] [--force] [--name <name>]";
|
|
7
|
+
const help = `${usage}
|
|
8
|
+
|
|
9
|
+
Adopts an existing database. Reads the live database sql.profiles.<env>
|
|
10
|
+
binds, with chant's import (what chant import --from <env> runs), writes
|
|
11
|
+
its declarations to the source directory (sourceDir, else src/), builds
|
|
12
|
+
them and plans them against the same database, which must show no change.
|
|
13
|
+
Then writes the baseline migration, migrations/<YYYYMMDDTHHMM>-baseline/,
|
|
14
|
+
the first migration (no parent), whose statements create everything, and
|
|
15
|
+
records it applied in the history table (yodel.config.ts history.database,
|
|
16
|
+
else YODEL_HISTORY_DATABASE, default yodeler) without running any of them.
|
|
17
|
+
From there, yodel plan <env> shows no change, yodel status <env> lists the
|
|
18
|
+
baseline applied with nothing pending, and yodel new writes the next
|
|
19
|
+
migration after the baseline.
|
|
20
|
+
|
|
21
|
+
The live database is only read. The one write to the server is the
|
|
22
|
+
baseline's history row (and the history's database and table, when they
|
|
23
|
+
are not there yet). If any step fails, every file init wrote is taken back.
|
|
24
|
+
|
|
25
|
+
What must exist first: a project directory with a chant.config.ts that has
|
|
26
|
+
lexicons: ["sql"], sql.dialect and sql.profiles.<env> (credentials by env
|
|
27
|
+
var), and a package.json from which chant and @intentius/chant-lexicon-sql
|
|
28
|
+
resolve, since chant builds the declarations. For ClickHouse the profile
|
|
29
|
+
must list the project's databases (sql.profiles.<env>.databases), for
|
|
30
|
+
Postgres its schemas (sql.profiles.<env>.schemas), and the history's
|
|
31
|
+
database (schema) must not be one of them. init does not write
|
|
32
|
+
chant.config.ts.
|
|
33
|
+
|
|
34
|
+
Postgres: the same, the history being <history database>.history in a
|
|
35
|
+
schema of that name (default yodeler.history), and the profile listing the
|
|
36
|
+
project's schemas (sql.profiles.<env>.schemas), the history's not among them.
|
|
37
|
+
|
|
38
|
+
Ownership: chant's import strips chant's ownership marker from comments,
|
|
39
|
+
and the plan compares declared definitions without it, so objects made by
|
|
40
|
+
hand (no marker) plan clean. init does not stamp the marker on them: they
|
|
41
|
+
stay unmarked, so chant never prunes them, until a declarative apply
|
|
42
|
+
restamps their comments.
|
|
43
|
+
|
|
44
|
+
Options:
|
|
45
|
+
--from <env> the environment to adopt (required)
|
|
46
|
+
--name <name> the baseline migration's name (default ${BASELINE_NAME})
|
|
47
|
+
--force overwrite declaration files the source directory already has
|
|
48
|
+
--json print what was done as JSON
|
|
49
|
+
-C, --dir <dir> the project directory (default: the working directory)
|
|
50
|
+
|
|
51
|
+
Exit codes:
|
|
52
|
+
0 adopted: declarations and the baseline written, the baseline recorded applied
|
|
53
|
+
4 refused, nothing written: the source directory already declares a
|
|
54
|
+
schema (without --force), the project already has migrations, the
|
|
55
|
+
history already records migrations, the environment holds nothing, or
|
|
56
|
+
a ClickHouse profile with no databases or with the history's database
|
|
57
|
+
5 another apply holds the lock; nothing recorded, nothing kept
|
|
58
|
+
1 anything else failed, and nothing was kept: a bad config, a server it
|
|
59
|
+
cannot read, a build or a plan that is not clean after the import
|
|
60
|
+
`;
|
|
61
|
+
function parseInitArgs(args) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = parseArgs({
|
|
65
|
+
args,
|
|
66
|
+
allowPositionals: false,
|
|
67
|
+
strict: true,
|
|
68
|
+
options: {
|
|
69
|
+
from: { type: "string" },
|
|
70
|
+
json: { type: "boolean" },
|
|
71
|
+
dir: { type: "string", short: "C" },
|
|
72
|
+
force: { type: "boolean" },
|
|
73
|
+
name: { type: "string" },
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
throw new YodelError(`${e instanceof Error ? e.message : String(e)}\n${usage}`);
|
|
79
|
+
}
|
|
80
|
+
const { values } = parsed;
|
|
81
|
+
if (typeof values.from !== "string" || values.from === "")
|
|
82
|
+
throw new YodelError(`--from <env> is required\n${usage}`);
|
|
83
|
+
const name = typeof values.name === "string" ? values.name : BASELINE_NAME;
|
|
84
|
+
migrationId(name, new Date()); // a bad name fails before anything is read
|
|
85
|
+
return {
|
|
86
|
+
from: values.from,
|
|
87
|
+
json: values.json === true,
|
|
88
|
+
dir: typeof values.dir === "string" ? values.dir : process.cwd(),
|
|
89
|
+
force: values.force === true,
|
|
90
|
+
name,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function report(io, json, a) {
|
|
94
|
+
if (json) {
|
|
95
|
+
io.out(`${JSON.stringify({
|
|
96
|
+
environment: a.environment,
|
|
97
|
+
dialect: a.dialect,
|
|
98
|
+
status: "adopted",
|
|
99
|
+
objects: a.objects,
|
|
100
|
+
schemaFiles: a.schemaFiles,
|
|
101
|
+
migration: { path: a.migrationPath, ...a.baseline },
|
|
102
|
+
recorded: { history: a.recorded.database, seq: a.recorded.row.seq, note: a.recorded.row.note, appliedBy: a.recorded.row.applied_by },
|
|
103
|
+
warnings: a.warnings,
|
|
104
|
+
}, null, 2)}\n`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const lines = [
|
|
108
|
+
`Adopted ${a.environment} (${a.dialect}): ${String(a.objects.length)} object${a.objects.length === 1 ? "" : "s"}`,
|
|
109
|
+
...a.objects.map((o) => ` ${o}`),
|
|
110
|
+
"",
|
|
111
|
+
`Declarations: ${a.schemaFiles.join(", ")}`,
|
|
112
|
+
`Baseline: ${a.migrationPath}/ (${String(a.baseline.statements)} statement${a.baseline.statements === 1 ? "" : "s"}, ${a.baseline.checksum})`,
|
|
113
|
+
`Recorded: applied in ${a.recorded.database}.history as a baseline; none of its statements was run`,
|
|
114
|
+
"",
|
|
115
|
+
`yodel plan ${a.environment} shows no change, and yodel status ${a.environment} lists the baseline applied.`,
|
|
116
|
+
];
|
|
117
|
+
for (const w of a.warnings)
|
|
118
|
+
lines.push(`warning: ${w}`);
|
|
119
|
+
io.out(`${lines.join("\n")}\n`);
|
|
120
|
+
}
|
|
121
|
+
/** `yodel init --from <env>`; the exit codes are in `help`. */
|
|
122
|
+
export const init = {
|
|
123
|
+
name: "init",
|
|
124
|
+
summary: "adopt a live database: its declarations, a baseline migration, recorded applied",
|
|
125
|
+
implemented: true,
|
|
126
|
+
run: (args, io) => guarded("init", io, args, help, async () => {
|
|
127
|
+
const a = parseInitArgs(args);
|
|
128
|
+
const project = await loadProject(a.dir);
|
|
129
|
+
const env = resolveEnvironment(project, a.from);
|
|
130
|
+
const adopted = await adopt(project, env, { force: a.force, name: a.name, log: (l) => { io.err(`${l}\n`); } });
|
|
131
|
+
report(io, a.json, adopted);
|
|
132
|
+
return 0;
|
|
133
|
+
}),
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAEtE,MAAM,KAAK,GAAG,qFAAqF,CAAC;AAEpG,MAAM,IAAI,GAAG,GAAG,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4DAuCuC,aAAa;;;;;;;;;;;;;;CAcxE,CAAC;AAUF,SAAS,aAAa,CAAC,IAAc;IACnC,IAAI,MAAoC,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,SAAS,CAAC;YACjB,IAAI;YACJ,gBAAgB,EAAE,KAAK;YACvB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE;gBACP,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACxB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gBACzB,GAAG,EAAE,EAAE,IAAI,EAAE,Q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