@prisma-next/cli 0.5.0-dev.9 → 0.6.0-dev.1
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 +61 -26
- package/dist/cli-errors-B9OBbled.d.mts +3 -0
- package/dist/cli-errors-D3_sMh2K.mjs +33 -0
- package/dist/cli-errors-D3_sMh2K.mjs.map +1 -0
- package/dist/cli.mjs +16 -78
- package/dist/cli.mjs.map +1 -1
- package/dist/client-qVH-rEgd.mjs +1595 -0
- package/dist/client-qVH-rEgd.mjs.map +1 -0
- package/dist/{result-handler-Ba3zWQsI.mjs → command-helpers-BeZHkxV8.mjs} +70 -47
- package/dist/command-helpers-BeZHkxV8.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +2 -4
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +2 -4
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +16 -13
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.d.mts.map +1 -1
- package/dist/commands/db-schema.mjs +6 -7
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.d.mts.map +1 -1
- package/dist/commands/db-sign.mjs +9 -9
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.d.mts.map +1 -1
- package/dist/commands/db-update.mjs +15 -13
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.d.mts.map +1 -1
- package/dist/commands/db-verify.mjs +1 -321
- package/dist/commands/migration-apply.d.mts +28 -13
- package/dist/commands/migration-apply.d.mts.map +1 -1
- package/dist/commands/migration-apply.mjs +55 -151
- package/dist/commands/migration-apply.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts +0 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +34 -40
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +33 -6
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +2 -348
- package/dist/commands/migration-ref.d.mts +1 -1
- package/dist/commands/migration-ref.d.mts.map +1 -1
- package/dist/commands/migration-ref.mjs +8 -12
- package/dist/commands/migration-ref.mjs.map +1 -1
- package/dist/commands/migration-show.d.mts +13 -7
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +35 -36
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +126 -5
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +2 -4
- package/dist/{config-loader-C25b63rJ.mjs → config-loader-B6sJjXTv.mjs} +3 -5
- package/dist/config-loader-B6sJjXTv.mjs.map +1 -0
- package/dist/config-loader.d.mts +0 -1
- package/dist/config-loader.d.mts.map +1 -1
- package/dist/config-loader.mjs +2 -3
- package/dist/contract-emit-9DBda5Ou.mjs +150 -0
- package/dist/contract-emit-9DBda5Ou.mjs.map +1 -0
- package/dist/contract-emit-B77TsJqf.mjs +327 -0
- package/dist/contract-emit-B77TsJqf.mjs.map +1 -0
- package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-Dani0mMW.mjs} +4 -6
- package/dist/contract-enrichment-Dani0mMW.mjs.map +1 -0
- package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-BK9YFGEG.mjs} +13 -22
- package/dist/contract-infer-BK9YFGEG.mjs.map +1 -0
- package/dist/db-verify-C0y1PCO2.mjs +404 -0
- package/dist/db-verify-C0y1PCO2.mjs.map +1 -0
- package/dist/exports/config-types.mjs +1 -2
- package/dist/exports/control-api.d.mts +101 -586
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +4 -6
- package/dist/exports/index.d.mts.map +1 -1
- package/dist/exports/index.mjs +28 -30
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts +2 -4
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +2 -3
- package/dist/extension-pack-inputs-C7xgE-vv.mjs +74 -0
- package/dist/extension-pack-inputs-C7xgE-vv.mjs.map +1 -0
- package/dist/{framework-components-Cr--XBKy.mjs → framework-components-ChqVUxR-.mjs} +3 -4
- package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-ChqVUxR-.mjs.map} +1 -1
- package/dist/global-flags-Icqpxk23.d.mts +12 -0
- package/dist/global-flags-Icqpxk23.d.mts.map +1 -0
- package/dist/helpers-eqdN8tH6.mjs +25 -0
- package/dist/helpers-eqdN8tH6.mjs.map +1 -0
- package/dist/{init-C5220SY9.mjs → init-DETSgw3h.mjs} +40 -49
- package/dist/init-DETSgw3h.mjs.map +1 -0
- package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-CWYxGKlb.mjs} +10 -11
- package/dist/inspect-live-schema-CWYxGKlb.mjs.map +1 -0
- package/dist/migration-cli.d.mts +41 -12
- package/dist/migration-cli.d.mts.map +1 -1
- package/dist/migration-cli.mjs +309 -86
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-B5dORFEv.mjs} +8 -9
- package/dist/migration-command-scaffold-B5dORFEv.mjs.map +1 -0
- package/dist/migration-plan-C6lVaHsO.mjs +554 -0
- package/dist/migration-plan-C6lVaHsO.mjs.map +1 -0
- package/dist/{migration-status-DUMiH8_G.mjs → migration-status-CZ-D5k7k.mjs} +272 -65
- package/dist/migration-status-CZ-D5k7k.mjs.map +1 -0
- package/dist/migrations-D_UJnpuW.mjs +216 -0
- package/dist/migrations-D_UJnpuW.mjs.map +1 -0
- package/dist/{output-BpcQrnnq.mjs → output-B16Kefzx.mjs} +9 -3
- package/dist/output-B16Kefzx.mjs.map +1 -0
- package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-DFfvZcYL.mjs} +2 -2
- package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-DFfvZcYL.mjs.map} +1 -1
- package/dist/result-handler-rmPVKIP2.mjs +25 -0
- package/dist/result-handler-rmPVKIP2.mjs.map +1 -0
- package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
- package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-C_hFNbAn.mjs} +4 -28
- package/dist/terminal-ui-C_hFNbAn.mjs.map +1 -0
- package/dist/types-D7x-IFLO.d.mts +858 -0
- package/dist/types-D7x-IFLO.d.mts.map +1 -0
- package/dist/{verify-Bkycc-Tf.mjs → verify-CiwNWM9N.mjs} +3 -4
- package/dist/verify-CiwNWM9N.mjs.map +1 -0
- package/package.json +28 -26
- package/src/cli.ts +32 -6
- package/src/commands/contract-emit.ts +67 -163
- package/src/commands/contract-infer.ts +7 -20
- package/src/commands/db-init.ts +15 -3
- package/src/commands/db-update.ts +9 -4
- package/src/commands/db-verify.ts +47 -15
- package/src/commands/init/index.ts +1 -1
- package/src/commands/init/init.ts +2 -2
- package/src/commands/init/templates/code-templates.ts +26 -18
- package/src/commands/inspect-live-schema.ts +10 -5
- package/src/commands/migration-apply.ts +114 -212
- package/src/commands/migration-new.ts +42 -45
- package/src/commands/migration-plan.ts +212 -72
- package/src/commands/migration-ref.ts +8 -7
- package/src/commands/migration-show.ts +60 -41
- package/src/commands/migration-status.ts +483 -64
- package/src/config-path-validation.ts +0 -1
- package/src/control-api/client.ts +85 -5
- package/src/control-api/contract-enrichment.ts +6 -4
- package/src/control-api/operations/apply-aggregate.ts +290 -0
- package/src/control-api/operations/contract-emit.ts +198 -115
- package/src/control-api/operations/db-apply-aggregate.ts +397 -0
- package/src/control-api/operations/db-init.ts +51 -253
- package/src/control-api/operations/db-update.ts +66 -183
- package/src/control-api/operations/db-verify.ts +342 -0
- package/src/control-api/operations/migration-apply.ts +424 -131
- package/src/control-api/types.ts +280 -29
- package/src/exports/control-api.ts +15 -3
- package/src/load-ts-contract.ts +28 -26
- package/src/migration-cli.ts +445 -122
- package/src/utils/cli-errors.ts +49 -2
- package/src/utils/combine-schema-results.ts +84 -0
- package/src/utils/command-helpers.ts +69 -25
- package/src/utils/contract-space-aggregate-loader.ts +204 -0
- package/src/utils/contract-space-extension-migrations-pass.ts +120 -0
- package/src/utils/contract-space-migrate-pass.ts +156 -0
- package/src/utils/emit-queue.ts +26 -0
- package/src/utils/extension-pack-inputs.ts +170 -0
- package/src/utils/formatters/graph-migration-mapper.ts +7 -3
- package/src/utils/formatters/migrations.ts +197 -61
- package/src/utils/publish-contract-artifact-pair.ts +134 -0
- package/dist/cli-errors-BFYgBH3L.d.mts +0 -4
- package/dist/cli-errors-Cd79vmTH.mjs +0 -5
- package/dist/client-CrsnY58k.mjs +0 -997
- package/dist/client-CrsnY58k.mjs.map +0 -1
- package/dist/commands/db-verify.mjs.map +0 -1
- package/dist/commands/migration-plan.mjs.map +0 -1
- package/dist/config-loader-C25b63rJ.mjs.map +0 -1
- package/dist/contract-emit--feXyNd7.mjs +0 -4
- package/dist/contract-emit-NJ01hiiv.mjs +0 -195
- package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
- package/dist/contract-emit-V5SSitUT.mjs +0 -122
- package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
- package/dist/contract-enrichment-CAOELa-H.mjs.map +0 -1
- package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
- package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
- package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
- package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
- package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
- package/dist/init-C5220SY9.mjs.map +0 -1
- package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
- package/dist/migration-command-scaffold-B3B09et6.mjs.map +0 -1
- package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
- package/dist/migrations-Bo5WtTla.mjs +0 -153
- package/dist/migrations-Bo5WtTla.mjs.map +0 -1
- package/dist/output-BpcQrnnq.mjs.map +0 -1
- package/dist/result-handler-Ba3zWQsI.mjs.map +0 -1
- package/dist/terminal-ui-C3ZLwQxK.mjs.map +0 -1
- package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
- package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
- package/dist/verify-Bkycc-Tf.mjs.map +0 -1
- package/src/control-api/operations/extract-operation-statements.ts +0 -14
- package/src/control-api/operations/extract-sql-ddl.ts +0 -47
|
@@ -11,32 +11,36 @@
|
|
|
11
11
|
import { readFileSync } from 'node:fs';
|
|
12
12
|
import type { Contract } from '@prisma-next/contract/types';
|
|
13
13
|
import { getEmittedArtifactPaths } from '@prisma-next/emitter';
|
|
14
|
-
import { createControlStack } from '@prisma-next/framework-components/control';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { findLatestMigration, reconstructGraph } from '@prisma-next/migration-tools/dag';
|
|
14
|
+
import { APP_SPACE_ID, createControlStack } from '@prisma-next/framework-components/control';
|
|
15
|
+
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
16
|
+
import { computeMigrationHash } from '@prisma-next/migration-tools/hash';
|
|
18
17
|
import {
|
|
19
18
|
copyFilesWithRename,
|
|
20
19
|
formatMigrationDirName,
|
|
21
20
|
readMigrationsDir,
|
|
22
21
|
writeMigrationPackage,
|
|
23
22
|
} from '@prisma-next/migration-tools/io';
|
|
23
|
+
import type { MigrationMetadata } from '@prisma-next/migration-tools/metadata';
|
|
24
|
+
import {
|
|
25
|
+
findLatestMigration,
|
|
26
|
+
reconstructGraph,
|
|
27
|
+
} from '@prisma-next/migration-tools/migration-graph';
|
|
24
28
|
import { writeMigrationTs } from '@prisma-next/migration-tools/migration-ts';
|
|
25
|
-
import type { MigrationManifest } from '@prisma-next/migration-tools/types';
|
|
26
|
-
import { MigrationToolsError } from '@prisma-next/migration-tools/types';
|
|
27
29
|
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
28
30
|
import { Command } from 'commander';
|
|
29
|
-
import { join, relative
|
|
31
|
+
import { join, relative } from 'pathe';
|
|
30
32
|
import { loadConfig } from '../config-loader';
|
|
31
33
|
import {
|
|
32
34
|
CliStructuredError,
|
|
33
35
|
errorRuntime,
|
|
34
36
|
errorTargetMigrationNotSupported,
|
|
35
37
|
errorUnexpected,
|
|
38
|
+
mapMigrationToolsError,
|
|
36
39
|
} from '../utils/cli-errors';
|
|
37
40
|
import {
|
|
38
41
|
addGlobalOptions,
|
|
39
42
|
getTargetMigrations,
|
|
43
|
+
resolveContractPath,
|
|
40
44
|
resolveMigrationPaths,
|
|
41
45
|
setCommandDescriptions,
|
|
42
46
|
setCommandExamples,
|
|
@@ -57,7 +61,7 @@ interface MigrationNewOptions extends CommonCommandOptions {
|
|
|
57
61
|
interface MigrationNewResult {
|
|
58
62
|
readonly ok: true;
|
|
59
63
|
readonly dir: string;
|
|
60
|
-
readonly from: string;
|
|
64
|
+
readonly from: string | null;
|
|
61
65
|
readonly to: string;
|
|
62
66
|
readonly summary: string;
|
|
63
67
|
}
|
|
@@ -66,13 +70,9 @@ async function executeMigrationNewCommand(
|
|
|
66
70
|
options: MigrationNewOptions,
|
|
67
71
|
): Promise<Result<MigrationNewResult, CliStructuredError>> {
|
|
68
72
|
const config = await loadConfig(options.config);
|
|
69
|
-
const {
|
|
73
|
+
const { appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(options.config, config);
|
|
70
74
|
|
|
71
|
-
const
|
|
72
|
-
const contractPathAbsolute = resolve(
|
|
73
|
-
options.config ? resolve(options.config, '..') : process.cwd(),
|
|
74
|
-
contractPath,
|
|
75
|
-
);
|
|
75
|
+
const contractPathAbsolute = resolveContractPath(config);
|
|
76
76
|
|
|
77
77
|
let contractJsonContent: string;
|
|
78
78
|
try {
|
|
@@ -116,37 +116,37 @@ async function executeMigrationNewCommand(
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
let fromContract: Contract | null = null;
|
|
119
|
-
let fromHash: string =
|
|
119
|
+
let fromHash: string | null = null;
|
|
120
120
|
let fromContractSourceDir: string | null = null;
|
|
121
121
|
|
|
122
122
|
try {
|
|
123
|
-
const packages = await readMigrationsDir(
|
|
123
|
+
const packages = await readMigrationsDir(appMigrationsDir);
|
|
124
124
|
|
|
125
125
|
if (packages.length > 0) {
|
|
126
126
|
const graph = reconstructGraph(packages);
|
|
127
127
|
|
|
128
128
|
if (options.from) {
|
|
129
|
-
const match = packages.find((p) => p.
|
|
129
|
+
const match = packages.find((p) => p.metadata.to.startsWith(options.from!));
|
|
130
130
|
if (!match) {
|
|
131
131
|
return notOk(
|
|
132
132
|
errorRuntime('Starting contract not found', {
|
|
133
|
-
why: `No migration with to hash matching "${options.from}" exists in ${
|
|
133
|
+
why: `No migration with to hash matching "${options.from}" exists in ${appMigrationsRelative}`,
|
|
134
134
|
fix: 'Check that the --from hash matches a known migration target hash.',
|
|
135
135
|
}),
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
|
-
fromHash = match.
|
|
139
|
-
fromContract = match.
|
|
138
|
+
fromHash = match.metadata.to;
|
|
139
|
+
fromContract = match.metadata.toContract;
|
|
140
140
|
fromContractSourceDir = match.dirPath;
|
|
141
141
|
} else {
|
|
142
142
|
const latestMigration = findLatestMigration(graph);
|
|
143
143
|
if (latestMigration) {
|
|
144
144
|
fromHash = latestMigration.to;
|
|
145
145
|
const leafPkg = packages.find(
|
|
146
|
-
(p) => p.
|
|
146
|
+
(p) => p.metadata.migrationHash === latestMigration.migrationHash,
|
|
147
147
|
);
|
|
148
148
|
if (leafPkg) {
|
|
149
|
-
fromContract = leafPkg.
|
|
149
|
+
fromContract = leafPkg.metadata.toContract;
|
|
150
150
|
fromContractSourceDir = leafPkg.dirPath;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -154,22 +154,16 @@ async function executeMigrationNewCommand(
|
|
|
154
154
|
}
|
|
155
155
|
} catch (error) {
|
|
156
156
|
if (MigrationToolsError.is(error)) {
|
|
157
|
-
return notOk(
|
|
158
|
-
errorRuntime(error.message, {
|
|
159
|
-
why: error.why,
|
|
160
|
-
fix: error.fix,
|
|
161
|
-
meta: { code: error.code },
|
|
162
|
-
}),
|
|
163
|
-
);
|
|
157
|
+
return notOk(mapMigrationToolsError(error));
|
|
164
158
|
}
|
|
165
159
|
throw error;
|
|
166
160
|
}
|
|
167
161
|
|
|
168
|
-
if (fromHash === toStorageHash) {
|
|
162
|
+
if (fromHash === toStorageHash && !options.from) {
|
|
169
163
|
return notOk(
|
|
170
164
|
errorRuntime('No changes detected', {
|
|
171
165
|
why: 'The from and to contract hashes are identical — there is nothing to migrate.',
|
|
172
|
-
fix: 'Change the contract and run `prisma-next contract emit` before creating a new migration.',
|
|
166
|
+
fix: 'Change the contract and run `prisma-next contract emit` before creating a new migration. To author a data-only migration on the current contract hash, pass `--from <hash>` explicitly.',
|
|
173
167
|
}),
|
|
174
168
|
);
|
|
175
169
|
}
|
|
@@ -177,16 +171,15 @@ async function executeMigrationNewCommand(
|
|
|
177
171
|
const timestamp = new Date();
|
|
178
172
|
const slug = options.name ?? 'migration';
|
|
179
173
|
const dirName = formatMigrationDirName(timestamp, slug);
|
|
180
|
-
const packageDir = join(
|
|
174
|
+
const packageDir = join(appMigrationsDir, dirName);
|
|
181
175
|
|
|
182
176
|
// `migration new` scaffolds an empty `migration.ts` for the user to
|
|
183
177
|
// fill, so we attest over `ops: []`. Re-running self-emit after the
|
|
184
|
-
// user adds operations will produce a different `
|
|
178
|
+
// user adds operations will produce a different `migrationHash` (over
|
|
185
179
|
// the real ops). This is intentional — there is no on-disk draft.
|
|
186
|
-
const
|
|
180
|
+
const baseMetadata: Omit<MigrationMetadata, 'migrationHash'> = {
|
|
187
181
|
from: fromHash,
|
|
188
182
|
to: toStorageHash,
|
|
189
|
-
kind: 'regular',
|
|
190
183
|
fromContract,
|
|
191
184
|
toContract: toContractJson,
|
|
192
185
|
hints: {
|
|
@@ -195,11 +188,12 @@ async function executeMigrationNewCommand(
|
|
|
195
188
|
plannerVersion: '1.0.0',
|
|
196
189
|
},
|
|
197
190
|
labels: [],
|
|
191
|
+
providedInvariants: [],
|
|
198
192
|
createdAt: timestamp.toISOString(),
|
|
199
193
|
};
|
|
200
|
-
const
|
|
201
|
-
...
|
|
202
|
-
|
|
194
|
+
const metadata: MigrationMetadata = {
|
|
195
|
+
...baseMetadata,
|
|
196
|
+
migrationHash: computeMigrationHash(baseMetadata, []),
|
|
203
197
|
};
|
|
204
198
|
|
|
205
199
|
const migrations = getTargetMigrations(config.target);
|
|
@@ -218,7 +212,7 @@ async function executeMigrationNewCommand(
|
|
|
218
212
|
...(config.extensionPacks ?? []),
|
|
219
213
|
]);
|
|
220
214
|
|
|
221
|
-
await writeMigrationPackage(packageDir,
|
|
215
|
+
await writeMigrationPackage(packageDir, metadata, []);
|
|
222
216
|
const destinationArtifacts = getEmittedArtifactPaths(contractPathAbsolute);
|
|
223
217
|
await copyFilesWithRename(packageDir, [
|
|
224
218
|
{ sourcePath: destinationArtifacts.jsonPath, destName: 'end-contract.json' },
|
|
@@ -237,12 +231,15 @@ async function executeMigrationNewCommand(
|
|
|
237
231
|
const stack = createControlStack(config);
|
|
238
232
|
const familyInstance = config.family.create(stack);
|
|
239
233
|
const planner = migrations.createPlanner(familyInstance);
|
|
240
|
-
const emptyPlan = planner.emptyMigration(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
234
|
+
const emptyPlan = planner.emptyMigration(
|
|
235
|
+
{
|
|
236
|
+
packageDir,
|
|
237
|
+
contractJsonPath: join(packageDir, 'end-contract.json'),
|
|
238
|
+
fromHash,
|
|
239
|
+
toHash: toStorageHash,
|
|
240
|
+
},
|
|
241
|
+
APP_SPACE_ID,
|
|
242
|
+
);
|
|
246
243
|
await writeMigrationTs(packageDir, emptyPlan.renderTypeScript());
|
|
247
244
|
|
|
248
245
|
return ok({
|