@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,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `migration new` — scaffolds a migration package with a migration.ts file
|
|
3
|
+
* for manual authoring. The user writes operation descriptors and data
|
|
4
|
+
* transforms; `migration verify` resolves them to ops.json.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
9
|
+
import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
|
|
10
|
+
import { findLatestMigration, reconstructGraph } from '@prisma-next/migration-tools/dag';
|
|
11
|
+
import {
|
|
12
|
+
formatMigrationDirName,
|
|
13
|
+
readMigrationsDir,
|
|
14
|
+
writeMigrationPackage,
|
|
15
|
+
} from '@prisma-next/migration-tools/io';
|
|
16
|
+
import { scaffoldMigrationTs } from '@prisma-next/migration-tools/migration-ts';
|
|
17
|
+
import type { MigrationManifest } from '@prisma-next/migration-tools/types';
|
|
18
|
+
import { isAttested, MigrationToolsError } from '@prisma-next/migration-tools/types';
|
|
19
|
+
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
20
|
+
import { Command } from 'commander';
|
|
21
|
+
import { join, relative, resolve } from 'pathe';
|
|
22
|
+
import { loadConfig } from '../config-loader';
|
|
23
|
+
import { type CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
|
|
24
|
+
import {
|
|
25
|
+
addGlobalOptions,
|
|
26
|
+
resolveMigrationPaths,
|
|
27
|
+
setCommandDescriptions,
|
|
28
|
+
setCommandExamples,
|
|
29
|
+
} from '../utils/command-helpers';
|
|
30
|
+
import { formatStyledHeader } from '../utils/formatters/styled';
|
|
31
|
+
import type { CommonCommandOptions } from '../utils/global-flags';
|
|
32
|
+
import { parseGlobalFlags } from '../utils/global-flags';
|
|
33
|
+
import { handleResult } from '../utils/result-handler';
|
|
34
|
+
import { TerminalUI } from '../utils/terminal-ui';
|
|
35
|
+
|
|
36
|
+
interface MigrationNewOptions extends CommonCommandOptions {
|
|
37
|
+
readonly name?: string;
|
|
38
|
+
readonly from?: string;
|
|
39
|
+
readonly config?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface MigrationNewResult {
|
|
43
|
+
readonly ok: true;
|
|
44
|
+
readonly dir: string;
|
|
45
|
+
readonly from: string;
|
|
46
|
+
readonly to: string;
|
|
47
|
+
readonly summary: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function executeMigrationNewCommand(
|
|
51
|
+
options: MigrationNewOptions,
|
|
52
|
+
): Promise<Result<MigrationNewResult, CliStructuredError>> {
|
|
53
|
+
const config = await loadConfig(options.config);
|
|
54
|
+
const { migrationsDir, migrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
55
|
+
|
|
56
|
+
// Read the emitted contract (destination)
|
|
57
|
+
const contractPath = config.contract?.output ?? 'contract.json';
|
|
58
|
+
const contractPathAbsolute = resolve(
|
|
59
|
+
options.config ? resolve(options.config, '..') : process.cwd(),
|
|
60
|
+
contractPath,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
let contractJsonContent: string;
|
|
64
|
+
try {
|
|
65
|
+
contractJsonContent = readFileSync(contractPathAbsolute, 'utf-8');
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {
|
|
68
|
+
return notOk(
|
|
69
|
+
errorRuntime(`Contract file not found at ${contractPathAbsolute}`, {
|
|
70
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
71
|
+
fix: 'Run `prisma-next contract emit` first to generate the contract',
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let toContractJson: Contract;
|
|
79
|
+
try {
|
|
80
|
+
toContractJson = JSON.parse(contractJsonContent) as Contract;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return notOk(
|
|
83
|
+
errorRuntime('Contract JSON is invalid', {
|
|
84
|
+
why: `Failed to parse ${contractPathAbsolute}: ${error instanceof Error ? error.message : String(error)}`,
|
|
85
|
+
fix: 'Run `prisma-next contract emit` to regenerate the contract',
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const toStorageHash = (
|
|
91
|
+
(toContractJson as unknown as Record<string, unknown>)['storage'] as
|
|
92
|
+
| Record<string, unknown>
|
|
93
|
+
| undefined
|
|
94
|
+
)?.['storageHash'] as string | undefined;
|
|
95
|
+
if (!toStorageHash) {
|
|
96
|
+
return notOk(
|
|
97
|
+
errorRuntime('Contract is missing storageHash', {
|
|
98
|
+
why: `Contract at ${contractPathAbsolute} has no storageHash`,
|
|
99
|
+
fix: 'Run `prisma-next contract emit` to regenerate the contract',
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Determine "from" hash
|
|
105
|
+
let fromContract: Contract | null = null;
|
|
106
|
+
let fromHash: string = EMPTY_CONTRACT_HASH;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const packages = await readMigrationsDir(migrationsDir);
|
|
110
|
+
const attested = packages.filter(isAttested);
|
|
111
|
+
|
|
112
|
+
if (attested.length > 0) {
|
|
113
|
+
const graph = reconstructGraph(attested);
|
|
114
|
+
|
|
115
|
+
if (options.from) {
|
|
116
|
+
// Explicit --from: find the migration with matching to hash
|
|
117
|
+
const match = attested.find((p) => p.manifest.to.startsWith(options.from!));
|
|
118
|
+
if (!match) {
|
|
119
|
+
return notOk(
|
|
120
|
+
errorRuntime('Starting contract not found', {
|
|
121
|
+
why: `No migration with to hash matching "${options.from}" exists in ${migrationsRelative}`,
|
|
122
|
+
fix: 'Check that the --from hash matches a known migration target hash.',
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
fromHash = match.manifest.to;
|
|
127
|
+
fromContract = match.manifest.toContract;
|
|
128
|
+
} else {
|
|
129
|
+
const latestMigration = findLatestMigration(graph);
|
|
130
|
+
if (latestMigration) {
|
|
131
|
+
fromHash = latestMigration.to;
|
|
132
|
+
const leafPkg = attested.find(
|
|
133
|
+
(p) => p.manifest.migrationId === latestMigration.migrationId,
|
|
134
|
+
);
|
|
135
|
+
if (leafPkg) {
|
|
136
|
+
fromContract = leafPkg.manifest.toContract;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (MigrationToolsError.is(error)) {
|
|
143
|
+
return notOk(
|
|
144
|
+
errorRuntime(error.message, {
|
|
145
|
+
why: error.why,
|
|
146
|
+
fix: error.fix,
|
|
147
|
+
meta: { code: error.code },
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Check for no-op
|
|
155
|
+
if (fromHash === toStorageHash) {
|
|
156
|
+
return notOk(
|
|
157
|
+
errorRuntime('No changes detected', {
|
|
158
|
+
why: 'The from and to contract hashes are identical — there is nothing to migrate.',
|
|
159
|
+
fix: 'Change the contract and run `prisma-next contract emit` before creating a new migration.',
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Build manifest and write package
|
|
165
|
+
const timestamp = new Date();
|
|
166
|
+
const slug = options.name ?? 'migration';
|
|
167
|
+
const dirName = formatMigrationDirName(timestamp, slug);
|
|
168
|
+
const packageDir = join(migrationsDir, dirName);
|
|
169
|
+
|
|
170
|
+
const manifest: MigrationManifest = {
|
|
171
|
+
from: fromHash,
|
|
172
|
+
to: toStorageHash,
|
|
173
|
+
migrationId: null,
|
|
174
|
+
kind: 'regular',
|
|
175
|
+
fromContract,
|
|
176
|
+
toContract: toContractJson,
|
|
177
|
+
hints: {
|
|
178
|
+
used: [],
|
|
179
|
+
applied: [],
|
|
180
|
+
plannerVersion: '1.0.0',
|
|
181
|
+
planningStrategy: 'manual',
|
|
182
|
+
},
|
|
183
|
+
labels: [],
|
|
184
|
+
createdAt: timestamp.toISOString(),
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
// Write package with empty ops (draft)
|
|
189
|
+
await writeMigrationPackage(packageDir, manifest, []);
|
|
190
|
+
|
|
191
|
+
// Scaffold migration.ts
|
|
192
|
+
await scaffoldMigrationTs(packageDir);
|
|
193
|
+
|
|
194
|
+
return ok({
|
|
195
|
+
ok: true as const,
|
|
196
|
+
dir: relative(process.cwd(), packageDir),
|
|
197
|
+
from: fromHash,
|
|
198
|
+
to: toStorageHash,
|
|
199
|
+
summary: `Scaffolded migration at ${relative(process.cwd(), packageDir)}`,
|
|
200
|
+
});
|
|
201
|
+
} catch (error) {
|
|
202
|
+
return notOk(
|
|
203
|
+
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
204
|
+
why: `Failed to scaffold migration: ${error instanceof Error ? error.message : String(error)}`,
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function createMigrationNewCommand(): Command {
|
|
211
|
+
const command = new Command('new');
|
|
212
|
+
setCommandDescriptions(
|
|
213
|
+
command,
|
|
214
|
+
'Scaffold a new migration for manual authoring',
|
|
215
|
+
'Creates a migration package with a migration.ts file for manual authoring.\n' +
|
|
216
|
+
'Write operation descriptors and data transforms in migration.ts, then run\n' +
|
|
217
|
+
'`migration verify` to resolve and attest the package.',
|
|
218
|
+
);
|
|
219
|
+
setCommandExamples(command, [
|
|
220
|
+
'prisma-next migration new --name split-name',
|
|
221
|
+
'prisma-next migration new --name custom-fk --from sha256:abc...',
|
|
222
|
+
]);
|
|
223
|
+
addGlobalOptions(command)
|
|
224
|
+
.option('--name <slug>', 'Migration name (used in directory name)')
|
|
225
|
+
.option('--from <hash>', 'Starting contract hash (default: latest migration target)')
|
|
226
|
+
.option('--config <path>', 'Path to prisma-next.config.ts')
|
|
227
|
+
.action(async (options: MigrationNewOptions) => {
|
|
228
|
+
const flags = parseGlobalFlags(options);
|
|
229
|
+
const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });
|
|
230
|
+
|
|
231
|
+
if (!flags.json && !flags.quiet) {
|
|
232
|
+
const header = formatStyledHeader({
|
|
233
|
+
command: 'migration new',
|
|
234
|
+
description: 'Scaffold a new migration',
|
|
235
|
+
details: [],
|
|
236
|
+
flags,
|
|
237
|
+
});
|
|
238
|
+
ui.stderr(header);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const result = await executeMigrationNewCommand(options);
|
|
242
|
+
|
|
243
|
+
const exitCode = handleResult(result, flags, ui, (value) => {
|
|
244
|
+
if (flags.json) {
|
|
245
|
+
ui.output(JSON.stringify(value, null, 2));
|
|
246
|
+
} else if (!flags.quiet) {
|
|
247
|
+
ui.output(`\nScaffolded migration at ${value.dir}`);
|
|
248
|
+
ui.output(` from: ${value.from}`);
|
|
249
|
+
ui.output(` to: ${value.to}`);
|
|
250
|
+
ui.output(
|
|
251
|
+
`\nEdit migration.ts, then run \`prisma-next migration verify --dir ${value.dir}\` to attest.`,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
process.exit(exitCode);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return command;
|
|
260
|
+
}
|