@prisma-next/cli 0.3.0-dev.15 → 0.3.0-dev.162
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 +201 -0
- package/README.md +381 -128
- package/dist/cli-errors-BDCYR5ap.mjs +4 -0
- package/dist/cli-errors-Dzs7Oxz7.d.mts +3 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2346
- package/dist/cli.mjs +245 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-yYtotiSX.mjs +1063 -0
- package/dist/client-yYtotiSX.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +8 -0
- package/dist/commands/contract-infer.d.mts +7 -0
- package/dist/commands/contract-infer.d.mts.map +1 -0
- package/dist/commands/contract-infer.mjs +9 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +125 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-schema.d.mts +7 -0
- package/dist/commands/db-schema.d.mts.map +1 -0
- package/dist/commands/db-schema.mjs +55 -0
- package/dist/commands/db-schema.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +136 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-update.d.mts +7 -0
- package/dist/commands/db-update.d.mts.map +1 -0
- package/dist/commands/db-update.mjs +122 -0
- package/dist/commands/db-update.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +322 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/commands/migration-apply.d.mts +36 -0
- package/dist/commands/migration-apply.d.mts.map +1 -0
- package/dist/commands/migration-apply.mjs +244 -0
- package/dist/commands/migration-apply.mjs.map +1 -0
- package/dist/commands/migration-new.d.mts +8 -0
- package/dist/commands/migration-new.d.mts.map +1 -0
- package/dist/commands/migration-new.mjs +151 -0
- package/dist/commands/migration-new.mjs.map +1 -0
- package/dist/commands/migration-plan.d.mts +47 -0
- package/dist/commands/migration-plan.d.mts.map +1 -0
- package/dist/commands/migration-plan.mjs +312 -0
- package/dist/commands/migration-plan.mjs.map +1 -0
- package/dist/commands/migration-ref.d.mts +43 -0
- package/dist/commands/migration-ref.d.mts.map +1 -0
- package/dist/commands/migration-ref.mjs +194 -0
- package/dist/commands/migration-ref.mjs.map +1 -0
- package/dist/commands/migration-show.d.mts +28 -0
- package/dist/commands/migration-show.d.mts.map +1 -0
- package/dist/commands/migration-show.mjs +139 -0
- package/dist/commands/migration-show.mjs.map +1 -0
- package/dist/commands/migration-status.d.mts +86 -0
- package/dist/commands/migration-status.d.mts.map +1 -0
- package/dist/commands/migration-status.mjs +8 -0
- package/dist/commands/migration-verify.d.mts +16 -0
- package/dist/commands/migration-verify.d.mts.map +1 -0
- package/dist/commands/migration-verify.mjs +109 -0
- package/dist/commands/migration-verify.mjs.map +1 -0
- package/dist/config-loader-C4VXKl8f.mjs +43 -0
- package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/contract-emit-Bk_eEDKu.mjs +187 -0
- package/dist/contract-emit-Bk_eEDKu.mjs.map +1 -0
- package/dist/contract-infer-suMDmFSG.mjs +89 -0
- package/dist/contract-infer-suMDmFSG.mjs.map +1 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +624 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +109 -0
- package/dist/exports/control-api.mjs.map +1 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +141 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/extract-operation-statements-BVlb3jxp.mjs +13 -0
- package/dist/extract-operation-statements-BVlb3jxp.mjs.map +1 -0
- package/dist/extract-sql-ddl-6EVSOThm.mjs +26 -0
- package/dist/extract-sql-ddl-6EVSOThm.mjs.map +1 -0
- package/dist/framework-components-BAsliT4V.mjs +59 -0
- package/dist/framework-components-BAsliT4V.mjs.map +1 -0
- package/dist/inspect-live-schema-HMutsJYh.mjs +91 -0
- package/dist/inspect-live-schema-HMutsJYh.mjs.map +1 -0
- package/dist/migration-command-scaffold-Dg7CKKCg.mjs +105 -0
- package/dist/migration-command-scaffold-Dg7CKKCg.mjs.map +1 -0
- package/dist/migration-status-BqfVmC0w.mjs +1582 -0
- package/dist/migration-status-BqfVmC0w.mjs.map +1 -0
- package/dist/migrations-Bv8oeiY_.mjs +173 -0
- package/dist/migrations-Bv8oeiY_.mjs.map +1 -0
- package/dist/progress-adapter-D4x8SbJa.mjs +43 -0
- package/dist/progress-adapter-D4x8SbJa.mjs.map +1 -0
- package/dist/terminal-ui-N5tR-ob5.mjs +967 -0
- package/dist/terminal-ui-N5tR-ob5.mjs.map +1 -0
- package/dist/verify-WARh5TjK.mjs +385 -0
- package/dist/verify-WARh5TjK.mjs.map +1 -0
- package/package.json +87 -41
- package/src/cli.ts +113 -58
- package/src/commands/contract-emit.ts +237 -144
- package/src/commands/contract-infer-paths.ts +32 -0
- package/src/commands/contract-infer.ts +143 -0
- package/src/commands/db-init.ts +211 -426
- package/src/commands/db-schema.ts +77 -0
- package/src/commands/db-sign.ts +208 -229
- package/src/commands/db-update.ts +236 -0
- package/src/commands/db-verify.ts +504 -184
- package/src/commands/inspect-live-schema.ts +170 -0
- package/src/commands/migration-apply.ts +427 -0
- package/src/commands/migration-new.ts +260 -0
- package/src/commands/migration-plan.ts +519 -0
- package/src/commands/migration-ref.ts +305 -0
- package/src/commands/migration-show.ts +246 -0
- package/src/commands/migration-status.ts +864 -0
- package/src/commands/migration-verify.ts +180 -0
- package/src/config-loader.ts +13 -3
- package/src/control-api/client.ts +428 -46
- package/src/control-api/contract-enrichment.ts +119 -0
- package/src/control-api/errors.ts +9 -0
- package/src/control-api/operations/contract-emit.ts +174 -0
- package/src/control-api/operations/db-init.ts +144 -26
- package/src/control-api/operations/db-update.ts +220 -0
- package/src/control-api/operations/extract-operation-statements.ts +14 -0
- package/src/control-api/operations/extract-sql-ddl.ts +47 -0
- package/src/control-api/operations/migration-apply.ts +191 -0
- package/src/control-api/operations/migration-helpers.ts +49 -0
- package/src/control-api/types.ts +450 -18
- package/src/exports/config-types.ts +4 -3
- package/src/exports/control-api.ts +24 -2
- package/src/load-ts-contract.ts +30 -19
- package/src/utils/cli-errors.ts +14 -8
- package/src/utils/command-helpers.ts +302 -3
- package/src/utils/formatters/emit.ts +67 -0
- package/src/utils/formatters/errors.ts +82 -0
- package/src/utils/formatters/graph-migration-mapper.ts +240 -0
- package/src/utils/formatters/graph-render.ts +1323 -0
- package/src/utils/formatters/graph-types.ts +120 -0
- package/src/utils/formatters/help.ts +380 -0
- package/src/utils/formatters/helpers.ts +28 -0
- package/src/utils/formatters/migrations.ts +346 -0
- package/src/utils/formatters/styled.ts +212 -0
- package/src/utils/formatters/verify.ts +621 -0
- package/src/utils/framework-components.ts +13 -10
- package/src/utils/global-flags.ts +41 -23
- package/src/utils/migration-command-scaffold.ts +184 -0
- package/src/utils/migration-types.ts +12 -0
- package/src/utils/progress-adapter.ts +75 -0
- package/src/utils/result-handler.ts +12 -13
- package/src/utils/shutdown.ts +92 -0
- package/src/utils/suggest-command.ts +31 -0
- package/src/utils/terminal-ui.ts +276 -0
- package/dist/chunk-6EPKRATC.js +0 -91
- package/dist/chunk-6EPKRATC.js.map +0 -1
- package/dist/chunk-DIJPT5TZ.js +0 -967
- package/dist/chunk-DIJPT5TZ.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-MG7PBERL.js +0 -131
- package/dist/chunk-MG7PBERL.js.map +0 -1
- package/dist/chunk-VI2YETW7.js +0 -38
- package/dist/chunk-VI2YETW7.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -10
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -339
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -183
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -161
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -196
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -170
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/control-api/client.d.ts +0 -13
- package/dist/control-api/client.d.ts.map +0 -1
- package/dist/control-api/operations/db-init.d.ts +0 -27
- package/dist/control-api/operations/db-init.d.ts.map +0 -1
- package/dist/control-api/types.d.ts +0 -203
- package/dist/control-api/types.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/control-api.d.ts +0 -13
- package/dist/exports/control-api.d.ts.map +0 -1
- package/dist/exports/control-api.js +0 -240
- package/dist/exports/control-api.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -176
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/action.d.ts +0 -16
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -70
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/dist/utils/spinner.d.ts +0 -29
- package/dist/utils/spinner.d.ts.map +0 -1
- package/src/commands/db-introspect.ts +0 -254
- package/src/commands/db-schema-verify.ts +0 -231
- package/src/utils/action.ts +0 -43
- package/src/utils/output.ts +0 -1471
- package/src/utils/spinner.ts +0 -67
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
2
|
+
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { ContractValidationError } from '../control-api/errors';
|
|
5
|
+
import type { DbUpdateFailure } from '../control-api/types';
|
|
6
|
+
import {
|
|
7
|
+
CliStructuredError,
|
|
8
|
+
ERROR_CODE_DESTRUCTIVE_CHANGES,
|
|
9
|
+
errorContractValidationFailed,
|
|
10
|
+
errorDestructiveChanges,
|
|
11
|
+
errorMigrationPlanningFailed,
|
|
12
|
+
errorRunnerFailed,
|
|
13
|
+
errorUnexpected,
|
|
14
|
+
} from '../utils/cli-errors';
|
|
15
|
+
import type { MigrationCommandOptions } from '../utils/command-helpers';
|
|
16
|
+
import {
|
|
17
|
+
sanitizeErrorMessage,
|
|
18
|
+
setCommandDescriptions,
|
|
19
|
+
setCommandExamples,
|
|
20
|
+
} from '../utils/command-helpers';
|
|
21
|
+
import {
|
|
22
|
+
formatMigrationApplyOutput,
|
|
23
|
+
formatMigrationJson,
|
|
24
|
+
formatMigrationPlanOutput,
|
|
25
|
+
type MigrationCommandResult,
|
|
26
|
+
} from '../utils/formatters/migrations';
|
|
27
|
+
import { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';
|
|
28
|
+
import {
|
|
29
|
+
addMigrationCommandOptions,
|
|
30
|
+
prepareMigrationContext,
|
|
31
|
+
} from '../utils/migration-command-scaffold';
|
|
32
|
+
import { handleResult } from '../utils/result-handler';
|
|
33
|
+
import { TerminalUI } from '../utils/terminal-ui';
|
|
34
|
+
|
|
35
|
+
type DbUpdateOptions = MigrationCommandOptions;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.
|
|
39
|
+
*/
|
|
40
|
+
function mapDbUpdateFailure(failure: DbUpdateFailure): CliStructuredError {
|
|
41
|
+
if (failure.code === 'PLANNING_FAILED') {
|
|
42
|
+
return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (failure.code === 'RUNNER_FAILED') {
|
|
46
|
+
return errorRunnerFailed(failure.summary, {
|
|
47
|
+
why: failure.why ?? 'Migration runner failed',
|
|
48
|
+
fix: 'Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`',
|
|
49
|
+
...ifDefined('meta', failure.meta),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (failure.code === 'DESTRUCTIVE_CHANGES') {
|
|
54
|
+
return errorDestructiveChanges(failure.summary, {
|
|
55
|
+
...ifDefined('why', failure.why),
|
|
56
|
+
fix: 'Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first',
|
|
57
|
+
...ifDefined('meta', failure.meta),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const exhaustive: never = failure.code;
|
|
62
|
+
throw new Error(`Unhandled DbUpdateFailure code: ${exhaustive}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Executes the db update command and returns a structured Result.
|
|
67
|
+
*/
|
|
68
|
+
async function executeDbUpdateCommand(
|
|
69
|
+
options: DbUpdateOptions,
|
|
70
|
+
flags: GlobalFlags,
|
|
71
|
+
ui: TerminalUI,
|
|
72
|
+
startTime: number,
|
|
73
|
+
): Promise<Result<MigrationCommandResult, CliStructuredError>> {
|
|
74
|
+
// Prepare shared migration context (config, contract, connection, client)
|
|
75
|
+
const ctxResult = await prepareMigrationContext(options, flags, ui, {
|
|
76
|
+
commandName: 'db update',
|
|
77
|
+
description: 'Update your database schema to match your contract',
|
|
78
|
+
url: 'https://pris.ly/db-update',
|
|
79
|
+
});
|
|
80
|
+
if (!ctxResult.ok) {
|
|
81
|
+
return ctxResult;
|
|
82
|
+
}
|
|
83
|
+
const { client, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
// Call dbUpdate with connection and progress callback
|
|
87
|
+
const result = await client.dbUpdate({
|
|
88
|
+
contract: contractJson,
|
|
89
|
+
mode: options.dryRun ? 'plan' : 'apply',
|
|
90
|
+
connection: dbConnection,
|
|
91
|
+
...(flags.yes ? { acceptDataLoss: true } : {}),
|
|
92
|
+
onProgress,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Handle failures by mapping to CLI structured error
|
|
96
|
+
if (!result.ok) {
|
|
97
|
+
return notOk(mapDbUpdateFailure(result.failure));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Convert success result to CLI output format
|
|
101
|
+
const dbUpdateResult: MigrationCommandResult = {
|
|
102
|
+
ok: true,
|
|
103
|
+
mode: result.value.mode,
|
|
104
|
+
plan: {
|
|
105
|
+
targetId: ctxResult.value.config.target.targetId,
|
|
106
|
+
destination: {
|
|
107
|
+
storageHash: result.value.destination.storageHash,
|
|
108
|
+
...ifDefined('profileHash', result.value.destination.profileHash),
|
|
109
|
+
},
|
|
110
|
+
operations: result.value.plan.operations.map((op) => ({
|
|
111
|
+
id: op.id,
|
|
112
|
+
label: op.label,
|
|
113
|
+
operationClass: op.operationClass,
|
|
114
|
+
})),
|
|
115
|
+
...ifDefined('sql', result.value.plan.sql),
|
|
116
|
+
},
|
|
117
|
+
...ifDefined(
|
|
118
|
+
'execution',
|
|
119
|
+
result.value.execution
|
|
120
|
+
? {
|
|
121
|
+
operationsPlanned: result.value.execution.operationsPlanned,
|
|
122
|
+
operationsExecuted: result.value.execution.operationsExecuted,
|
|
123
|
+
}
|
|
124
|
+
: undefined,
|
|
125
|
+
),
|
|
126
|
+
...ifDefined(
|
|
127
|
+
'marker',
|
|
128
|
+
result.value.marker
|
|
129
|
+
? {
|
|
130
|
+
storageHash: result.value.marker.storageHash,
|
|
131
|
+
...ifDefined('profileHash', result.value.marker.profileHash),
|
|
132
|
+
}
|
|
133
|
+
: undefined,
|
|
134
|
+
),
|
|
135
|
+
summary: result.value.summary,
|
|
136
|
+
timings: { total: Date.now() - startTime },
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return ok(dbUpdateResult);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (CliStructuredError.is(error)) {
|
|
142
|
+
return notOk(error);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (error instanceof ContractValidationError) {
|
|
146
|
+
return notOk(
|
|
147
|
+
errorContractValidationFailed(`Contract validation failed: ${error.message}`, {
|
|
148
|
+
where: { path: contractPathAbsolute },
|
|
149
|
+
}),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
154
|
+
const safeMessage = sanitizeErrorMessage(
|
|
155
|
+
rawMessage,
|
|
156
|
+
typeof dbConnection === 'string' ? dbConnection : undefined,
|
|
157
|
+
);
|
|
158
|
+
return notOk(
|
|
159
|
+
errorUnexpected(safeMessage, {
|
|
160
|
+
why: `Unexpected error during db update: ${safeMessage}`,
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
} finally {
|
|
164
|
+
await client.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function createDbUpdateCommand(): Command {
|
|
169
|
+
const command = new Command('update');
|
|
170
|
+
setCommandDescriptions(
|
|
171
|
+
command,
|
|
172
|
+
'Update your database schema to match your contract',
|
|
173
|
+
'Compares your database schema to the emitted contract and applies the necessary\n' +
|
|
174
|
+
'changes. Works on any database, whether or not it has been initialized with `db init`.\n' +
|
|
175
|
+
'Destructive operations prompt for confirmation in interactive mode. Use -y to\n' +
|
|
176
|
+
'auto-accept or --dry-run to preview first.',
|
|
177
|
+
);
|
|
178
|
+
setCommandExamples(command, [
|
|
179
|
+
'prisma-next db update --db $DATABASE_URL',
|
|
180
|
+
'prisma-next db update --db $DATABASE_URL --dry-run',
|
|
181
|
+
]);
|
|
182
|
+
addMigrationCommandOptions(command);
|
|
183
|
+
command.action(async (options: DbUpdateOptions) => {
|
|
184
|
+
const flags = parseGlobalFlags(options);
|
|
185
|
+
const startTime = Date.now();
|
|
186
|
+
|
|
187
|
+
const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });
|
|
188
|
+
|
|
189
|
+
let result = await executeDbUpdateCommand(options, flags, ui, startTime);
|
|
190
|
+
|
|
191
|
+
// Interactive confirmation for destructive operations:
|
|
192
|
+
// When the control API rejects destructive changes, prompt the user instead of failing.
|
|
193
|
+
// In non-interactive mode (CI, piped, --no-interactive, --json), the error is returned as-is.
|
|
194
|
+
if (
|
|
195
|
+
!result.ok &&
|
|
196
|
+
result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES &&
|
|
197
|
+
flags.interactive &&
|
|
198
|
+
!flags.json &&
|
|
199
|
+
!flags.yes
|
|
200
|
+
) {
|
|
201
|
+
const meta = result.failure.meta as
|
|
202
|
+
| { destructiveOperations?: readonly { id: string; label: string }[] }
|
|
203
|
+
| undefined;
|
|
204
|
+
const destructiveOps = meta?.destructiveOperations ?? [];
|
|
205
|
+
|
|
206
|
+
if (destructiveOps.length > 0) {
|
|
207
|
+
ui.warn(
|
|
208
|
+
`${destructiveOps.length} destructive operation(s) that may cause data loss:\n${destructiveOps.map((op) => ` ${ui.yellow('▸')} ${op.label}`).join('\n')}`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const confirmed = await ui.confirm('Apply destructive changes? This cannot be undone.');
|
|
213
|
+
|
|
214
|
+
if (confirmed) {
|
|
215
|
+
result = await executeDbUpdateCommand(options, { ...flags, yes: true }, ui, Date.now());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {
|
|
220
|
+
if (flags.json) {
|
|
221
|
+
ui.output(formatMigrationJson(dbUpdateResult));
|
|
222
|
+
} else {
|
|
223
|
+
const output =
|
|
224
|
+
dbUpdateResult.mode === 'plan'
|
|
225
|
+
? formatMigrationPlanOutput(dbUpdateResult, flags)
|
|
226
|
+
: formatMigrationApplyOutput(dbUpdateResult, flags);
|
|
227
|
+
if (output) {
|
|
228
|
+
ui.log(output);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
process.exit(exitCode);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return command;
|
|
236
|
+
}
|