chkit 0.1.0-beta.9 → 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/README.md +38 -2
- package/dist/bin/chkit.js +230 -203
- package/dist/bin/chkit.js.map +1 -1
- package/dist/bin/clickhouse-resource.d.ts +4 -0
- package/dist/bin/clickhouse-resource.d.ts.map +1 -0
- package/dist/bin/clickhouse-resource.js +11 -0
- package/dist/bin/clickhouse-resource.js.map +1 -0
- package/dist/bin/command-dispatch.d.ts +13 -0
- package/dist/bin/command-dispatch.d.ts.map +1 -0
- package/dist/bin/command-dispatch.js +186 -0
- package/dist/bin/command-dispatch.js.map +1 -0
- package/dist/bin/commands/check.d.ts +1 -1
- package/dist/bin/commands/check.d.ts.map +1 -1
- package/dist/bin/commands/check.js +157 -107
- package/dist/bin/commands/check.js.map +1 -1
- package/dist/bin/commands/drift.d.ts +6 -2
- package/dist/bin/commands/drift.d.ts.map +1 -1
- package/dist/bin/commands/drift.js +49 -8
- package/dist/bin/commands/drift.js.map +1 -1
- package/dist/bin/commands/generate.d.ts.map +1 -1
- package/dist/bin/commands/generate.js +4 -0
- package/dist/bin/commands/generate.js.map +1 -1
- package/dist/bin/commands/migrate.d.ts.map +1 -1
- package/dist/bin/commands/migrate.js +189 -171
- package/dist/bin/commands/migrate.js.map +1 -1
- package/dist/bin/commands/status.d.ts.map +1 -1
- package/dist/bin/commands/status.js +15 -5
- package/dist/bin/commands/status.js.map +1 -1
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +14 -5
- package/dist/bin/config.js.map +1 -1
- package/dist/bin/debug.d.ts +3 -0
- package/dist/bin/debug.d.ts.map +1 -0
- package/dist/bin/debug.js +14 -0
- package/dist/bin/debug.js.map +1 -0
- package/dist/bin/help.d.ts.map +1 -1
- package/dist/bin/help.js +1 -0
- package/dist/bin/help.js.map +1 -1
- package/dist/bin/internal-plugins/index.d.ts +3 -0
- package/dist/bin/internal-plugins/index.d.ts.map +1 -0
- package/dist/bin/internal-plugins/index.js +5 -0
- package/dist/bin/internal-plugins/index.js.map +1 -0
- package/dist/bin/internal-plugins/skill-hint.d.ts +31 -0
- package/dist/bin/internal-plugins/skill-hint.d.ts.map +1 -0
- package/dist/bin/internal-plugins/skill-hint.js +172 -0
- package/dist/bin/internal-plugins/skill-hint.js.map +1 -0
- package/dist/bin/journal-store.d.ts +3 -6
- package/dist/bin/journal-store.d.ts.map +1 -1
- package/dist/bin/journal-store.js +87 -16
- package/dist/bin/journal-store.js.map +1 -1
- package/dist/bin/json-output.d.ts +2 -5
- package/dist/bin/json-output.d.ts.map +1 -1
- package/dist/bin/json-output.js +1 -1
- package/dist/bin/json-output.js.map +1 -1
- package/dist/bin/lib.d.ts +2 -5
- package/dist/bin/lib.d.ts.map +1 -1
- package/dist/bin/lib.js +2 -5
- package/dist/bin/lib.js.map +1 -1
- package/dist/bin/logging.d.ts +3 -0
- package/dist/bin/logging.d.ts.map +1 -0
- package/dist/bin/logging.js +31 -0
- package/dist/bin/logging.js.map +1 -0
- package/dist/bin/migration-store.d.ts +2 -2
- package/dist/bin/migration-store.d.ts.map +1 -1
- package/dist/bin/migration-store.js +1 -1
- package/dist/bin/migration-store.js.map +1 -1
- package/dist/bin/plugin-runtime.d.ts +9 -1
- package/dist/bin/plugin-runtime.d.ts.map +1 -1
- package/dist/bin/plugin-runtime.js +251 -2
- package/dist/bin/plugin-runtime.js.map +1 -1
- package/dist/bin/safety-markers.d.ts +3 -4
- package/dist/bin/safety-markers.d.ts.map +1 -1
- package/dist/bin/safety-markers.js +4 -13
- package/dist/bin/safety-markers.js.map +1 -1
- package/dist/bin/schema-loader.d.ts +1 -1
- package/dist/bin/schema-loader.d.ts.map +1 -1
- package/dist/bin/schema-loader.js +7 -2
- package/dist/bin/schema-loader.js.map +1 -1
- package/dist/bin/table-scope.d.ts +1 -2
- package/dist/bin/table-scope.d.ts.map +1 -1
- package/dist/bin/table-scope.js +1 -1
- package/dist/bin/table-scope.js.map +1 -1
- package/dist/commands/check/command.d.ts +3 -0
- package/dist/commands/check/command.d.ts.map +1 -0
- package/dist/commands/check/command.js +106 -0
- package/dist/commands/check/command.js.map +1 -0
- package/dist/commands/check/output.d.ts +35 -0
- package/dist/commands/check/output.d.ts.map +1 -0
- package/dist/commands/check/output.js +105 -0
- package/dist/commands/check/output.js.map +1 -0
- package/dist/commands/drift/command.d.ts +3 -0
- package/dist/commands/drift/command.d.ts.map +1 -0
- package/dist/commands/drift/command.js +128 -0
- package/dist/commands/drift/command.js.map +1 -0
- package/dist/commands/drift/compare.d.ts +66 -0
- package/dist/commands/drift/compare.d.ts.map +1 -0
- package/dist/commands/drift/compare.js +220 -0
- package/dist/commands/drift/compare.js.map +1 -0
- package/dist/commands/drift/diff.d.ts +8 -0
- package/dist/commands/drift/diff.d.ts.map +1 -0
- package/dist/commands/drift/diff.js +46 -0
- package/dist/commands/drift/diff.js.map +1 -0
- package/dist/commands/drift/payload.d.ts +38 -0
- package/dist/commands/drift/payload.d.ts.map +1 -0
- package/dist/commands/drift/payload.js +111 -0
- package/dist/commands/drift/payload.js.map +1 -0
- package/dist/commands/generate/command.d.ts +3 -0
- package/dist/commands/generate/command.d.ts.map +1 -0
- package/dist/commands/generate/command.js +163 -0
- package/dist/commands/generate/command.js.map +1 -0
- package/dist/commands/generate/output.d.ts +8 -0
- package/dist/commands/generate/output.d.ts.map +1 -0
- package/dist/commands/generate/output.js +59 -0
- package/dist/commands/generate/output.js.map +1 -0
- package/dist/commands/generate/plan-pipeline.d.ts +7 -0
- package/dist/commands/generate/plan-pipeline.d.ts.map +1 -0
- package/dist/commands/generate/plan-pipeline.js +143 -0
- package/dist/commands/generate/plan-pipeline.js.map +1 -0
- package/dist/commands/generate/rename-mappings.d.ts +29 -0
- package/dist/commands/generate/rename-mappings.d.ts.map +1 -0
- package/dist/commands/generate/rename-mappings.js +195 -0
- package/dist/commands/generate/rename-mappings.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +101 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/migrate/apply.d.ts +33 -0
- package/dist/commands/migrate/apply.d.ts.map +1 -0
- package/dist/commands/migrate/apply.js +143 -0
- package/dist/commands/migrate/apply.js.map +1 -0
- package/dist/commands/migrate/async-apply.d.ts +30 -0
- package/dist/commands/migrate/async-apply.d.ts.map +1 -0
- package/dist/commands/migrate/async-apply.js +258 -0
- package/dist/commands/migrate/async-apply.js.map +1 -0
- package/dist/commands/migrate/command.d.ts +3 -0
- package/dist/commands/migrate/command.d.ts.map +1 -0
- package/dist/commands/migrate/command.js +207 -0
- package/dist/commands/migrate/command.js.map +1 -0
- package/dist/commands/migrate/destructive.d.ts +7 -0
- package/dist/commands/migrate/destructive.d.ts.map +1 -0
- package/dist/commands/migrate/destructive.js +24 -0
- package/dist/commands/migrate/destructive.js.map +1 -0
- package/dist/commands/migrate/prompts.d.ts +6 -0
- package/dist/commands/migrate/prompts.d.ts.map +1 -0
- package/dist/commands/migrate/prompts.js +40 -0
- package/dist/commands/migrate/prompts.js.map +1 -0
- package/dist/commands/migrate/scope.d.ts +12 -0
- package/dist/commands/migrate/scope.d.ts.map +1 -0
- package/dist/commands/migrate/scope.js +35 -0
- package/dist/commands/migrate/scope.js.map +1 -0
- package/dist/commands/plugin.d.ts +3 -0
- package/dist/commands/plugin.d.ts.map +1 -0
- package/dist/commands/plugin.js +129 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/query.d.ts +17 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +155 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/skills.d.ts +13 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +25 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +69 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/drift.d.ts +7 -6
- package/dist/drift.d.ts.map +1 -1
- package/dist/drift.js +19 -8
- package/dist/drift.js.map +1 -1
- package/dist/internal-plugins/core/plugin.d.ts +2 -0
- package/dist/internal-plugins/core/plugin.d.ts.map +1 -0
- package/dist/internal-plugins/core/plugin.js +21 -0
- package/dist/internal-plugins/core/plugin.js.map +1 -0
- package/dist/internal-plugins/index.d.ts +3 -0
- package/dist/internal-plugins/index.d.ts.map +1 -0
- package/dist/internal-plugins/index.js +6 -0
- package/dist/internal-plugins/index.js.map +1 -0
- package/dist/internal-plugins/skill-hint/agent-detect.d.ts +20 -0
- package/dist/internal-plugins/skill-hint/agent-detect.d.ts.map +1 -0
- package/dist/internal-plugins/skill-hint/agent-detect.js +68 -0
- package/dist/internal-plugins/skill-hint/agent-detect.js.map +1 -0
- package/dist/internal-plugins/skill-hint/plugin.d.ts +16 -0
- package/dist/internal-plugins/skill-hint/plugin.d.ts.map +1 -0
- package/dist/internal-plugins/skill-hint/plugin.js +60 -0
- package/dist/internal-plugins/skill-hint/plugin.js.map +1 -0
- package/dist/internal-plugins/skill-hint/prompt.d.ts +5 -0
- package/dist/internal-plugins/skill-hint/prompt.d.ts.map +1 -0
- package/dist/internal-plugins/skill-hint/prompt.js +37 -0
- package/dist/internal-plugins/skill-hint/prompt.js.map +1 -0
- package/dist/internal-plugins/skill-hint/state.d.ts +7 -0
- package/dist/internal-plugins/skill-hint/state.d.ts.map +1 -0
- package/dist/internal-plugins/skill-hint/state.js +23 -0
- package/dist/internal-plugins/skill-hint/state.js.map +1 -0
- package/dist/plugins.d.ts +109 -27
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +0 -6
- package/dist/plugins.js.map +1 -1
- package/dist/runtime/command-dispatch.d.ts +18 -0
- package/dist/runtime/command-dispatch.d.ts.map +1 -0
- package/dist/runtime/command-dispatch.js +227 -0
- package/dist/runtime/command-dispatch.js.map +1 -0
- package/dist/runtime/command-registry.d.ts +31 -0
- package/dist/runtime/command-registry.d.ts.map +1 -0
- package/dist/runtime/command-registry.js +74 -0
- package/dist/runtime/command-registry.js.map +1 -0
- package/dist/runtime/config-merge.d.ts +4 -0
- package/dist/runtime/config-merge.d.ts.map +1 -0
- package/dist/runtime/config-merge.js +72 -0
- package/dist/runtime/config-merge.js.map +1 -0
- package/dist/runtime/config.d.ts +30 -0
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/runtime/config.js +173 -0
- package/dist/runtime/config.js.map +1 -0
- package/dist/runtime/debug.d.ts +3 -0
- package/dist/runtime/debug.d.ts.map +1 -0
- package/dist/runtime/debug.js +14 -0
- package/dist/runtime/debug.js.map +1 -0
- package/dist/runtime/deps.d.ts +28 -0
- package/dist/runtime/deps.d.ts.map +1 -0
- package/dist/runtime/deps.js +91 -0
- package/dist/runtime/deps.js.map +1 -0
- package/dist/runtime/extract-config-path.d.ts +2 -0
- package/dist/runtime/extract-config-path.d.ts.map +1 -0
- package/dist/runtime/extract-config-path.js +13 -0
- package/dist/runtime/extract-config-path.js.map +1 -0
- package/dist/runtime/global-flags.d.ts +16 -0
- package/dist/runtime/global-flags.d.ts.map +1 -0
- package/dist/runtime/global-flags.js +7 -0
- package/dist/runtime/global-flags.js.map +1 -0
- package/dist/runtime/help.d.ts +5 -0
- package/dist/runtime/help.d.ts.map +1 -0
- package/dist/runtime/help.js +94 -0
- package/dist/runtime/help.js.map +1 -0
- package/dist/runtime/journal-store.d.ts +31 -0
- package/dist/runtime/journal-store.d.ts.map +1 -0
- package/dist/runtime/journal-store.js +235 -0
- package/dist/runtime/journal-store.js.map +1 -0
- package/dist/runtime/json-output.d.ts +25 -0
- package/dist/runtime/json-output.d.ts.map +1 -0
- package/dist/runtime/json-output.js +50 -0
- package/dist/runtime/json-output.js.map +1 -0
- package/dist/runtime/logging.d.ts +3 -0
- package/dist/runtime/logging.d.ts.map +1 -0
- package/dist/runtime/logging.js +31 -0
- package/dist/runtime/logging.js.map +1 -0
- package/dist/runtime/migration-metadata.d.ts +5 -0
- package/dist/runtime/migration-metadata.d.ts.map +1 -0
- package/dist/runtime/migration-metadata.js +29 -0
- package/dist/runtime/migration-metadata.js.map +1 -0
- package/dist/runtime/migration-store.d.ts +22 -0
- package/dist/runtime/migration-store.d.ts.map +1 -0
- package/dist/runtime/migration-store.js +60 -0
- package/dist/runtime/migration-store.js.map +1 -0
- package/dist/runtime/plugin-runtime/errors.d.ts +3 -0
- package/dist/runtime/plugin-runtime/errors.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/errors.js +13 -0
- package/dist/runtime/plugin-runtime/errors.js.map +1 -0
- package/dist/runtime/plugin-runtime/executor-debug.d.ts +3 -0
- package/dist/runtime/plugin-runtime/executor-debug.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/executor-debug.js +65 -0
- package/dist/runtime/plugin-runtime/executor-debug.js.map +1 -0
- package/dist/runtime/plugin-runtime/hooks.d.ts +23 -0
- package/dist/runtime/plugin-runtime/hooks.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/hooks.js +148 -0
- package/dist/runtime/plugin-runtime/hooks.js.map +1 -0
- package/dist/runtime/plugin-runtime/index.d.ts +9 -0
- package/dist/runtime/plugin-runtime/index.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/index.js +184 -0
- package/dist/runtime/plugin-runtime/index.js.map +1 -0
- package/dist/runtime/plugin-runtime/loader.d.ts +11 -0
- package/dist/runtime/plugin-runtime/loader.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/loader.js +37 -0
- package/dist/runtime/plugin-runtime/loader.js.map +1 -0
- package/dist/runtime/plugin-runtime/null-executor.d.ts +3 -0
- package/dist/runtime/plugin-runtime/null-executor.d.ts.map +1 -0
- package/dist/runtime/plugin-runtime/null-executor.js +17 -0
- package/dist/runtime/plugin-runtime/null-executor.js.map +1 -0
- package/dist/runtime/safety-markers.d.ts +56 -0
- package/dist/runtime/safety-markers.d.ts.map +1 -0
- package/dist/runtime/safety-markers.js +211 -0
- package/dist/runtime/safety-markers.js.map +1 -0
- package/dist/runtime/schema-loader.d.ts +3 -0
- package/dist/runtime/schema-loader.d.ts.map +1 -0
- package/dist/runtime/schema-loader.js +11 -0
- package/dist/runtime/schema-loader.js.map +1 -0
- package/dist/runtime/table-scope.d.ts +33 -0
- package/dist/runtime/table-scope.d.ts.map +1 -0
- package/dist/runtime/table-scope.js +167 -0
- package/dist/runtime/table-scope.js.map +1 -0
- package/dist/runtime/user-config.d.ts +4 -0
- package/dist/runtime/user-config.d.ts.map +1 -0
- package/dist/runtime/user-config.js +11 -0
- package/dist/runtime/user-config.js.map +1 -0
- package/dist/runtime/version.d.ts +2 -0
- package/dist/runtime/version.d.ts.map +1 -0
- package/dist/runtime/version.js +5 -0
- package/dist/runtime/version.js.map +1 -0
- package/package.json +24 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { isUnknownDatabaseError } from '@chkit/clickhouse';
|
|
3
3
|
import { typedFlags } from '../../plugins.js';
|
|
4
4
|
import { GLOBAL_FLAGS } from '../global-flags.js';
|
|
5
5
|
import { compareSchemaObjects, compareTableShape, } from '../../drift.js';
|
|
6
|
+
import { debug } from '../debug.js';
|
|
6
7
|
import { emitJson } from '../json-output.js';
|
|
7
8
|
import { readSnapshot } from '../migration-store.js';
|
|
8
9
|
import { resolveTableScope, tableKeysFromDefinitions } from '../table-scope.js';
|
|
@@ -12,12 +13,44 @@ export const driftCommand = {
|
|
|
12
13
|
flags: [],
|
|
13
14
|
run: cmdDrift,
|
|
14
15
|
};
|
|
15
|
-
export async function buildDriftPayload(config, metaDir, snapshot, scope) {
|
|
16
|
+
export async function buildDriftPayload(config, metaDir, snapshot, scope, executor) {
|
|
16
17
|
const selectedTables = scope?.enabled && scope.matchCount > 0 ? new Set(scope.matchedTables) : undefined;
|
|
17
|
-
if (!
|
|
18
|
+
if (!executor)
|
|
18
19
|
throw new Error('clickhouse config is required for drift checks');
|
|
19
|
-
const db =
|
|
20
|
-
|
|
20
|
+
const db = executor;
|
|
21
|
+
debug('drift', `building drift payload — expected: ${snapshot.definitions.length} definitions`);
|
|
22
|
+
let actualObjects;
|
|
23
|
+
try {
|
|
24
|
+
actualObjects = await db.listSchemaObjects();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (isUnknownDatabaseError(error)) {
|
|
28
|
+
const allExpected = snapshot.definitions
|
|
29
|
+
.filter((def) => {
|
|
30
|
+
if (!selectedTables)
|
|
31
|
+
return true;
|
|
32
|
+
if (def.kind !== 'table')
|
|
33
|
+
return true;
|
|
34
|
+
return selectedTables.has(`${def.database}.${def.name}`);
|
|
35
|
+
})
|
|
36
|
+
.map((def) => `${def.database}.${def.name}`);
|
|
37
|
+
return {
|
|
38
|
+
scope,
|
|
39
|
+
snapshotFile: join(metaDir, 'snapshot.json'),
|
|
40
|
+
expectedCount: allExpected.length,
|
|
41
|
+
actualCount: 0,
|
|
42
|
+
drifted: allExpected.length > 0,
|
|
43
|
+
databaseMissing: true,
|
|
44
|
+
database: config.clickhouse?.database,
|
|
45
|
+
missing: allExpected,
|
|
46
|
+
extra: [],
|
|
47
|
+
kindMismatches: [],
|
|
48
|
+
objectDrift: [],
|
|
49
|
+
tableDrift: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
21
54
|
const expectedObjects = snapshot.definitions
|
|
22
55
|
.filter((def) => {
|
|
23
56
|
if (!selectedTables)
|
|
@@ -52,6 +85,7 @@ export async function buildDriftPayload(config, metaDir, snapshot, scope) {
|
|
|
52
85
|
})
|
|
53
86
|
.filter((item) => item !== null)
|
|
54
87
|
.sort((a, b) => a.table.localeCompare(b.table));
|
|
88
|
+
debug('drift', `comparison: missing=${missing.length}, extra=${extra.length}, kindMismatches=${kindMismatches.length}, objectDrift=${objectDrift.length}, tableDrift=${tableDrift.length}`);
|
|
55
89
|
const drifted = missing.length > 0 ||
|
|
56
90
|
extra.length > 0 ||
|
|
57
91
|
kindMismatches.length > 0 ||
|
|
@@ -70,8 +104,8 @@ export async function buildDriftPayload(config, metaDir, snapshot, scope) {
|
|
|
70
104
|
tableDrift,
|
|
71
105
|
};
|
|
72
106
|
}
|
|
73
|
-
async function cmdDrift(
|
|
74
|
-
const { flags, config, dirs } =
|
|
107
|
+
async function cmdDrift(runCtx) {
|
|
108
|
+
const { flags, config, dirs, ctx } = runCtx;
|
|
75
109
|
const f = typedFlags(flags, GLOBAL_FLAGS);
|
|
76
110
|
const tableSelector = f['--table'];
|
|
77
111
|
const jsonMode = f['--json'] === true;
|
|
@@ -104,11 +138,18 @@ async function cmdDrift(ctx) {
|
|
|
104
138
|
console.log(`No tables matched selector "${scope.selector ?? ''}". Drift check is a no-op.`);
|
|
105
139
|
return;
|
|
106
140
|
}
|
|
107
|
-
|
|
141
|
+
if (!ctx.hasExecutor) {
|
|
142
|
+
throw new Error('clickhouse config is required for drift checks');
|
|
143
|
+
}
|
|
144
|
+
const payload = await buildDriftPayload(config, metaDir, snapshot, scope, ctx.executor);
|
|
108
145
|
if (jsonMode) {
|
|
109
146
|
emitJson('drift', payload);
|
|
110
147
|
return;
|
|
111
148
|
}
|
|
149
|
+
if (payload.databaseMissing) {
|
|
150
|
+
console.log(`\u26A0 Database "${payload.database ?? ''}" does not exist on the target server.`);
|
|
151
|
+
console.log(' It will be created when you run: chkit migrate --apply\n');
|
|
152
|
+
}
|
|
112
153
|
console.log(`Expected objects: ${payload.expectedCount}`);
|
|
113
154
|
console.log(`Actual objects: ${payload.actualCount}`);
|
|
114
155
|
console.log(`Drifted: ${payload.drifted ? 'yes' : 'no'}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../../../src/bin/commands/drift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../../../src/bin/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,CAAA;YAC7D,IAAI,IAAI,CAAC,kBAAkB;gBAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;YACrE,IAAI,IAAI,CAAC,eAAe;gBAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;YAC/D,IAAI,IAAI,CAAC,iBAAiB;gBAAE,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;YACnE,IAAI,IAAI,CAAC,mBAAmB;gBAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;YACvE,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACpE,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/generate.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,KAAK,UAAU,EAA0B,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/generate.ts"],"names":[],"mappings":"AAIA,OAAO,EAA2B,KAAK,UAAU,EAA0B,MAAM,kBAAkB,CAAA;AA2CnG,eAAO,MAAM,eAAe,EAAE,UAK7B,CAAA"}
|
|
@@ -8,6 +8,7 @@ import { buildScopedSnapshotDefinitions, filterPlanByTableScope, resolveTableSco
|
|
|
8
8
|
import { applyExplicitTableRenames, applySelectedRenameSuggestions, assertCliColumnMappingsResolvable, buildExplicitColumnRenameSuggestions, } from './generate/plan-pipeline.js';
|
|
9
9
|
import { assertCliTableMappingsResolvable, assertNoConflictingColumnMappings, assertNoConflictingTableMappings, collectSchemaRenameMappings, mergeColumnMappings, mergeTableMappings, parseRenameColumnMappings, parseRenameTableMappings, remapOldDefinitionsForTableRenames, resolveActiveTableMappings, } from './generate/rename-mappings.js';
|
|
10
10
|
import { emitGenerateApplyOutput, emitGeneratePlanOutput } from './generate/output.js';
|
|
11
|
+
import { debug } from '../debug.js';
|
|
11
12
|
const GENERATE_FLAGS = defineFlags([
|
|
12
13
|
{ name: '--name', type: 'string', description: 'Migration name', placeholder: '<name>' },
|
|
13
14
|
{ name: '--migration-id', type: 'string', description: 'Deterministic migration file prefix', placeholder: '<id>' },
|
|
@@ -29,6 +30,7 @@ async function cmdGenerate(ctx) {
|
|
|
29
30
|
const tableSelector = f['--table'];
|
|
30
31
|
const planMode = f['--dryrun'] === true;
|
|
31
32
|
const jsonMode = f['--json'] === true;
|
|
33
|
+
debug('generate', `flags: name=${migrationName ?? '(auto)'}, dryrun=${planMode}, json=${jsonMode}`);
|
|
32
34
|
await pluginRuntime.runOnConfigLoaded({
|
|
33
35
|
command: 'generate',
|
|
34
36
|
config,
|
|
@@ -79,6 +81,7 @@ async function cmdGenerate(ctx) {
|
|
|
79
81
|
assertCliTableMappingsResolvable(cliTableMappings, previousDefinitions, definitions);
|
|
80
82
|
const activeTableMappings = resolveActiveTableMappings(previousDefinitions, definitions, tableMappings);
|
|
81
83
|
const remappedPreviousDefinitions = remapOldDefinitionsForTableRenames(previousDefinitions, activeTableMappings);
|
|
84
|
+
debug('generate', `previous snapshot: ${previousDefinitions.length} definitions, current: ${definitions.length} definitions`);
|
|
82
85
|
let plan;
|
|
83
86
|
try {
|
|
84
87
|
plan = planDiff(remappedPreviousDefinitions, definitions);
|
|
@@ -124,6 +127,7 @@ async function cmdGenerate(ctx) {
|
|
|
124
127
|
renameMappings: activeTableMappings,
|
|
125
128
|
})
|
|
126
129
|
: definitions;
|
|
130
|
+
debug('generate', `plan: ${plan.operations.length} operations — writing artifacts`);
|
|
127
131
|
const result = await generateArtifacts({
|
|
128
132
|
definitions: artifactDefinitions,
|
|
129
133
|
migrationsDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/bin/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,WAAW,EAAE,UAAU,EAA2C,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,YAAY,GACb,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,8BAA8B,EAC9B,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,iCAAiC,EACjC,oCAAoC,GACrC,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EACjC,gCAAgC,EAChC,2BAA2B,EAC3B,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,kCAAkC,EAClC,0BAA0B,GAC3B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/bin/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,WAAW,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EAAE,mBAAmB;QAChC,aAAa;QACb,OAAO;QACP,aAAa;QACb,WAAW;QACX,IAAI;QACJ,UAAU,EAAE,WAAW;KACxB,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;IACrG,MAAM,oBAAoB,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;IAClG,IAAI,aAAa,IAAI,oBAAoB,EAAE,CAAC;QAC1C,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE;YACjF,MAAM;YACN,UAAU;YACV,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,aAAa;YACzB,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,EAAE;YACT,KAAK,KAAI,CAAC;SACX,CAAC,CAAA;QACF,IAAI,eAAe,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,kEAAkE,eAAe,GAAG,CAAC,CAAA;QACvG,CAAC;IACH,CAAC;IAED,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;AACrF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/migrate.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,UAAU,EAA0B,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/migrate.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,UAAU,EAA0B,MAAM,kBAAkB,CAAA;AA4BnG,eAAO,MAAM,cAAc,EAAE,UAK5B,CAAA"}
|
|
@@ -3,12 +3,14 @@ import { join } from 'node:path';
|
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { defineFlags, typedFlags } from '../../plugins.js';
|
|
6
|
+
import { waitForDDLPropagation } from '@chkit/clickhouse';
|
|
6
7
|
import { GLOBAL_FLAGS } from '../global-flags.js';
|
|
7
8
|
import { emitJson } from '../json-output.js';
|
|
8
|
-
import {
|
|
9
|
+
import { createJournalStore } from '../journal-store.js';
|
|
9
10
|
import { checksumSQL, findChecksumMismatches, listMigrations, readSnapshot, } from '../migration-store.js';
|
|
10
11
|
import { collectDestructiveOperationMarkers, extractExecutableStatements, extractMigrationOperationSummaries, migrationContainsDangerOperation, } from '../safety-markers.js';
|
|
11
12
|
import { databaseKeyFromOperationKey, resolveTableScope, tableKeyFromOperationKey, tableKeysFromDefinitions } from '../table-scope.js';
|
|
13
|
+
import { debug } from '../debug.js';
|
|
12
14
|
const MIGRATE_FLAGS = defineFlags([
|
|
13
15
|
{ name: '--apply', type: 'boolean', description: 'Apply pending migrations on ClickHouse (no prompt)' },
|
|
14
16
|
{ name: '--execute', type: 'boolean', description: 'Alias for --apply' },
|
|
@@ -68,203 +70,219 @@ async function filterPendingByScope(migrationsDir, pending, selectedTables) {
|
|
|
68
70
|
}
|
|
69
71
|
return inScope;
|
|
70
72
|
}
|
|
71
|
-
async function cmdMigrate(
|
|
72
|
-
const { flags, config, configPath, dirs, pluginRuntime } =
|
|
73
|
+
async function cmdMigrate(runCtx) {
|
|
74
|
+
const { flags, config, configPath, dirs, pluginRuntime, ctx } = runCtx;
|
|
73
75
|
const f = typedFlags(flags, [...GLOBAL_FLAGS, ...MIGRATE_FLAGS]);
|
|
74
76
|
const executeRequested = f['--apply'] === true || f['--execute'] === true;
|
|
75
77
|
const allowDestructive = f['--allow-destructive'] === true;
|
|
76
78
|
const tableSelector = f['--table'];
|
|
77
79
|
const jsonMode = f['--json'] === true;
|
|
78
80
|
const { migrationsDir, metaDir } = dirs;
|
|
79
|
-
|
|
81
|
+
debug('migrate', `flags: execute=${executeRequested}, allowDestructive=${allowDestructive}, json=${jsonMode}`);
|
|
82
|
+
if (!ctx.hasExecutor) {
|
|
80
83
|
throw new Error('clickhouse config is required for migrate (journal is stored in ClickHouse)');
|
|
81
84
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
error: 'Checksum mismatch detected on applied migrations',
|
|
104
|
-
checksumMismatches,
|
|
105
|
-
});
|
|
106
|
-
process.exitCode = 1;
|
|
107
|
-
return;
|
|
85
|
+
const db = ctx.executor;
|
|
86
|
+
{
|
|
87
|
+
const journalStore = createJournalStore(db);
|
|
88
|
+
const snapshot = await readSnapshot(metaDir);
|
|
89
|
+
const tableScope = resolveTableScope(tableSelector, tableKeysFromDefinitions(snapshot?.definitions ?? []));
|
|
90
|
+
await pluginRuntime.runOnConfigLoaded({
|
|
91
|
+
command: 'migrate',
|
|
92
|
+
config,
|
|
93
|
+
configPath,
|
|
94
|
+
tableScope,
|
|
95
|
+
flags,
|
|
96
|
+
});
|
|
97
|
+
await mkdir(migrationsDir, { recursive: true });
|
|
98
|
+
const files = await listMigrations(migrationsDir);
|
|
99
|
+
const journal = await journalStore.readJournal();
|
|
100
|
+
const appliedNames = new Set(journal.applied.map((entry) => entry.name));
|
|
101
|
+
const pendingAll = files.filter((f) => !appliedNames.has(f));
|
|
102
|
+
debug('migrate', `migrations: total=${files.length}, applied=${journal.applied.length}, pending=${pendingAll.length}`);
|
|
103
|
+
const checksumMismatches = await findChecksumMismatches(migrationsDir, journal);
|
|
104
|
+
if (checksumMismatches.length > 0) {
|
|
105
|
+
debug('migrate', `checksum mismatches: ${checksumMismatches.map((m) => m.name).join(', ')}`);
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
if (checksumMismatches.length > 0) {
|
|
108
|
+
if (jsonMode) {
|
|
109
|
+
emitJson('migrate', {
|
|
110
|
+
mode: executeRequested ? 'execute' : 'plan',
|
|
111
|
+
scope: tableScope,
|
|
112
|
+
error: 'Checksum mismatch detected on applied migrations',
|
|
113
|
+
checksumMismatches,
|
|
114
|
+
});
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
throw new Error(`Checksum mismatch detected on applied migrations: ${checksumMismatches
|
|
119
|
+
.map((item) => item.name)
|
|
120
|
+
.join(', ')}`);
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
if (tableScope.enabled && tableScope.matchCount === 0) {
|
|
123
|
+
if (jsonMode) {
|
|
124
|
+
emitJson('migrate', {
|
|
125
|
+
mode: executeRequested ? 'execute' : 'plan',
|
|
126
|
+
scope: tableScope,
|
|
127
|
+
pending: [],
|
|
128
|
+
applied: [],
|
|
129
|
+
warning: `No tables matched selector "${tableScope.selector ?? ''}".`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.log(`No tables matched selector "${tableScope.selector ?? ''}". No migrations selected.`);
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
125
136
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
const pending = tableScope.enabled
|
|
138
|
+
? await filterPendingByScope(migrationsDir, pendingAll, new Set(tableScope.matchedTables))
|
|
139
|
+
: pendingAll;
|
|
140
|
+
if (pending.length === 0) {
|
|
141
|
+
if (jsonMode) {
|
|
142
|
+
emitJson('migrate', {
|
|
143
|
+
mode: executeRequested ? 'execute' : 'plan',
|
|
144
|
+
scope: tableScope,
|
|
145
|
+
pending: [],
|
|
146
|
+
applied: [],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.log('No pending migrations.');
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
139
153
|
}
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
const planned = {
|
|
155
|
+
mode: executeRequested ? 'execute' : 'plan',
|
|
156
|
+
scope: tableScope,
|
|
157
|
+
pending,
|
|
158
|
+
};
|
|
159
|
+
if (jsonMode && !executeRequested) {
|
|
160
|
+
emitJson('migrate', planned);
|
|
161
|
+
return;
|
|
142
162
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (!jsonMode) {
|
|
155
|
-
if (tableScope.enabled) {
|
|
156
|
-
console.log(`Table scope: ${tableScope.selector ?? ''} (${tableScope.matchCount} matched)`);
|
|
157
|
-
for (const table of tableScope.matchedTables)
|
|
158
|
-
console.log(`- ${table}`);
|
|
163
|
+
if (!jsonMode) {
|
|
164
|
+
if (tableScope.enabled) {
|
|
165
|
+
console.log(`Table scope: ${tableScope.selector ?? ''} (${tableScope.matchCount} matched)`);
|
|
166
|
+
for (const table of tableScope.matchedTables)
|
|
167
|
+
console.log(`- ${table}`);
|
|
168
|
+
}
|
|
169
|
+
console.log(`Pending migrations: ${pending.length}`);
|
|
170
|
+
for (const file of pending)
|
|
171
|
+
console.log(`- ${file}`);
|
|
159
172
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
let shouldExecute = executeRequested;
|
|
174
|
+
if (!shouldExecute) {
|
|
175
|
+
if (isBackgroundOrCI() || jsonMode) {
|
|
176
|
+
if (!jsonMode) {
|
|
177
|
+
console.log('\nPlan only. Re-run with --apply to apply and journal these migrations.');
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
182
|
+
try {
|
|
183
|
+
console.log('');
|
|
184
|
+
console.log('Type "yes" to continue. Any other input cancels.');
|
|
185
|
+
const response = await rl.question('Apply pending migrations now? [no/yes]: ');
|
|
186
|
+
shouldExecute = response.trim().toLowerCase() === 'yes';
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
rl.close();
|
|
190
|
+
}
|
|
191
|
+
if (!shouldExecute) {
|
|
192
|
+
console.log('Migration apply cancelled by user.');
|
|
193
|
+
return;
|
|
169
194
|
}
|
|
170
|
-
return;
|
|
171
195
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
196
|
+
const destructiveMigrations = [];
|
|
197
|
+
const destructiveOperations = [];
|
|
198
|
+
for (const file of pending) {
|
|
199
|
+
const sql = await readFile(join(migrationsDir, file), 'utf8');
|
|
200
|
+
if (migrationContainsDangerOperation(sql)) {
|
|
201
|
+
destructiveMigrations.push(file);
|
|
202
|
+
destructiveOperations.push(...collectDestructiveOperationMarkers(file, sql));
|
|
203
|
+
}
|
|
178
204
|
}
|
|
179
|
-
|
|
180
|
-
|
|
205
|
+
let destructiveAllowed = allowDestructive || config.safety?.allowDestructive === true;
|
|
206
|
+
if (destructiveMigrations.length > 0 && !destructiveAllowed) {
|
|
207
|
+
const error = 'Blocked destructive migration execution. Re-run with --allow-destructive or set safety.allowDestructive=true after review.';
|
|
208
|
+
if (jsonMode) {
|
|
209
|
+
emitJson('migrate', {
|
|
210
|
+
mode: 'execute',
|
|
211
|
+
scope: tableScope,
|
|
212
|
+
error,
|
|
213
|
+
destructiveMigrations,
|
|
214
|
+
destructiveOperations,
|
|
215
|
+
});
|
|
216
|
+
process.exitCode = 3;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (isBackgroundOrCI()) {
|
|
220
|
+
printDestructiveOperationDetails(destructiveOperations);
|
|
221
|
+
throw new Error(`${error}\nDestructive migrations: ${destructiveMigrations.join(', ')}\n` +
|
|
222
|
+
'Non-interactive run detected. Pass --allow-destructive to proceed.');
|
|
223
|
+
}
|
|
224
|
+
const confirmed = await confirmDestructiveExecution(destructiveOperations);
|
|
225
|
+
if (!confirmed) {
|
|
226
|
+
throw new Error(`Destructive migration cancelled by user.\nDestructive migrations: ${destructiveMigrations.join(', ')}`);
|
|
227
|
+
}
|
|
228
|
+
destructiveAllowed = true;
|
|
181
229
|
}
|
|
182
|
-
if (!
|
|
183
|
-
|
|
184
|
-
return;
|
|
230
|
+
if (destructiveMigrations.length > 0 && !destructiveAllowed) {
|
|
231
|
+
throw new Error('Blocked destructive migration execution.');
|
|
185
232
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
233
|
+
const appliedNow = [];
|
|
234
|
+
for (const file of pending) {
|
|
235
|
+
debug('migrate', `applying ${file}`);
|
|
236
|
+
const fullPath = join(migrationsDir, file);
|
|
237
|
+
const sql = await readFile(fullPath, 'utf8');
|
|
238
|
+
const parsedStatements = extractExecutableStatements(sql);
|
|
239
|
+
const operationSummaries = extractMigrationOperationSummaries(sql);
|
|
240
|
+
debug('migrate', `${file}: ${parsedStatements.length} statements, ${operationSummaries.length} operations`);
|
|
241
|
+
const statements = await pluginRuntime.runOnBeforeApply({
|
|
242
|
+
command: 'migrate',
|
|
243
|
+
config,
|
|
244
|
+
tableScope,
|
|
245
|
+
flags,
|
|
246
|
+
migration: file,
|
|
247
|
+
sql,
|
|
248
|
+
statements: parsedStatements,
|
|
249
|
+
});
|
|
250
|
+
for (let i = 0; i < statements.length; i++) {
|
|
251
|
+
const statement = statements[i];
|
|
252
|
+
await db.command(statement);
|
|
253
|
+
const operation = operationSummaries[i];
|
|
254
|
+
if (operation) {
|
|
255
|
+
await waitForDDLPropagation(db, operation.type, operation.key);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const entry = {
|
|
259
|
+
name: file,
|
|
260
|
+
appliedAt: new Date().toISOString().replace('Z', ''),
|
|
261
|
+
checksum: checksumSQL(sql),
|
|
262
|
+
};
|
|
263
|
+
appliedNow.push(entry);
|
|
264
|
+
await journalStore.appendEntry(entry);
|
|
265
|
+
await pluginRuntime.runOnAfterApply({
|
|
266
|
+
command: 'migrate',
|
|
267
|
+
config,
|
|
268
|
+
tableScope,
|
|
269
|
+
flags,
|
|
270
|
+
migration: file,
|
|
271
|
+
statements,
|
|
272
|
+
appliedAt: entry.appliedAt,
|
|
273
|
+
});
|
|
274
|
+
if (!jsonMode)
|
|
275
|
+
console.log(`Applied: ${file}`);
|
|
194
276
|
}
|
|
195
|
-
}
|
|
196
|
-
let destructiveAllowed = allowDestructive || config.safety?.allowDestructive === true;
|
|
197
|
-
if (destructiveMigrations.length > 0 && !destructiveAllowed) {
|
|
198
|
-
const error = 'Blocked destructive migration execution. Re-run with --allow-destructive or set safety.allowDestructive=true after review.';
|
|
199
277
|
if (jsonMode) {
|
|
200
278
|
emitJson('migrate', {
|
|
201
279
|
mode: 'execute',
|
|
202
280
|
scope: tableScope,
|
|
203
|
-
|
|
204
|
-
destructiveMigrations,
|
|
205
|
-
destructiveOperations,
|
|
281
|
+
applied: appliedNow,
|
|
206
282
|
});
|
|
207
|
-
process.exitCode = 3;
|
|
208
283
|
return;
|
|
209
284
|
}
|
|
210
|
-
|
|
211
|
-
printDestructiveOperationDetails(destructiveOperations);
|
|
212
|
-
throw new Error(`${error}\nDestructive migrations: ${destructiveMigrations.join(', ')}\n` +
|
|
213
|
-
'Non-interactive run detected. Pass --allow-destructive to proceed.');
|
|
214
|
-
}
|
|
215
|
-
const confirmed = await confirmDestructiveExecution(destructiveOperations);
|
|
216
|
-
if (!confirmed) {
|
|
217
|
-
throw new Error(`Destructive migration cancelled by user.\nDestructive migrations: ${destructiveMigrations.join(', ')}`);
|
|
218
|
-
}
|
|
219
|
-
destructiveAllowed = true;
|
|
220
|
-
}
|
|
221
|
-
if (destructiveMigrations.length > 0 && !destructiveAllowed) {
|
|
222
|
-
throw new Error('Blocked destructive migration execution.');
|
|
223
|
-
}
|
|
224
|
-
const appliedNow = [];
|
|
225
|
-
for (const file of pending) {
|
|
226
|
-
const fullPath = join(migrationsDir, file);
|
|
227
|
-
const sql = await readFile(fullPath, 'utf8');
|
|
228
|
-
const parsedStatements = extractExecutableStatements(sql);
|
|
229
|
-
const statements = await pluginRuntime.runOnBeforeApply({
|
|
230
|
-
command: 'migrate',
|
|
231
|
-
config,
|
|
232
|
-
tableScope,
|
|
233
|
-
flags,
|
|
234
|
-
migration: file,
|
|
235
|
-
sql,
|
|
236
|
-
statements: parsedStatements,
|
|
237
|
-
});
|
|
238
|
-
for (const statement of statements) {
|
|
239
|
-
await db.execute(statement);
|
|
240
|
-
}
|
|
241
|
-
const entry = {
|
|
242
|
-
name: file,
|
|
243
|
-
appliedAt: new Date().toISOString().replace('Z', ''),
|
|
244
|
-
checksum: checksumSQL(sql),
|
|
245
|
-
};
|
|
246
|
-
appliedNow.push(entry);
|
|
247
|
-
await journalStore.appendEntry(entry);
|
|
248
|
-
await pluginRuntime.runOnAfterApply({
|
|
249
|
-
command: 'migrate',
|
|
250
|
-
config,
|
|
251
|
-
tableScope,
|
|
252
|
-
flags,
|
|
253
|
-
migration: file,
|
|
254
|
-
statements,
|
|
255
|
-
appliedAt: entry.appliedAt,
|
|
256
|
-
});
|
|
257
|
-
if (!jsonMode)
|
|
258
|
-
console.log(`Applied: ${file}`);
|
|
259
|
-
}
|
|
260
|
-
if (jsonMode) {
|
|
261
|
-
emitJson('migrate', {
|
|
262
|
-
mode: 'execute',
|
|
263
|
-
scope: tableScope,
|
|
264
|
-
applied: appliedNow,
|
|
265
|
-
});
|
|
266
|
-
return;
|
|
285
|
+
console.log(`\nMigrations recorded in ClickHouse _chkit_migrations table.`);
|
|
267
286
|
}
|
|
268
|
-
console.log(`\nMigrations recorded in ClickHouse _chkit_migrations table.`);
|
|
269
287
|
}
|
|
270
288
|
//# sourceMappingURL=migrate.js.map
|