@prisma-next/cli 0.4.1 → 0.4.3
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 +56 -26
- package/dist/agent-skill-mongo.md +63 -31
- package/dist/agent-skill-postgres.md +1 -1
- package/dist/cli-errors-By1iVE3z.mjs +34 -0
- package/dist/cli-errors-By1iVE3z.mjs.map +1 -0
- package/dist/cli-errors-DDeVsP2Y.d.mts +5 -0
- package/dist/cli.mjs +131 -15
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-DGKrciLM.mjs → client-1JqqkiC7.mjs} +45 -20
- package/dist/client-1JqqkiC7.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +7 -2
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +8 -2
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +11 -9
- package/dist/commands/db-init.mjs.map +1 -1
- package/dist/commands/db-schema.mjs +8 -5
- package/dist/commands/db-schema.mjs.map +1 -1
- package/dist/commands/db-sign.mjs +8 -7
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.mjs +10 -9
- package/dist/commands/db-update.mjs.map +1 -1
- package/dist/commands/db-verify.mjs +10 -9
- package/dist/commands/db-verify.mjs.map +1 -1
- package/dist/commands/migration-apply.d.mts +5 -2
- package/dist/commands/migration-apply.d.mts.map +1 -1
- package/dist/commands/migration-apply.mjs +57 -57
- package/dist/commands/migration-apply.mjs.map +1 -1
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +26 -32
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +14 -5
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +45 -48
- package/dist/commands/migration-plan.mjs.map +1 -1
- package/dist/commands/migration-ref.d.mts +6 -4
- package/dist/commands/migration-ref.d.mts.map +1 -1
- package/dist/commands/migration-ref.mjs +31 -40
- 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 +28 -29
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +23 -5
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +8 -3
- package/dist/{config-loader-_xQZsw0i.mjs → config-loader-ih8ViDb_.mjs} +2 -2
- package/dist/config-loader-ih8ViDb_.mjs.map +1 -0
- package/dist/config-loader.mjs +1 -1
- package/dist/contract-emit-DS5NzZh2.mjs +6 -0
- package/dist/contract-emit-RZBWzkop.mjs +329 -0
- package/dist/contract-emit-RZBWzkop.mjs.map +1 -0
- package/dist/contract-emit-rt_Nmdwq.mjs +150 -0
- package/dist/contract-emit-rt_Nmdwq.mjs.map +1 -0
- package/dist/{contract-enrichment-BV4KpbNW.mjs → contract-enrichment-4Ptgw3Pe.mjs} +1 -1
- package/dist/{contract-enrichment-BV4KpbNW.mjs.map → contract-enrichment-4Ptgw3Pe.mjs.map} +1 -1
- package/dist/{contract-infer-CUbiWGX0.mjs → contract-infer-Cf5J2wVg.mjs} +11 -19
- package/dist/contract-infer-Cf5J2wVg.mjs.map +1 -0
- package/dist/exports/control-api.d.mts +86 -21
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +7 -5
- package/dist/exports/index.mjs +8 -3
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts +39 -0
- package/dist/exports/init-output.d.mts.map +1 -0
- package/dist/exports/init-output.mjs +3 -0
- package/dist/{framework-components-B__p--vT.mjs → framework-components-Bgcre3Z6.mjs} +2 -2
- package/dist/{framework-components-B__p--vT.mjs.map → framework-components-Bgcre3Z6.mjs.map} +1 -1
- package/dist/init-DAbQMxIR.mjs +2062 -0
- package/dist/init-DAbQMxIR.mjs.map +1 -0
- package/dist/{inspect-live-schema-wIYBTdL3.mjs → inspect-live-schema-LWtXfxm_.mjs} +9 -9
- package/dist/inspect-live-schema-LWtXfxm_.mjs.map +1 -0
- package/dist/migration-cli.d.mts +80 -0
- package/dist/migration-cli.d.mts.map +1 -0
- package/dist/migration-cli.mjs +408 -0
- package/dist/migration-cli.mjs.map +1 -0
- package/dist/{migration-command-scaffold-BC73xQSo.mjs → migration-command-scaffold-CU452v9h.mjs} +7 -7
- package/dist/{migration-command-scaffold-BC73xQSo.mjs.map → migration-command-scaffold-CU452v9h.mjs.map} +1 -1
- package/dist/{migration-status-CXBbScH5.mjs → migration-status-DoPrFIOQ.mjs} +119 -64
- package/dist/migration-status-DoPrFIOQ.mjs.map +1 -0
- package/dist/{migrations-DYRAjiVh.mjs → migrations-MEoKMiV5.mjs} +42 -21
- package/dist/migrations-MEoKMiV5.mjs.map +1 -0
- package/dist/output-BpcQrnnq.mjs +103 -0
- package/dist/output-BpcQrnnq.mjs.map +1 -0
- package/dist/{progress-adapter-Bwouy73-.mjs → progress-adapter-DgRGldpT.mjs} +1 -1
- package/dist/{progress-adapter-Bwouy73-.mjs.map → progress-adapter-DgRGldpT.mjs.map} +1 -1
- package/dist/quick-reference-mongo.md +34 -13
- package/dist/quick-reference-postgres.md +11 -9
- package/dist/{result-handler-CGohaH1o.mjs → result-handler-Ch6hVnOo.mjs} +36 -94
- package/dist/result-handler-Ch6hVnOo.mjs.map +1 -0
- package/dist/{terminal-ui-BuPXVRFY.mjs → terminal-ui-u2YgKghu.mjs} +76 -2
- package/dist/terminal-ui-u2YgKghu.mjs.map +1 -0
- package/dist/{verify-Cm2UFuZA.mjs → verify-BT9tgCOH.mjs} +2 -2
- package/dist/{verify-Cm2UFuZA.mjs.map → verify-BT9tgCOH.mjs.map} +1 -1
- package/package.json +27 -17
- 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 +1 -0
- package/src/commands/db-update.ts +1 -1
- package/src/commands/init/detect-pnpm-catalog.ts +141 -0
- package/src/commands/init/errors.ts +254 -0
- package/src/commands/init/exit-codes.ts +62 -0
- package/src/commands/init/hygiene-gitattributes.ts +97 -0
- package/src/commands/init/hygiene-gitignore.ts +48 -0
- package/src/commands/init/hygiene-package-scripts.ts +91 -0
- package/src/commands/init/index.ts +112 -7
- package/src/commands/init/init.ts +766 -144
- package/src/commands/init/inputs.ts +421 -0
- package/src/commands/init/output.ts +147 -0
- package/src/commands/init/probe-db.ts +308 -0
- package/src/commands/init/reinit-cleanup.ts +83 -0
- package/src/commands/init/templates/agent-skill-mongo.md +63 -31
- package/src/commands/init/templates/agent-skill-postgres.md +1 -1
- package/src/commands/init/templates/agent-skill.ts +25 -3
- package/src/commands/init/templates/code-templates.ts +125 -32
- package/src/commands/init/templates/env.ts +80 -0
- package/src/commands/init/templates/quick-reference-mongo.md +34 -13
- package/src/commands/init/templates/quick-reference-postgres.md +11 -9
- package/src/commands/init/templates/quick-reference.ts +42 -3
- package/src/commands/init/templates/tsconfig.ts +167 -5
- package/src/commands/inspect-live-schema.ts +10 -5
- package/src/commands/migration-apply.ts +86 -65
- package/src/commands/migration-new.ts +28 -34
- package/src/commands/migration-plan.ts +80 -56
- package/src/commands/migration-ref.ts +40 -54
- package/src/commands/migration-show.ts +53 -36
- package/src/commands/migration-status.ts +202 -71
- package/src/config-path-validation.ts +0 -1
- package/src/control-api/client.ts +21 -0
- package/src/control-api/operations/contract-emit.ts +198 -115
- package/src/control-api/operations/db-init.ts +10 -6
- package/src/control-api/operations/db-update.ts +10 -6
- package/src/control-api/operations/migration-apply.ts +30 -9
- package/src/control-api/types.ts +69 -7
- package/src/exports/control-api.ts +2 -1
- package/src/exports/init-output.ts +10 -0
- package/src/migration-cli.ts +577 -0
- package/src/utils/cli-errors.ts +50 -2
- package/src/utils/command-helpers.ts +48 -26
- package/src/utils/emit-queue.ts +26 -0
- package/src/utils/formatters/graph-migration-mapper.ts +7 -3
- package/src/utils/formatters/migrations.ts +62 -26
- package/src/utils/publish-contract-artifact-pair.ts +134 -0
- package/dist/cli-errors-CznZA5-d.mjs +0 -5
- package/dist/cli-errors-z37sV3eR.d.mts +0 -4
- package/dist/client-DGKrciLM.mjs.map +0 -1
- package/dist/config-loader-_xQZsw0i.mjs.map +0 -1
- package/dist/contract-emit-304WZtZJ.mjs +0 -4
- package/dist/contract-emit-DgeWdonT.mjs +0 -122
- package/dist/contract-emit-DgeWdonT.mjs.map +0 -1
- package/dist/contract-emit-mU1_B_m9.mjs +0 -195
- package/dist/contract-emit-mU1_B_m9.mjs.map +0 -1
- package/dist/contract-infer-CUbiWGX0.mjs.map +0 -1
- package/dist/extract-operation-statements-DWWFz1PK.mjs +0 -13
- package/dist/extract-operation-statements-DWWFz1PK.mjs.map +0 -1
- package/dist/extract-sql-ddl-7zn_AFS8.mjs +0 -26
- package/dist/extract-sql-ddl-7zn_AFS8.mjs.map +0 -1
- package/dist/init-DRquYpPa.mjs +0 -430
- package/dist/init-DRquYpPa.mjs.map +0 -1
- package/dist/inspect-live-schema-wIYBTdL3.mjs.map +0 -1
- package/dist/migration-status-CXBbScH5.mjs.map +0 -1
- package/dist/migrations-DYRAjiVh.mjs.map +0 -1
- package/dist/result-handler-CGohaH1o.mjs.map +0 -1
- package/dist/terminal-ui-BuPXVRFY.mjs.map +0 -1
- package/dist/validate-contract-deps-DZqv9m7H.mjs +0 -37
- package/dist/validate-contract-deps-DZqv9m7H.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
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
MigrationPlanOperation,
|
|
3
|
+
OperationPreview,
|
|
4
|
+
} from '@prisma-next/framework-components/control';
|
|
5
|
+
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
3
6
|
import { readMigrationPackage, readMigrationsDir } from '@prisma-next/migration-tools/io';
|
|
4
|
-
import
|
|
5
|
-
|
|
7
|
+
import {
|
|
8
|
+
findLatestMigration,
|
|
9
|
+
reconstructGraph,
|
|
10
|
+
} from '@prisma-next/migration-tools/migration-graph';
|
|
11
|
+
import type { MigrationPackage } from '@prisma-next/migration-tools/package';
|
|
6
12
|
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
7
13
|
import { Command } from 'commander';
|
|
8
14
|
import { relative, resolve } from 'pathe';
|
|
9
15
|
import { loadConfig } from '../config-loader';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
16
|
+
import { createControlClient } from '../control-api/client';
|
|
17
|
+
import {
|
|
18
|
+
type CliStructuredError,
|
|
19
|
+
errorRuntime,
|
|
20
|
+
errorUnexpected,
|
|
21
|
+
mapMigrationToolsError,
|
|
22
|
+
} from '../utils/cli-errors';
|
|
12
23
|
import {
|
|
13
24
|
addGlobalOptions,
|
|
14
25
|
setCommandDescriptions,
|
|
@@ -29,17 +40,22 @@ export interface MigrationShowResult {
|
|
|
29
40
|
readonly ok: true;
|
|
30
41
|
readonly dirName: string;
|
|
31
42
|
readonly dirPath: string;
|
|
32
|
-
readonly from: string;
|
|
43
|
+
readonly from: string | null;
|
|
33
44
|
readonly to: string;
|
|
34
|
-
readonly
|
|
35
|
-
readonly kind: string;
|
|
45
|
+
readonly migrationHash: string;
|
|
36
46
|
readonly createdAt: string;
|
|
37
47
|
readonly operations: readonly {
|
|
38
48
|
readonly id: string;
|
|
39
49
|
readonly label: string;
|
|
40
50
|
readonly operationClass: string;
|
|
41
51
|
}[];
|
|
42
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Family-agnostic textual preview of the migration's operations. Replaces
|
|
54
|
+
* the previous string-array DDL field. Always defined; statements is empty
|
|
55
|
+
* for a no-op migration or a family that does not implement the
|
|
56
|
+
* `OperationPreviewCapable` capability.
|
|
57
|
+
*/
|
|
58
|
+
readonly preview: OperationPreview;
|
|
43
59
|
readonly summary: string;
|
|
44
60
|
}
|
|
45
61
|
|
|
@@ -48,11 +64,11 @@ function looksLikePath(target: string): boolean {
|
|
|
48
64
|
}
|
|
49
65
|
|
|
50
66
|
export function resolveByHashPrefix(
|
|
51
|
-
packages: readonly
|
|
67
|
+
packages: readonly MigrationPackage[],
|
|
52
68
|
prefix: string,
|
|
53
|
-
): Result<
|
|
69
|
+
): Result<MigrationPackage, CliStructuredError> {
|
|
54
70
|
const normalizedPrefix = prefix.startsWith('sha256:') ? prefix : `sha256:${prefix}`;
|
|
55
|
-
const matches = packages.filter((p) => p.
|
|
71
|
+
const matches = packages.filter((p) => p.metadata.migrationHash.startsWith(normalizedPrefix));
|
|
56
72
|
|
|
57
73
|
if (matches.length === 1) {
|
|
58
74
|
return ok(matches[0]!);
|
|
@@ -61,13 +77,13 @@ export function resolveByHashPrefix(
|
|
|
61
77
|
if (matches.length === 0) {
|
|
62
78
|
return notOk(
|
|
63
79
|
errorRuntime('No migration found matching prefix', {
|
|
64
|
-
why: `No migration has a
|
|
80
|
+
why: `No migration has a migrationHash starting with "${normalizedPrefix}"`,
|
|
65
81
|
fix: 'Run `prisma-next migration show` (no argument) to see the latest migration, or check the migrations directory for available packages.',
|
|
66
82
|
}),
|
|
67
83
|
);
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
const candidates = matches.map((p) => ` ${p.dirName} ${p.
|
|
86
|
+
const candidates = matches.map((p) => ` ${p.dirName} ${p.metadata.migrationHash}`).join('\n');
|
|
71
87
|
return notOk(
|
|
72
88
|
errorRuntime('Ambiguous hash prefix', {
|
|
73
89
|
why: `Multiple migrations match prefix "${normalizedPrefix}":\n${candidates}`,
|
|
@@ -110,7 +126,7 @@ async function executeMigrationShowCommand(
|
|
|
110
126
|
ui.stderr(header);
|
|
111
127
|
}
|
|
112
128
|
|
|
113
|
-
let pkg:
|
|
129
|
+
let pkg: MigrationPackage;
|
|
114
130
|
|
|
115
131
|
try {
|
|
116
132
|
if (target && looksLikePath(target)) {
|
|
@@ -142,7 +158,7 @@ async function executeMigrationShowCommand(
|
|
|
142
158
|
);
|
|
143
159
|
}
|
|
144
160
|
const leafPkg = allPackages.find(
|
|
145
|
-
(p) => p.
|
|
161
|
+
(p) => p.metadata.migrationHash === latestMigration.migrationHash,
|
|
146
162
|
);
|
|
147
163
|
if (!leafPkg) {
|
|
148
164
|
return notOk(
|
|
@@ -157,13 +173,7 @@ async function executeMigrationShowCommand(
|
|
|
157
173
|
}
|
|
158
174
|
} catch (error) {
|
|
159
175
|
if (MigrationToolsError.is(error)) {
|
|
160
|
-
return notOk(
|
|
161
|
-
errorRuntime(error.message, {
|
|
162
|
-
why: error.why,
|
|
163
|
-
fix: error.fix,
|
|
164
|
-
meta: { code: error.code, ...(error.details ?? {}) },
|
|
165
|
-
}),
|
|
166
|
-
);
|
|
176
|
+
return notOk(mapMigrationToolsError(error));
|
|
167
177
|
}
|
|
168
178
|
return notOk(
|
|
169
179
|
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
@@ -173,23 +183,33 @@ async function executeMigrationShowCommand(
|
|
|
173
183
|
}
|
|
174
184
|
|
|
175
185
|
const ops = pkg.ops as readonly MigrationPlanOperation[];
|
|
176
|
-
|
|
186
|
+
|
|
187
|
+
// `migration show` is an offline command; the control client is constructed
|
|
188
|
+
// purely to dispatch the family-specific `toOperationPreview` capability and
|
|
189
|
+
// is not connected to a database.
|
|
190
|
+
const client = createControlClient({
|
|
191
|
+
family: config.family,
|
|
192
|
+
target: config.target,
|
|
193
|
+
adapter: config.adapter,
|
|
194
|
+
...(config.driver ? { driver: config.driver } : {}),
|
|
195
|
+
extensionPacks: config.extensionPacks ?? [],
|
|
196
|
+
});
|
|
197
|
+
const preview: OperationPreview = client.toOperationPreview(ops) ?? { statements: [] };
|
|
177
198
|
|
|
178
199
|
const result: MigrationShowResult = {
|
|
179
200
|
ok: true,
|
|
180
201
|
dirName: pkg.dirName,
|
|
181
202
|
dirPath: relative(process.cwd(), pkg.dirPath),
|
|
182
|
-
from: pkg.
|
|
183
|
-
to: pkg.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
createdAt: pkg.manifest.createdAt,
|
|
203
|
+
from: pkg.metadata.from,
|
|
204
|
+
to: pkg.metadata.to,
|
|
205
|
+
migrationHash: pkg.metadata.migrationHash,
|
|
206
|
+
createdAt: pkg.metadata.createdAt,
|
|
187
207
|
operations: ops.map((op) => ({
|
|
188
208
|
id: op.id,
|
|
189
209
|
label: op.label,
|
|
190
210
|
operationClass: op.operationClass,
|
|
191
211
|
})),
|
|
192
|
-
|
|
212
|
+
preview,
|
|
193
213
|
summary: `${ops.length} operation(s)`,
|
|
194
214
|
};
|
|
195
215
|
return ok(result);
|
|
@@ -200,7 +220,7 @@ export function createMigrationShowCommand(): Command {
|
|
|
200
220
|
setCommandDescriptions(
|
|
201
221
|
command,
|
|
202
222
|
'Display migration package contents',
|
|
203
|
-
'Shows the operations,
|
|
223
|
+
'Shows the operations, statement preview, and metadata for a migration package.\n' +
|
|
204
224
|
'Accepts a directory path, a hash prefix (git-style), or defaults to the\n' +
|
|
205
225
|
'latest migration.',
|
|
206
226
|
);
|
|
@@ -209,10 +229,7 @@ export function createMigrationShowCommand(): Command {
|
|
|
209
229
|
'prisma-next migration show sha256:a1b2c3',
|
|
210
230
|
]);
|
|
211
231
|
addGlobalOptions(command)
|
|
212
|
-
.argument(
|
|
213
|
-
'[target]',
|
|
214
|
-
'Migration directory path or migrationId hash prefix (defaults to latest)',
|
|
215
|
-
)
|
|
232
|
+
.argument('[target]', 'Migration directory path or migrationHash prefix (defaults to latest)')
|
|
216
233
|
.option('--config <path>', 'Path to prisma-next.config.ts')
|
|
217
234
|
.action(async (target: string | undefined, options: MigrationShowOptions) => {
|
|
218
235
|
const flags = parseGlobalFlags(options);
|