@prisma-next/cli 0.12.0 → 0.13.0-dev.10
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 +2 -2
- package/dist/cli.mjs +180 -163
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-KgJorIvG.mjs → client-CJzuo5wX.mjs} +222 -107
- package/dist/client-CJzuo5wX.mjs.map +1 -0
- package/dist/{command-helpers-Bbw1GbwL.mjs → command-helpers-DGMvGBeX.mjs} +318 -25
- package/dist/command-helpers-DGMvGBeX.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts.map +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.d.mts.map +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.d.mts.map +1 -1
- package/dist/commands/db-init.mjs +4 -5
- 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 +3 -3
- 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 +6 -6
- 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 +10 -7
- 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 -1
- package/dist/commands/migrate.d.mts +37 -3
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +298 -12
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +55 -13
- package/dist/commands/migration-check.d.mts.map +1 -1
- package/dist/commands/migration-check.mjs +3 -2
- package/dist/commands/migration-graph.d.mts +17 -8
- package/dist/commands/migration-graph.d.mts.map +1 -1
- package/dist/commands/migration-graph.mjs +185 -2
- package/dist/commands/migration-graph.mjs.map +1 -0
- package/dist/commands/migration-list.d.mts +26 -27
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +2 -190
- package/dist/commands/migration-log.d.mts +9 -19
- package/dist/commands/migration-log.d.mts.map +1 -1
- package/dist/commands/migration-log.mjs +1 -137
- package/dist/commands/migration-new.d.mts.map +1 -1
- package/dist/commands/migration-new.mjs +6 -5
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.d.mts +1 -1
- package/dist/commands/migration-plan.d.mts.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.d.mts +17 -21
- package/dist/commands/migration-show.d.mts.map +1 -1
- package/dist/commands/migration-show.mjs +24 -36
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +42 -144
- package/dist/commands/migration-status.d.mts.map +1 -1
- package/dist/commands/migration-status.mjs +3 -759
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.d.mts.map +1 -1
- package/dist/commands/ref.mjs +4 -4
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/commands/telemetry/index.d.mts +7 -0
- package/dist/commands/telemetry/index.d.mts.map +1 -0
- package/dist/commands/telemetry/index.mjs +2 -0
- package/dist/{config-loader-B6sJjXTv.mjs → config-loader-p9JMrekQ.mjs} +1 -1
- package/dist/{config-loader-B6sJjXTv.mjs.map → config-loader-p9JMrekQ.mjs.map} +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{contract-at-errors-BxP-TOMl.mjs → contract-at-errors-CFXsstzm.mjs} +2 -2
- package/dist/{contract-at-errors-BxP-TOMl.mjs.map → contract-at-errors-CFXsstzm.mjs.map} +1 -1
- package/dist/{contract-emit-DxcGl4Uq.mjs → contract-emit-B_qriF8B.mjs} +5 -5
- package/dist/{contract-emit-DxcGl4Uq.mjs.map → contract-emit-B_qriF8B.mjs.map} +1 -1
- package/dist/{contract-emit-D-4jrNve.mjs → contract-emit-C8HmtboH.mjs} +12 -7
- package/dist/contract-emit-C8HmtboH.mjs.map +1 -0
- package/dist/{contract-enrichment-a0V5Y_mL.mjs → contract-enrichment-gn9sWbPw.mjs} +1 -1
- package/dist/{contract-enrichment-a0V5Y_mL.mjs.map → contract-enrichment-gn9sWbPw.mjs.map} +1 -1
- package/dist/{contract-infer-D8uEbJuu.mjs → contract-infer-BYT_ra_U.mjs} +5 -5
- package/dist/contract-infer-BYT_ra_U.mjs.map +1 -0
- package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs → contract-space-aggregate-loader-ClI1KN6d.mjs} +5 -5
- package/dist/{contract-space-aggregate-loader-DvZwdkrr.mjs.map → contract-space-aggregate-loader-ClI1KN6d.mjs.map} +1 -1
- package/dist/{db-verify-v_vUKXTU.mjs → db-verify-C24FKhb7.mjs} +6 -6
- package/dist/{db-verify-v_vUKXTU.mjs.map → db-verify-C24FKhb7.mjs.map} +1 -1
- package/dist/exports/control-api.d.mts +5 -3
- package/dist/exports/control-api.d.mts.map +1 -1
- package/dist/exports/control-api.mjs +3 -3
- package/dist/exports/index.mjs +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/init-output.d.mts +1 -3
- package/dist/exports/init-output.d.mts.map +1 -1
- package/dist/exports/init-output.mjs +1 -1
- package/dist/{extension-pack-inputs-IDvjRCi3.mjs → extension-pack-inputs-1ySHqxKG.mjs} +1 -1
- package/dist/{extension-pack-inputs-IDvjRCi3.mjs.map → extension-pack-inputs-1ySHqxKG.mjs.map} +1 -1
- package/dist/{framework-components-fYXjz_in.mjs → framework-components-YVQHhPH7.mjs} +2 -2
- package/dist/{framework-components-fYXjz_in.mjs.map → framework-components-YVQHhPH7.mjs.map} +1 -1
- package/dist/{global-flags-DEHjV8_s.d.mts → global-flags-BpoOYtNZ.d.mts} +1 -1
- package/dist/{global-flags-DEHjV8_s.d.mts.map → global-flags-BpoOYtNZ.d.mts.map} +1 -1
- package/dist/{init-Cv9UzWL5.mjs → init-0HwB-Vh8.mjs} +5 -58
- package/dist/init-0HwB-Vh8.mjs.map +1 -0
- package/dist/{inspect-live-schema-C6ohV_oQ.mjs → inspect-live-schema-DF6IwcDl.mjs} +7 -5
- package/dist/inspect-live-schema-DF6IwcDl.mjs.map +1 -0
- package/dist/migration-check-soB5uZEQ.mjs +573 -0
- package/dist/migration-check-soB5uZEQ.mjs.map +1 -0
- package/dist/migration-cli.mjs +1 -1
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-CjvwO6at.mjs → migration-command-scaffold-DA-Lhx6o.mjs} +5 -5
- package/dist/{migration-command-scaffold-CjvwO6at.mjs.map → migration-command-scaffold-DA-Lhx6o.mjs.map} +1 -1
- package/dist/migration-graph-command-render-CEez7YUK.mjs +1960 -0
- package/dist/migration-graph-command-render-CEez7YUK.mjs.map +1 -0
- package/dist/migration-list-DlJJ_38Z.mjs +230 -0
- package/dist/migration-list-DlJJ_38Z.mjs.map +1 -0
- package/dist/migration-log-CG0qQAFm.mjs +222 -0
- package/dist/migration-log-CG0qQAFm.mjs.map +1 -0
- package/dist/migration-path-target-Ce6OZImp.mjs +38 -0
- package/dist/migration-path-target-Ce6OZImp.mjs.map +1 -0
- package/dist/{migration-plan-9DJ7q7_z.mjs → migration-plan-z5Ing-TD.mjs} +9 -8
- package/dist/migration-plan-z5Ing-TD.mjs.map +1 -0
- package/dist/migration-status-CgWSoI_g.mjs +446 -0
- package/dist/migration-status-CgWSoI_g.mjs.map +1 -0
- package/dist/{output-B60Gw5fu.mjs → output-mEQ74_nd.mjs} +1 -1
- package/dist/{output-B60Gw5fu.mjs.map → output-mEQ74_nd.mjs.map} +1 -1
- package/dist/{progress-adapter-C644QK8l.mjs → progress-adapter-CjAeTxY_.mjs} +1 -1
- package/dist/{progress-adapter-C644QK8l.mjs.map → progress-adapter-CjAeTxY_.mjs.map} +1 -1
- package/dist/{ref-advancement-DUZqsue6.mjs → ref-advancement-BkXlikCA.mjs} +1 -1
- package/dist/{ref-advancement-DUZqsue6.mjs.map → ref-advancement-BkXlikCA.mjs.map} +1 -1
- package/dist/schemas-CeGMYFYX.d.mts +191 -0
- package/dist/schemas-CeGMYFYX.d.mts.map +1 -0
- package/dist/schemas-KhXMzNA_.mjs +112 -0
- package/dist/schemas-KhXMzNA_.mjs.map +1 -0
- package/dist/telemetry-BIM4beEO.mjs +122 -0
- package/dist/telemetry-BIM4beEO.mjs.map +1 -0
- package/dist/{terminal-ui-5Y6mrg93.d.mts → terminal-ui-DGRNFWna.d.mts} +1 -1
- package/dist/terminal-ui-DGRNFWna.d.mts.map +1 -0
- package/dist/{types-Dt_SfqFm.d.mts → types-C_tYiJYx.d.mts} +53 -31
- package/dist/types-C_tYiJYx.d.mts.map +1 -0
- package/dist/{verify-DCA9Sldu.mjs → verify-DcOYZ1tH.mjs} +2 -2
- package/dist/{verify-DCA9Sldu.mjs.map → verify-DcOYZ1tH.mjs.map} +1 -1
- package/package.json +26 -22
- package/src/cli.ts +5 -0
- package/src/commands/contract-infer.ts +2 -2
- package/src/commands/db-update.ts +7 -1
- package/src/commands/init/index.ts +6 -35
- package/src/commands/init/init.ts +1 -14
- package/src/commands/init/inputs.ts +0 -75
- package/src/commands/inspect-live-schema.ts +10 -0
- package/src/commands/json/schemas.ts +195 -0
- package/src/commands/migrate.ts +527 -8
- package/src/commands/migration-check.ts +469 -134
- package/src/commands/migration-graph.ts +164 -91
- package/src/commands/migration-list.ts +72 -39
- package/src/commands/migration-log.ts +52 -102
- package/src/commands/migration-new.ts +2 -1
- package/src/commands/migration-plan.ts +2 -1
- package/src/commands/migration-show.ts +31 -66
- package/src/commands/migration-status-overlay.ts +61 -0
- package/src/commands/migration-status.ts +458 -1066
- package/src/commands/telemetry/index.ts +107 -0
- package/src/commands/telemetry/status.ts +67 -0
- package/src/control-api/client.ts +70 -9
- package/src/control-api/operations/contract-emit.ts +22 -2
- package/src/control-api/operations/db-init.ts +6 -3
- package/src/control-api/operations/{db-apply.ts → db-run.ts} +55 -14
- package/src/control-api/operations/db-update.ts +7 -4
- package/src/control-api/operations/db-verify.ts +15 -5
- package/src/control-api/operations/{migration-apply.ts → migrate.ts} +181 -80
- package/src/control-api/operations/{apply.ts → run-migration.ts} +33 -27
- package/src/control-api/types.ts +56 -29
- package/src/utils/cli-errors.ts +70 -2
- package/src/utils/formatters/errors.ts +11 -0
- package/src/utils/formatters/migration-graph-command-render.ts +239 -0
- package/src/utils/formatters/migration-graph-grid-layout.ts +1134 -0
- package/src/utils/formatters/migration-graph-labels.ts +408 -0
- package/src/utils/formatters/migration-graph-model.ts +103 -0
- package/src/utils/formatters/migration-graph-occlusion-render.ts +258 -0
- package/src/utils/formatters/migration-graph-rows.ts +128 -15
- package/src/utils/formatters/migration-graph-space-render.ts +188 -0
- package/src/utils/formatters/migration-list-data-column.ts +4 -91
- package/src/utils/formatters/migration-list-graph-topology.ts +72 -94
- package/src/utils/formatters/migration-list-render.ts +135 -71
- package/src/utils/formatters/migration-list-styler.ts +46 -5
- package/src/utils/formatters/migration-list-types.ts +5 -21
- package/src/utils/formatters/migration-log-table.ts +205 -0
- package/src/utils/formatters/migrations.ts +33 -11
- package/src/utils/global-flags.ts +35 -0
- package/src/utils/integrity-violation-to-check-failure.ts +28 -19
- package/src/utils/legend.ts +38 -0
- package/src/utils/migration-path-target.ts +60 -0
- package/src/utils/telemetry.ts +68 -32
- package/dist/client-KgJorIvG.mjs.map +0 -1
- package/dist/command-helpers-Bbw1GbwL.mjs.map +0 -1
- package/dist/commands/migration-list.mjs.map +0 -1
- package/dist/commands/migration-log.mjs.map +0 -1
- package/dist/commands/migration-status.mjs.map +0 -1
- package/dist/contract-emit-D-4jrNve.mjs.map +0 -1
- package/dist/contract-infer-D8uEbJuu.mjs.map +0 -1
- package/dist/graph-render-rFAqZujX.mjs +0 -1081
- package/dist/graph-render-rFAqZujX.mjs.map +0 -1
- package/dist/init-Cv9UzWL5.mjs.map +0 -1
- package/dist/inspect-live-schema-C6ohV_oQ.mjs.map +0 -1
- package/dist/migration-check-BiBJoYYW.mjs +0 -341
- package/dist/migration-check-BiBJoYYW.mjs.map +0 -1
- package/dist/migration-graph-D7DVUElV.mjs +0 -1232
- package/dist/migration-graph-D7DVUElV.mjs.map +0 -1
- package/dist/migration-list-styler-BRwF4-gy.mjs +0 -399
- package/dist/migration-list-styler-BRwF4-gy.mjs.map +0 -1
- package/dist/migration-plan-9DJ7q7_z.mjs.map +0 -1
- package/dist/migration-types-D2FW63pr.d.mts +0 -15
- package/dist/migration-types-D2FW63pr.d.mts.map +0 -1
- package/dist/migrations-Cv2jxNNK.mjs +0 -228
- package/dist/migrations-Cv2jxNNK.mjs.map +0 -1
- package/dist/terminal-ui-5Y6mrg93.d.mts.map +0 -1
- package/dist/types-Dt_SfqFm.d.mts.map +0 -1
- package/src/utils/formatters/graph-migration-mapper.ts +0 -235
- package/src/utils/formatters/graph-render.ts +0 -1323
- package/src/utils/formatters/graph-types.ts +0 -120
- package/src/utils/formatters/migration-graph-layout.ts +0 -1119
- package/src/utils/formatters/migration-graph-tree-render.ts +0 -459
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../src/commands/migrate.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { createControlStack } from '@prisma-next/framework-components/control';\nimport { errorUnknownInvariant, MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport { findLatestMigration, isGraphNode } from '@prisma-next/migration-tools/migration-graph';\nimport { parseContractRef } from '@prisma-next/migration-tools/ref-resolution';\nimport type { RefEntry } from '@prisma-next/migration-tools/refs';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport type {\n MigrationApplyFailure,\n MigrationApplyPathDecision,\n PerSpaceExecutionEntry,\n} from '../control-api/types';\nimport {\n CliStructuredError,\n type CliStructuredError as CliStructuredErrorType,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorMarkerMismatch,\n errorPathUnreachable,\n errorRuntime,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n mapMigrationToolsError,\n mapRefResolutionError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n collectDeclaredInvariants,\n maskConnectionUrl,\n resolveContractPath,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n targetSupportsMigrations,\n} from '../utils/command-helpers';\nimport { mapContractAtError } from '../utils/contract-at-errors';\nimport {\n loadContractSpaceAggregateForCli,\n refuseContractSpaceIntegrity,\n} from '../utils/contract-space-aggregate-loader';\nimport { toDeclaredExtensionsFromRaw } from '../utils/extension-pack-inputs';\nimport { formatMigrationApplyCommandOutput } from '../utils/formatters/migrations';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { executeRefAdvancement, readContractIR } from '../utils/ref-advancement';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrateCommandOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n readonly to?: string;\n readonly advanceRef?: string;\n}\n\nexport interface MigrateResult {\n readonly ok: boolean;\n readonly migrationsApplied: number;\n readonly migrationsTotal: number;\n readonly markerHash: string;\n readonly applied: readonly {\n readonly spaceId: string;\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly operationsExecuted: number;\n }[];\n readonly summary: string;\n readonly perSpace: readonly PerSpaceExecutionEntry[];\n readonly pathDecision?: MigrationApplyPathDecision;\n readonly timings: {\n readonly total: number;\n };\n readonly advancedRef?: { readonly name: string; readonly hash: string } | null;\n}\n\nfunction mapApplyFailure(failure: MigrationApplyFailure): CliStructuredErrorType {\n if (failure.code === 'MIGRATION_PATH_NOT_FOUND') {\n return errorPathUnreachable(failure);\n }\n return errorRuntime(failure.summary, {\n why: failure.why ?? 'Migration runner failed',\n fix: 'Fix the issue and re-run `prisma-next migrate --to <contract>` — previously applied migrations are preserved.',\n meta: failure.meta ?? {},\n });\n}\n\nasync function executeMigrateCommand(\n options: MigrateCommandOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrateResult, CliStructuredErrorType>> {\n const config = await loadConfig(options.config);\n const { configPath, migrationsDir, appMigrationsRelative, refsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for migrate (set db.connection in ${configPath}, or pass --db <url>)`,\n commandName: 'migrate',\n }),\n );\n }\n\n if (!config.driver) {\n return notOk(\n errorDriverRequired({\n why: 'Config.driver is required for migrate',\n }),\n );\n }\n\n if (!targetSupportsMigrations(config.target)) {\n return notOk(\n errorTargetMigrationNotSupported({\n why: `Target \"${config.target.id}\" does not support migrations`,\n }),\n );\n }\n\n const toArg = options.to;\n\n // Construct the family instance up-front so the on-disk contract read\n // crosses the serializer seam (`familyInstance.deserializeContract`) at\n // the read site. The downstream `client.migrationApply({ contract })`\n // re-validates internally (no harm — validation is idempotent), but\n // closing the gap at the read site is what makes the cast-pattern\n // lint enforceable and matches the other CLI commands. See TML-2536.\n const stack = createControlStack(config);\n const familyInstance = config.family.create(stack);\n\n const contractPathAbsolute = resolveContractPath(config);\n let contractRaw: Contract;\n let contractContent: string;\n try {\n contractContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n return notOk(\n errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n fix: 'Run `prisma-next contract emit` to generate a valid contract.json, then retry.',\n }),\n );\n }\n return notOk(\n errorContractValidationFailed(\n `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n try {\n contractRaw = familyInstance.deserializeContract(JSON.parse(contractContent) as unknown);\n } catch (error) {\n return notOk(\n errorContractValidationFailed(\n `Contract at ${contractPathAbsolute} failed to deserialize: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n\n const loadedAggregate = await loadContractSpaceAggregateForCli({\n targetId: config.target.targetId,\n migrationsDir,\n appContract: contractRaw,\n extensionPacks: config.extensionPacks ?? [],\n deserializeContract: (json) => familyInstance.deserializeContract(json),\n });\n if (!loadedAggregate.ok) {\n return notOk(loadedAggregate.failure);\n }\n const aggregate = loadedAggregate.value;\n const integrityFailure = refuseContractSpaceIntegrity(aggregate, {\n declaredExtensions: toDeclaredExtensionsFromRaw(\n (config.extensionPacks ?? []) as ReadonlyArray<unknown>,\n ),\n checkContracts: true,\n });\n if (integrityFailure) {\n return notOk(integrityFailure);\n }\n\n let refEntry: RefEntry | undefined;\n let refName: string | undefined;\n if (toArg) {\n const refs = aggregate.app.refs;\n const refResult = parseContractRef(toArg, { graph: aggregate.app.graph(), refs });\n if (!refResult.ok) {\n return notOk(mapRefResolutionError(refResult.failure));\n }\n if (refResult.value.provenance.kind === 'ref') {\n refName = refResult.value.provenance.refName;\n const resolved = refs[refName];\n if (resolved) refEntry = resolved;\n } else {\n refEntry = { hash: refResult.value.hash, invariants: [] };\n }\n }\n\n if (!flags.json && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ];\n if (typeof dbConnection === 'string') {\n details.push({\n label: 'database',\n value: maskConnectionUrl(dbConnection),\n });\n }\n if (toArg) {\n details.push({ label: 'to', value: toArg });\n }\n const header = formatStyledHeader({\n command: 'migrate',\n description: 'Apply planned migrations to advance the database',\n url: 'https://pris.ly/migrate',\n details,\n flags,\n });\n ui.stderr(header);\n }\n\n const appGraph = aggregate.app.graph();\n\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n try {\n await client.connect(dbConnection);\n\n const allMarkers = await client.readAllMarkers();\n const appMarker = allMarkers.get('app') ?? null;\n\n if (appMarker !== null && !isGraphNode(appMarker.storageHash, appGraph)) {\n return notOk(\n errorMarkerMismatch(\n appMarker.storageHash,\n [...appGraph.nodes].sort(),\n findLatestMigration(appGraph)?.to ?? null,\n ),\n );\n }\n\n if (refEntry && refEntry.invariants.length > 0) {\n const declared = collectDeclaredInvariants(appGraph);\n const known = new Set<string>(declared);\n for (const id of appMarker?.invariants ?? []) known.add(id);\n const unknown = refEntry.invariants.filter((id) => !known.has(id));\n if (unknown.length > 0) {\n return notOk(\n mapMigrationToolsError(\n errorUnknownInvariant({\n ...ifDefined('refName', toArg),\n unknown,\n declared: [...declared].sort(),\n }),\n ),\n );\n }\n }\n\n if (!flags.quiet && !flags.json) {\n ui.step('Loading contract spaces…');\n }\n\n // When `--to` resolves to an on-disk graph node with a matching bundle,\n // verify and apply against THAT bundle's destination contract via\n // `contractAt` — not the emitted `contract.json`. With `--to` omitted,\n // or a target with no matching bundle, the emitted contract stays the\n // apply contract (the only migrate-specific default). The same\n // `contractAt` artifacts feed the optional ref-advancement snapshot.\n let applyContract: Contract = contractRaw;\n let snapshotContractJson: Record<string, unknown> = JSON.parse(contractContent);\n let snapshotContractDts: string | undefined;\n if (toArg && refEntry) {\n const targetHash = refEntry.hash;\n const matchingBundle = aggregate.app.packages.find((p) => p.metadata.to === targetHash);\n if (matchingBundle) {\n try {\n const at = await aggregate.app.contractAt(\n targetHash,\n refName !== undefined ? { refName } : undefined,\n );\n applyContract = at.contract;\n snapshotContractJson = at.contractJson as Record<string, unknown>;\n snapshotContractDts = at.contractDts;\n } catch (error) {\n return mapContractAtError(error, { artifactRole: 'to' });\n }\n }\n }\n\n const applyResult = await client.migrationApply({\n contract: applyContract,\n migrationsDir,\n ...ifDefined('refHash', refEntry?.hash),\n ...(refEntry?.invariants ? { refInvariants: refEntry.invariants } : {}),\n ...(refEntry !== undefined ? ifDefined('refName', toArg) : {}),\n });\n\n if (!applyResult.ok) {\n return notOk(mapApplyFailure(applyResult.failure));\n }\n\n const { value } = applyResult;\n\n let advancedRef: { name: string; hash: string } | null = null;\n if (options.advanceRef !== undefined) {\n try {\n const contractIR =\n snapshotContractDts !== undefined\n ? { contract: snapshotContractJson, contractDts: snapshotContractDts }\n : await readContractIR(snapshotContractJson, contractPathAbsolute);\n advancedRef = await executeRefAdvancement(\n refsDir,\n options.advanceRef,\n value.markerHash,\n contractIR,\n );\n } catch (error) {\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n throw error;\n }\n }\n\n return ok({\n ok: true,\n migrationsApplied: value.migrationsApplied,\n migrationsTotal: value.perSpace.length,\n markerHash: value.markerHash,\n applied: value.applied,\n summary: value.summary,\n perSpace: value.perSpace,\n ...ifDefined('pathDecision', value.pathDecision),\n timings: { total: Date.now() - startTime },\n advancedRef,\n });\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during migrate: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createMigrateCommand(): Command {\n const command = new Command('migrate');\n setCommandDescriptions(\n command,\n 'Apply planned migrations to advance the database',\n 'Walks every contract space (app + extensions) and applies pending\\n' +\n 'on-disk migrations in canonical order (extensions alphabetically,\\n' +\n 'then app). Graph-walks the on-disk migration graph for every space.\\n' +\n 'Use --to to target a specific contract (hash, ref name, migration dir).',\n );\n setCommandExamples(command, [\n 'prisma-next migrate --db $DATABASE_URL',\n 'prisma-next migrate --to production --db $DATABASE_URL',\n 'prisma-next migrate --to sha256:abc123 --db $DATABASE_URL',\n ]);\n addGlobalOptions(command)\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option(\n '--to <contract>',\n 'Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)',\n )\n .option('--advance-ref <name>', 'Advance the named ref to the post-apply marker after success')\n .action(async (options: MigrateCommandOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const startTime = Date.now();\n\n const ui = createTerminalUI(flags);\n\n const result = await executeMigrateCommand(options, flags, ui, startTime);\n\n const exitCode = handleResult(result, flags, ui, (migrateResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(migrateResult, null, 2));\n } else if (!flags.quiet) {\n ui.log(formatMigrationApplyCommandOutput(migrateResult, flags));\n }\n });\n\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqFA,SAAS,gBAAgB,SAAwD;CAC/E,IAAI,QAAQ,SAAS,4BACnB,OAAO,qBAAqB,OAAO;CAErC,OAAO,aAAa,QAAQ,SAAS;EACnC,KAAK,QAAQ,OAAO;EACpB,KAAK;EACL,MAAM,QAAQ,QAAQ,CAAC;CACzB,CAAC;AACH;AAEA,eAAe,sBACb,SACA,OACA,IACA,WACwD;CACxD,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,EAAE,YAAY,eAAe,uBAAuB,YAAY,sBACpE,QAAQ,QACR,MACF;CAEA,MAAM,eAAe,QAAQ,MAAM,OAAO,IAAI;CAC9C,IAAI,CAAC,cACH,OAAO,MACL,gCAAgC;EAC9B,KAAK,qEAAqE,WAAW;EACrF,aAAa;CACf,CAAC,CACH;CAGF,IAAI,CAAC,OAAO,QACV,OAAO,MACL,oBAAoB,EAClB,KAAK,wCACP,CAAC,CACH;CAGF,IAAI,CAAC,yBAAyB,OAAO,MAAM,GACzC,OAAO,MACL,iCAAiC,EAC/B,KAAK,WAAW,OAAO,OAAO,GAAG,+BACnC,CAAC,CACH;CAGF,MAAM,QAAQ,QAAQ;CAQtB,MA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,MAAM,WAAW,aAAa,MAFT,sBAAsB,SAAS,OAAO,IAAI,SAAS,GAElC,OAAO,KAAK,kBAAkB;GAClE,IAAI,MAAM,MACR,GAAG,OAAO,KAAK,UAAU,eAAe,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,OAChB,GAAG,IAAI,kCAAkC,eAAe,KAAK,CAAC;EAElE,CAAC;EAED,QAAQ,KAAK,QAAQ;CACvB,CAAC;CAEH,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../src/commands/migrate.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { createControlStack } from '@prisma-next/framework-components/control';\nimport { type ContractSpaceMember, requireHeadRef } from '@prisma-next/migration-tools/aggregate';\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { errorUnknownInvariant, MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport { findLatestMigration, isGraphNode } from '@prisma-next/migration-tools/migration-graph';\nimport { parseContractRef } from '@prisma-next/migration-tools/ref-resolution';\nimport type { RefEntry, Refs } from '@prisma-next/migration-tools/refs';\nimport { readRefs } from '@prisma-next/migration-tools/refs';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport { planMemberPath } from '../control-api/operations/migrate';\nimport type {\n MigrateFailure,\n MigratePathDecision,\n PerSpaceExecutionEntry,\n} from '../control-api/types';\nimport {\n CliStructuredError,\n type CliStructuredError as CliStructuredErrorType,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorMarkerMismatch,\n errorPathUnreachable,\n errorRuntime,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n mapMigrationToolsError,\n mapRefResolutionError,\n requireLiveDatabase,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n collectDeclaredInvariants,\n maskConnectionUrl,\n resolveContractPath,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n targetSupportsMigrations,\n} from '../utils/command-helpers';\nimport { mapContractAtError } from '../utils/contract-at-errors';\nimport {\n buildReadAggregate,\n loadContractSpaceAggregateForCli,\n refuseContractSpaceIntegrity,\n} from '../utils/contract-space-aggregate-loader';\nimport { toDeclaredExtensionsFromRaw } from '../utils/extension-pack-inputs';\nimport {\n computeLabelColumn,\n computeMaxDirNameWidth,\n renderMigrationGraphCommand,\n} from '../utils/formatters/migration-graph-command-render';\nimport { buildGrid } from '../utils/formatters/migration-graph-grid-layout';\nimport {\n formatOnPathMigrationRow,\n type MigrationEdgeAnnotation,\n} from '../utils/formatters/migration-graph-labels';\nimport { buildMigrationGraphRows } from '../utils/formatters/migration-graph-rows';\nimport {\n highlightFromEdgeAnnotations,\n indentMigrationGraphTreeBlock,\n} from '../utils/formatters/migration-graph-space-render';\nimport { formatMigrationApplyCommandOutput } from '../utils/formatters/migrations';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { executeRefAdvancement, readContractIR } from '../utils/ref-advancement';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\nimport { listRefsByContractHash } from './migration-list';\n\ninterface MigrateCommandOptions extends CommonCommandOptions {\n readonly db?: string;\n readonly config?: string;\n readonly to?: string;\n readonly advanceRef?: string;\n readonly show?: boolean;\n readonly from?: string;\n}\n\n/**\n * One migration that will run in a `migrate --show` preview, in execution order.\n */\nexport interface MigrateShowMigration {\n readonly spaceId: string;\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n}\n\n/** Result returned by `migrate --show`. Read-only; no writes performed. */\nexport interface MigrateShowResult {\n readonly ok: true;\n readonly migrations: readonly MigrateShowMigration[];\n readonly summary: string;\n /**\n * Pre-rendered Tier-3 graph tree for human output. Off-path migrations render\n * dim; on-path migrations render in ordinary colours. Only present in human\n * (non-JSON) mode.\n */\n readonly graphOutput?: string;\n /**\n * Name column width for the \"Will run, in order:\" list — globally aligned with\n * every graph-tree section. Only present in human (non-JSON) mode.\n */\n readonly runListDirNameWidth?: number;\n /**\n * Left-pad offset (number of blank spaces) matching the graph's data-column\n * offset (`globalMaxEdgeTreePrefixWidth`). Used to align list rows with graph\n * rows so every `→` in the output (graph + list) lands at the same column.\n * Only present in human (non-JSON) mode when multiple spaces are rendered.\n */\n readonly runListLeftPad?: number;\n}\n\nexport interface MigrateResult {\n readonly ok: boolean;\n readonly migrationsApplied: number;\n readonly migrationsTotal: number;\n readonly markerHash: string;\n readonly applied: readonly {\n readonly spaceId: string;\n readonly dirName: string;\n readonly migrationHash: string;\n readonly from: string;\n readonly to: string;\n readonly operationsExecuted: number;\n }[];\n readonly summary: string;\n readonly perSpace: readonly PerSpaceExecutionEntry[];\n readonly pathDecision?: MigratePathDecision;\n readonly timings: {\n readonly total: number;\n };\n readonly advancedRef?: { readonly name: string; readonly hash: string } | null;\n}\n\n/**\n * Read-only preview of the migration path `migrate` will take.\n *\n * Computes the path through the SAME seam as `executeMigrate`:\n * - `readAllMarkers()` for the from-state (when no `--from` is given), preserving\n * the full marker including `invariants` (not just `storageHash`).\n * - `planMemberPath()` (shared with `executeMigrate`) for per-member path selection,\n * which feeds `graphWalkStrategy()` with the same target hash, target invariants,\n * and current marker as the real apply path uses.\n *\n * Returns BEFORE any write boundary (`runMigration` / marker / DDL). No\n * DB state is mutated.\n */\nasync function executeMigrateShowCommand(\n options: MigrateCommandOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrateShowResult, CliStructuredErrorType>> {\n const config = await loadConfig(options.config);\n const { configPath, migrationsDir, migrationsRelative, refsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const dbConnection = options.db ?? config.db?.connection;\n const hasDriver = !!config.driver;\n const hasExplicitFrom = options.from !== undefined;\n\n // When --from is omitted we read the live DB marker (same as migrate's default).\n // When --from is given, we're in offline hypothetical mode — no connection needed.\n if (!hasExplicitFrom) {\n const missingDb = requireLiveDatabase({\n dbConnection,\n hasDriver,\n why: 'migrate --show needs a database connection to read the live marker (or pass --from <contract> for an offline preview)',\n retryCommand: 'prisma-next migrate --show --from <contract>',\n });\n if (missingDb) {\n return notOk(missingDb);\n }\n }\n\n let allRefs: Refs = {};\n try {\n allRefs = await readRefs(refsDir);\n } catch (error) {\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n throw error;\n }\n\n const loaded = await buildReadAggregate(config, { migrationsDir });\n if (!loaded.ok) {\n return notOk(loaded.failure);\n }\n const { aggregate, contractHash } = loaded.value;\n const appGraph = aggregate.app.graph();\n\n // Resolve the --to target (defaults to the on-disk contract, same as migrate).\n // Also capture the ref's invariants so planMemberPath feeds graphWalkStrategy the\n // same target invariants that real migrate would use (refInvariants ?? headRef.invariants).\n let targetHash: string = contractHash;\n let refInvariants: readonly string[] | undefined;\n if (options.to) {\n const toResult = parseContractRef(options.to, {\n graph: appGraph,\n refs: allRefs,\n contractHash,\n });\n if (!toResult.ok) {\n return notOk(mapRefResolutionError(toResult.failure));\n }\n if (toResult.value.provenance.kind === 'reserved-db') {\n return notOk(\n errorDatabaseConnectionRequired({\n why: '@db is not valid as a --to target; it names the live database state, not a target contract.',\n commandName: 'migrate --show',\n }),\n );\n }\n targetHash = toResult.value.hash;\n if (toResult.value.provenance.kind === 'ref') {\n const refEntry = allRefs[toResult.value.provenance.refName];\n if (refEntry) refInvariants = refEntry.invariants;\n }\n }\n\n if (!flags.json && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'migrations', value: migrationsRelative },\n ];\n if (dbConnection && !hasExplicitFrom) {\n details.push({ label: 'database', value: maskConnectionUrl(String(dbConnection)) });\n }\n if (options.from) {\n details.push({ label: 'from', value: options.from });\n }\n if (options.to) {\n details.push({ label: 'to', value: options.to });\n }\n const header = formatStyledHeader({\n command: 'migrate --show',\n description: 'Preview the migration path migrate will take (read-only)',\n details,\n flags,\n });\n ui.stderr(header);\n }\n\n // Resolve the from-state.\n // - Explicit --from: parse it offline (no connection).\n // - Omitted: read the live DB marker via readAllMarkers() — the same source migrate uses.\n //\n // Full marker records (storageHash + invariants) are preserved so planMemberPath\n // can feed graphWalkStrategy the complete currentMarker — exactly as executeMigrate\n // does via familyInstance.readAllMarkers(). A stripped { storageHash, invariants: [] }\n // marker would produce a different `required` set and a different (incorrect) path.\n type LiveMarker = { readonly storageHash: string; readonly invariants: readonly string[] };\n const markerBySpace = new Map<string, LiveMarker | null>();\n const allMembers: ReadonlyArray<ContractSpaceMember> = [aggregate.app, ...aggregate.extensions];\n\n if (hasExplicitFrom) {\n // @db with explicit --from requires a connection\n if (options.from === '@db') {\n const missingDb = requireLiveDatabase({\n dbConnection,\n hasDriver,\n why: '@db resolves to the live database marker and requires a --db connection',\n retryCommand: 'prisma-next migrate --show --from @db --db $DATABASE_URL',\n });\n if (missingDb) {\n return notOk(missingDb);\n }\n // Fall through to the connection path below\n } else {\n const fromResult = parseContractRef(options.from, {\n graph: appGraph,\n refs: allRefs,\n contractHash,\n });\n if (!fromResult.ok) {\n return notOk(mapRefResolutionError(fromResult.failure));\n }\n if (fromResult.value.provenance.kind === 'reserved-db') {\n // Unreachable given the @db branch above, but guard for safety\n const missingDb = requireLiveDatabase({\n dbConnection,\n hasDriver,\n why: '@db resolves to the live database marker and requires a --db connection',\n });\n if (missingDb) {\n return notOk(missingDb);\n }\n } else {\n // Offline hypothetical: the --from ref only carries a hash (no live invariants).\n // Apply the from-hash marker to the APP space only. Extension spaces are left\n // absent from markerBySpace (treated as null / greenfield by planMemberPath),\n // so they plan from their own marker → own head — exactly as executeMigrate does.\n const fromHash = fromResult.value.hash;\n const offlineMarker: LiveMarker | null =\n fromHash === EMPTY_CONTRACT_HASH ? null : { storageHash: fromHash, invariants: [] };\n markerBySpace.set(aggregate.app.spaceId, offlineMarker);\n }\n }\n }\n\n // If we need the live DB marker (no --from, or --from @db), connect and read.\n const needsLiveMarker = !hasExplicitFrom || options.from === '@db';\n if (needsLiveMarker) {\n if (!dbConnection || !hasDriver) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: 'A database connection is required to read the live marker for migrate --show',\n commandName: 'migrate --show',\n }),\n );\n }\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver!,\n extensionPacks: config.extensionPacks ?? [],\n });\n try {\n await client.connect(dbConnection);\n const allMarkers = await client.readAllMarkers();\n // Store the full marker record (storageHash + invariants) per space.\n // This is the same data executeMigrate uses via familyInstance.readAllMarkers().\n for (const member of allMembers) {\n const marker = allMarkers.get(member.spaceId);\n markerBySpace.set(member.spaceId, marker ?? null);\n }\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read live DB marker: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n }\n\n // Walk the path via planMemberPath — the same helper executeMigrate uses.\n // planMemberPath feeds graphWalkStrategy identical inputs (targetHash, targetInvariants,\n // currentMarker with full invariants), so the preview path is always the path migrate runs.\n //\n // Canonical schedule order: extensions alphabetically first, then app — mirroring the\n // runner's `applyOrder` in operations/migrate.ts so the \"Will run, in order:\" list\n // reflects the actual execution sequence (extensions install first, app last).\n const canonicalOrderMembers: ReadonlyArray<ContractSpaceMember> = [\n ...aggregate.extensions,\n aggregate.app,\n ];\n const orderedMigrations: MigrateShowMigration[] = [];\n for (const member of canonicalOrderMembers) {\n const isAppMember = member.spaceId === aggregate.app.spaceId;\n const headRef = requireHeadRef(member);\n const memberTargetHash = isAppMember ? targetHash : headRef.hash;\n const memberRefInvariants = isAppMember ? refInvariants : undefined;\n const liveMarker = markerBySpace.get(member.spaceId) ?? null;\n\n const outcome = planMemberPath({\n member,\n aggregate,\n targetHash: memberTargetHash,\n refInvariants: memberRefInvariants,\n liveMarker,\n });\n\n if (outcome.kind === 'at-head') {\n // Empty-graph member already at target — nothing to run for this space.\n continue;\n }\n if (outcome.kind === 'never-planned') {\n return notOk(\n errorPathUnreachable({\n code: 'MIGRATION_PATH_NOT_FOUND',\n summary: `No on-disk migrations for contract space \"${outcome.spaceId}\"`,\n why: `migrate is replay-only: space \"${outcome.spaceId}\" has no on-disk migrations but its head ref targets \"${outcome.targetHash}\".`,\n meta: { spaceId: outcome.spaceId, target: outcome.targetHash, kind: 'neverPlanned' },\n }),\n );\n }\n if (outcome.kind === 'unreachable') {\n const fromHash = outcome.liveMarker?.storageHash ?? EMPTY_CONTRACT_HASH;\n return notOk(\n errorPathUnreachable({\n code: 'MIGRATION_PATH_NOT_FOUND',\n summary: `No migration path from ${fromHash.slice(0, 14)} to ${outcome.targetHash.slice(0, 14)} in space \"${outcome.spaceId}\".`,\n why: `The migration graph has no path from the from-state to the target in space \"${outcome.spaceId}\".`,\n meta: { spaceId: outcome.spaceId, from: fromHash, to: outcome.targetHash },\n }),\n );\n }\n if (outcome.kind === 'unsatisfiable') {\n return notOk(\n errorRuntime(`Missing required invariants for space \"${outcome.spaceId}\"`, {\n why: `The path requires invariants not available on disk: ${outcome.missing.join(', ')}`,\n }),\n );\n }\n\n for (const edge of outcome.plan.migrationEdges) {\n orderedMigrations.push({\n spaceId: member.spaceId,\n dirName: edge.dirName,\n migrationHash: edge.migrationHash,\n from: edge.from,\n to: edge.to,\n });\n }\n }\n\n const count = orderedMigrations.length;\n const summary =\n count === 0\n ? 'Already up to date — nothing to run'\n : `${count} migration${count === 1 ? '' : 's'} will run`;\n\n // Build the Tier-3 graph visualization (human mode only; skipped for --json).\n // Reuses the existing annotation hook — no parallel renderer.\n let graphOutput: string | undefined;\n let runListDirNameWidth: number | undefined;\n let runListLeftPad: number | undefined;\n if (!flags.json) {\n const onPathHashes = new Set(orderedMigrations.map((m) => m.migrationHash));\n const colorize = flags.color !== false;\n\n // Build layouts for all spaces first so we can compute global column widths\n // before rendering. This ensures the name column, hash column, and ops column\n // start at the same horizontal offset across every space section AND the\n // \"Will run, in order:\" list below.\n const memberLayouts = allMembers.map((member) => {\n const isApp = member.spaceId === aggregate.app.spaceId;\n const memberGraph = member.graph();\n const rowModel = buildMigrationGraphRows(memberGraph, isApp ? { contractHash } : {});\n const edgeAnnotations = new Map<string, MigrationEdgeAnnotation>();\n for (const edge of memberGraph.migrationByHash.values()) {\n edgeAnnotations.set(edge.migrationHash, {\n pathHighlight: onPathHashes.has(edge.migrationHash) ? 'on-path' : 'off-path',\n });\n }\n // The on-path migration set lifts to focus mode so the chosen route draws\n // green/continuous; off-path lanes dim. Rows, gutter, and labels all come\n // from this one grid.\n const grid = buildGrid(rowModel, {}, highlightFromEdgeAnnotations(edgeAnnotations));\n return { member, isApp, memberGraph, rowModel, grid, edgeAnnotations };\n });\n\n // Global max across all space grids so every section's labels share columns.\n const globalLabelColumn =\n memberLayouts.length > 1\n ? Math.max(...memberLayouts.map(({ grid }) => computeLabelColumn(grid, 'unicode')))\n : undefined;\n const globalMaxDirNameWidthFromLayouts =\n memberLayouts.length > 1\n ? Math.max(...memberLayouts.map(({ rowModel }) => computeMaxDirNameWidth(rowModel)))\n : undefined;\n // The run-list name column width must be at least as wide as the global tree dirName\n // width so that tree sections and the list align at the hash column.\n const runListMaxFromMigrations =\n orderedMigrations.length > 0\n ? Math.max(...orderedMigrations.map((m) => m.dirName.length))\n : 0;\n const globalMaxDirNameWidth =\n globalMaxDirNameWidthFromLayouts !== undefined\n ? Math.max(globalMaxDirNameWidthFromLayouts, runListMaxFromMigrations)\n : undefined;\n runListDirNameWidth = globalMaxDirNameWidth ?? runListMaxFromMigrations;\n runListLeftPad = globalLabelColumn;\n\n // Render each space section with globally computed widths.\n const showSpaceHeadings = allMembers.length > 1;\n const sections: string[] = [];\n for (const { member, isApp, rowModel, grid, edgeAnnotations } of memberLayouts) {\n const liveMarker = markerBySpace.get(member.spaceId) ?? null;\n const liveMarkerHash = liveMarker?.storageHash ?? EMPTY_CONTRACT_HASH;\n const tree = renderMigrationGraphCommand({\n grid,\n rowModel,\n contractHash,\n isAppSpace: isApp,\n ...(needsLiveMarker ? { dbHash: liveMarkerHash } : {}),\n refsByHash: listRefsByContractHash(member),\n edgeAnnotationsByHash: edgeAnnotations,\n colorize,\n glyphMode: 'unicode',\n ...(globalLabelColumn !== undefined ? { globalLabelColumn } : {}),\n ...(globalMaxDirNameWidth !== undefined ? { globalMaxDirNameWidth } : {}),\n });\n if (tree.length === 0) continue;\n if (showSpaceHeadings) {\n sections.push(`${member.spaceId}:\\n${indentMigrationGraphTreeBlock(tree, ' ')}`);\n } else {\n sections.push(tree);\n }\n }\n graphOutput = sections.join('\\n\\n');\n }\n\n return ok({\n ok: true,\n migrations: orderedMigrations,\n summary,\n ...(graphOutput !== undefined ? { graphOutput } : {}),\n ...(runListDirNameWidth !== undefined ? { runListDirNameWidth } : {}),\n ...(runListLeftPad !== undefined ? { runListLeftPad } : {}),\n });\n}\n\nfunction formatMigrateShowOutput(result: MigrateShowResult, flags: GlobalFlags): string {\n if (flags.quiet) return '';\n const colorize = flags.color !== false;\n const lines: string[] = [];\n // Graph tree first (shows the full topology with on-path highlighted).\n if (result.graphOutput !== undefined && result.graphOutput.length > 0) {\n lines.push(result.graphOutput);\n lines.push('');\n }\n const n = result.migrations.length;\n if (n > 0) {\n // Consolidated header: one line replaces the old separate summary + blank +\n // \"Will run, in order:\" header.\n lines.push(`The following ${n} migration${n === 1 ? '' : 's'} will run:`);\n // Ordered list rendered through the SAME on-path row renderer as the tree.\n // `formatOnPathMigrationRow` uses PATH_HIGHLIGHT_STYLES.onPath so the list and\n // graph-tree rows are styled identically — changing the on-path colour in future\n // is a one-line edit in PATH_HIGHLIGHT_STYLES.\n //\n // Alignment anchor: the `→` arrow (source-hash onward) must land at the SAME\n // absolute column as in graph edge rows, across every graph section and this list.\n //\n // Multi-space output layout (space headings + 2-space indented tree sections):\n // Graph edge row: [2 heading][G gutter][D dirName][7 source] [→] [dest]\n // List row: [2 spaces][L dirName][ ][7 source] [→] [dest]\n // Alignment: 2 + G + D + 9 = 2 + L + 2 + 9 => L = G + D - 2\n //\n // Single-space output layout (flat tree, no heading indent):\n // Graph edge row: [G gutter][D dirName][7 source] [→] [dest]\n // List row: [2 spaces][L dirName][ ][7 source] [→] [dest]\n // Alignment: G + D + 9 = 2 + L + 2 + 9 => L = G + D - 4\n //\n // D (edgeDirNameWidth) = max(rawDirNameWidth + LABEL_GAP, MIN_HASH_DATA_COLUMN - G)\n // where LABEL_GAP = 2 and MIN_HASH_DATA_COLUMN = 25 (same constants as the renderer).\n //\n // runListLeftPad is set only for multi-space; undefined means single-space.\n const isMultiSpace = result.runListLeftPad !== undefined;\n const gutter = result.runListLeftPad ?? 0;\n const rawDirNameWidth =\n result.runListDirNameWidth ?? Math.max(...result.migrations.map((m) => m.dirName.length));\n const edgeDirNameWidth = Math.max(rawDirNameWidth + 2, 25 - gutter);\n const listDirNameWidth = gutter + edgeDirNameWidth - (isMultiSpace ? 2 : 4);\n for (const m of result.migrations) {\n lines.push(\n ` ${formatOnPathMigrationRow(m.dirName, m.from, m.to, listDirNameWidth, colorize, 'unicode')}`,\n );\n }\n } else {\n lines.push(result.summary);\n }\n return lines.join('\\n');\n}\n\nfunction mapApplyFailure(failure: MigrateFailure): CliStructuredErrorType {\n if (failure.code === 'MIGRATION_PATH_NOT_FOUND') {\n return errorPathUnreachable(failure);\n }\n return errorRuntime(failure.summary, {\n why: failure.why ?? 'Migration runner failed',\n fix: 'Fix the issue and re-run `prisma-next migrate --to <contract>` — previously applied migrations are preserved.',\n meta: failure.meta ?? {},\n });\n}\n\nasync function executeMigrateCommand(\n options: MigrateCommandOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrateResult, CliStructuredErrorType>> {\n const config = await loadConfig(options.config);\n const { configPath, migrationsDir, appMigrationsRelative, refsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for migrate (set db.connection in ${configPath}, or pass --db <url>)`,\n commandName: 'migrate',\n }),\n );\n }\n\n if (!config.driver) {\n return notOk(\n errorDriverRequired({\n why: 'Config.driver is required for migrate',\n }),\n );\n }\n\n if (!targetSupportsMigrations(config.target)) {\n return notOk(\n errorTargetMigrationNotSupported({\n why: `Target \"${config.target.id}\" does not support migrations`,\n }),\n );\n }\n\n const toArg = options.to;\n\n // Construct the family instance up-front so the on-disk contract read\n // crosses the serializer seam (`familyInstance.deserializeContract`) at\n // the read site. The downstream `client.migrate({ contract })`\n // re-validates internally (no harm — validation is idempotent), but\n // closing the gap at the read site is what makes the cast-pattern\n // lint enforceable and matches the other CLI commands. See TML-2536.\n const stack = createControlStack(config);\n const familyInstance = config.family.create(stack);\n\n const contractPathAbsolute = resolveContractPath(config);\n let contractRaw: Contract;\n let contractContent: string;\n try {\n contractContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n return notOk(\n errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n fix: 'Run `prisma-next contract emit` to generate a valid contract.json, then retry.',\n }),\n );\n }\n return notOk(\n errorContractValidationFailed(\n `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n try {\n contractRaw = familyInstance.deserializeContract(JSON.parse(contractContent) as unknown);\n } catch (error) {\n return notOk(\n errorContractValidationFailed(\n `Contract at ${contractPathAbsolute} failed to deserialize: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n\n const loadedAggregate = await loadContractSpaceAggregateForCli({\n targetId: config.target.targetId,\n migrationsDir,\n appContract: contractRaw,\n extensionPacks: config.extensionPacks ?? [],\n deserializeContract: (json) => familyInstance.deserializeContract(json),\n });\n if (!loadedAggregate.ok) {\n return notOk(loadedAggregate.failure);\n }\n const aggregate = loadedAggregate.value;\n const integrityFailure = refuseContractSpaceIntegrity(aggregate, {\n declaredExtensions: toDeclaredExtensionsFromRaw(\n (config.extensionPacks ?? []) as ReadonlyArray<unknown>,\n ),\n checkContracts: true,\n });\n if (integrityFailure) {\n return notOk(integrityFailure);\n }\n\n let refEntry: RefEntry | undefined;\n let refName: string | undefined;\n if (toArg) {\n const refs = aggregate.app.refs;\n const refResult = parseContractRef(toArg, { graph: aggregate.app.graph(), refs });\n if (!refResult.ok) {\n return notOk(mapRefResolutionError(refResult.failure));\n }\n if (refResult.value.provenance.kind === 'ref') {\n refName = refResult.value.provenance.refName;\n const resolved = refs[refName];\n if (resolved) refEntry = resolved;\n } else {\n refEntry = { hash: refResult.value.hash, invariants: [] };\n }\n }\n\n if (!flags.json && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ];\n if (typeof dbConnection === 'string') {\n details.push({\n label: 'database',\n value: maskConnectionUrl(dbConnection),\n });\n }\n if (toArg) {\n details.push({ label: 'to', value: toArg });\n }\n const header = formatStyledHeader({\n command: 'migrate',\n description: 'Apply planned migrations to advance the database',\n url: 'https://pris.ly/migrate',\n details,\n flags,\n });\n ui.stderr(header);\n }\n\n const appGraph = aggregate.app.graph();\n\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n try {\n await client.connect(dbConnection);\n\n const allMarkers = await client.readAllMarkers();\n const appMarker = allMarkers.get('app') ?? null;\n\n if (appMarker !== null && !isGraphNode(appMarker.storageHash, appGraph)) {\n return notOk(\n errorMarkerMismatch(\n appMarker.storageHash,\n [...appGraph.nodes].sort(),\n findLatestMigration(appGraph)?.to ?? null,\n ),\n );\n }\n\n if (refEntry && refEntry.invariants.length > 0) {\n const declared = collectDeclaredInvariants(appGraph);\n const known = new Set<string>(declared);\n for (const id of appMarker?.invariants ?? []) known.add(id);\n const unknown = refEntry.invariants.filter((id) => !known.has(id));\n if (unknown.length > 0) {\n return notOk(\n mapMigrationToolsError(\n errorUnknownInvariant({\n ...ifDefined('refName', toArg),\n unknown,\n declared: [...declared].sort(),\n }),\n ),\n );\n }\n }\n\n if (!flags.quiet && !flags.json) {\n ui.step('Loading contract spaces…');\n }\n\n // When `--to` resolves to an on-disk graph node with a matching bundle,\n // verify and apply against THAT bundle's destination contract via\n // `contractAt` — not the emitted `contract.json`. With `--to` omitted,\n // or a target with no matching bundle, the emitted contract stays the\n // apply contract (the only migrate-specific default). The same\n // `contractAt` artifacts feed the optional ref-advancement snapshot.\n let applyContract: Contract = contractRaw;\n let snapshotContractJson: Record<string, unknown> = JSON.parse(contractContent);\n let snapshotContractDts: string | undefined;\n if (toArg && refEntry) {\n const targetHash = refEntry.hash;\n const matchingBundle = aggregate.app.packages.find((p) => p.metadata.to === targetHash);\n if (matchingBundle) {\n try {\n const at = await aggregate.app.contractAt(\n targetHash,\n refName !== undefined ? { refName } : undefined,\n );\n applyContract = at.contract;\n snapshotContractJson = at.contractJson as Record<string, unknown>;\n snapshotContractDts = at.contractDts;\n } catch (error) {\n return mapContractAtError(error, { artifactRole: 'to' });\n }\n }\n }\n\n const applyResult = await client.migrate({\n contract: applyContract,\n migrationsDir,\n ...ifDefined('refHash', refEntry?.hash),\n ...(refEntry?.invariants ? { refInvariants: refEntry.invariants } : {}),\n ...(refEntry !== undefined ? ifDefined('refName', toArg) : {}),\n });\n\n if (!applyResult.ok) {\n return notOk(mapApplyFailure(applyResult.failure));\n }\n\n const { value } = applyResult;\n\n let advancedRef: { name: string; hash: string } | null = null;\n if (options.advanceRef !== undefined) {\n try {\n const contractIR =\n snapshotContractDts !== undefined\n ? { contract: snapshotContractJson, contractDts: snapshotContractDts }\n : await readContractIR(snapshotContractJson, contractPathAbsolute);\n advancedRef = await executeRefAdvancement(\n refsDir,\n options.advanceRef,\n value.markerHash,\n contractIR,\n );\n } catch (error) {\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n throw error;\n }\n }\n\n return ok({\n ok: true,\n migrationsApplied: value.migrationsApplied,\n migrationsTotal: value.perSpace.length,\n markerHash: value.markerHash,\n applied: value.applied,\n summary: value.summary,\n perSpace: value.perSpace,\n ...ifDefined('pathDecision', value.pathDecision),\n timings: { total: Date.now() - startTime },\n advancedRef,\n });\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n if (MigrationToolsError.is(error)) {\n return notOk(mapMigrationToolsError(error));\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during migrate: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createMigrateCommand(): Command {\n const command = new Command('migrate');\n setCommandDescriptions(\n command,\n 'Apply planned migrations to advance the database',\n 'Walks every contract space (app + extensions) and applies pending\\n' +\n 'on-disk migrations in canonical order (extensions alphabetically,\\n' +\n 'then app). Graph-walks the on-disk migration graph for every space.\\n' +\n 'Use --to to target a specific contract (hash, ref name, migration dir).\\n' +\n 'Use --show for a read-only preview of the path that would run.',\n );\n setCommandExamples(command, [\n 'prisma-next migrate --db $DATABASE_URL',\n 'prisma-next migrate --to production --db $DATABASE_URL',\n 'prisma-next migrate --to sha256:abc123 --db $DATABASE_URL',\n 'prisma-next migrate --show --db $DATABASE_URL',\n 'prisma-next migrate --show --from @contract --to production',\n ]);\n addGlobalOptions(command)\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option(\n '--to <contract>',\n 'Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)',\n )\n .option('--advance-ref <name>', 'Advance the named ref to the post-apply marker after success')\n .option('--show', 'Preview the migration path without applying (read-only)')\n .option(\n '--from <contract>',\n 'From-state for --show preview (@contract, @db, hash, ref name, or migration dir)',\n )\n .action(async (options: MigrateCommandOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const startTime = Date.now();\n\n const ui = createTerminalUI(flags);\n\n if (options.show) {\n // Read-only path: compute the migration plan and print the ordered list.\n // NEVER reaches runMigration() or any write boundary.\n const result = await executeMigrateShowCommand(options, flags, ui);\n\n const exitCode = handleResult(result, flags, ui, (showResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(showResult, null, 2));\n } else {\n // Print directly to stdout — not via ui.log() which injects Clack's │ gutter.\n ui.output(formatMigrateShowOutput(showResult, flags));\n }\n });\n\n process.exit(exitCode);\n return;\n }\n\n const result = await executeMigrateCommand(options, flags, ui, startTime);\n\n const exitCode = handleResult(result, flags, ui, (migrateResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(migrateResult, null, 2));\n } else if (!flags.quiet) {\n ui.log(formatMigrationApplyCommandOutput(migrateResult, flags));\n }\n });\n\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,eAAe,0BACb,SACA,OACA,IAC4D;CAC5D,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,EAAE,YAAY,eAAe,oBAAoB,YAAY,sBACjE,QAAQ,QACR,MACF;CAEA,MAAM,eAAe,QAAQ,MAAM,OAAO,IAAI;CAC9C,MAAM,YAAY,CAAC,CAAC,OAAO;CAC3B,MAAM,kBAAkB,QAAQ,SAAS,KAAA;CAIzC,IAAI,CAAC,iBAAiB;EACpB,MAAM,YAAY,oBAAoB;GACpC;GACA;GACA,KAAK;GACL,cAAc;EAChB,CAAC;EACD,IAAI,WACF,OAAO,MAAM,SAAS;CAE1B;CAEA,IAAI,UAAgB,CAAC;CACrB,IAAI;EACF,UA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;EACR,MAAM,OAAO,MAAM;CACrB;AACF;AAEA,SAAgB,uBAAgC;CAC9C,MAAM,UAAU,IAAI,QAAQ,SAAS;CACrC,uBACE,SACA,oDACA,oVAKF;CACA,mBAAmB,SAAS;EAC1B;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,iBAAiB,OAAO,CAAC,CACtB,OAAO,cAAc,4BAA4B,CAAC,CAClD,OAAO,mBAAmB,+BAA+B,CAAC,CAC1D,OACC,mBACA,2FACF,CAAC,CACA,OAAO,wBAAwB,8DAA8D,CAAC,CAC9F,OAAO,UAAU,yDAAyD,CAAC,CAC3E,OACC,qBACA,kFACF,CAAC,CACA,OAAO,OAAO,YAAmC;EAChD,MAAM,QAAQ,uBAAuB,OAAO;EAC5C,MAAM,YAAY,KAAK,IAAI;EAE3B,MAAM,KAAK,iBAAiB,KAAK;EAEjC,IAAI,QAAQ,MAAM;GAKhB,MAAM,WAAW,aAAa,MAFT,0BAA0B,SAAS,OAAO,EAAE,GAE3B,OAAO,KAAK,eAAe;IAC/D,IAAI,MAAM,MACR,GAAG,OAAO,KAAK,UAAU,YAAY,MAAM,CAAC,CAAC;SAG7C,GAAG,OAAO,wBAAwB,YAAY,KAAK,CAAC;GAExD,CAAC;GAED,QAAQ,KAAK,QAAQ;GACrB;EACF;EAIA,MAAM,WAAW,aAAa,MAFT,sBAAsB,SAAS,OAAO,IAAI,SAAS,GAElC,OAAO,KAAK,kBAAkB;GAClE,IAAI,MAAM,MACR,GAAG,OAAO,KAAK,UAAU,eAAe,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,OAChB,GAAG,IAAI,kCAAkC,eAAe,KAAK,CAAC;EAElE,CAAC;EAED,QAAQ,KAAK,QAAQ;CACvB,CAAC;CAEH,OAAO;AACT"}
|
|
@@ -1,19 +1,61 @@
|
|
|
1
|
+
import { N as CliStructuredError } from "../types-C_tYiJYx.mjs";
|
|
2
|
+
import { f as migrationCheckResultSchema, n as MigrationCheckResult, t as CheckFailure } from "../schemas-CeGMYFYX.mjs";
|
|
1
3
|
import { Command } from "commander";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
4
|
+
import { Result } from "@prisma-next/utils/result";
|
|
5
|
+
import { ContractSpaceAggregate } from "@prisma-next/migration-tools/aggregate";
|
|
6
|
+
import { Refs } from "@prisma-next/migration-tools/refs";
|
|
7
|
+
import { MigrationGraph } from "@prisma-next/migration-tools/graph";
|
|
8
|
+
import { OnDiskMigrationPackage } from "@prisma-next/migration-tools/package";
|
|
9
|
+
|
|
10
10
|
//#region src/commands/migration-check.d.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* One contract space's on-disk state, resolved for the explicit graph
|
|
13
|
+
* checks `runMigrationCheck` runs per space: the space's migration
|
|
14
|
+
* packages, its user-authored refs, its induced graph, and the absolute
|
|
15
|
+
* `migrations/<space>/` + `migrations/<space>/refs/` directories the
|
|
16
|
+
* file-existence and dangling-ref `where` paths are derived from.
|
|
17
|
+
*/
|
|
18
|
+
interface CheckSpace {
|
|
19
|
+
readonly spaceId: string;
|
|
20
|
+
readonly packages: readonly OnDiskMigrationPackage[];
|
|
21
|
+
readonly refs: Refs;
|
|
22
|
+
readonly graph: MigrationGraph;
|
|
23
|
+
readonly migrationsDir: string;
|
|
24
|
+
readonly refsDir: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Project the loaded {@link ContractSpaceAggregate} into the
|
|
28
|
+
* {@link CheckSpace} rows the multi-space check iterates — one per on-disk
|
|
29
|
+
* contract-space directory, in the aggregate's `app`-first ordering. Mirrors
|
|
30
|
+
* `migration list`'s `migrationSpaceListEntriesFromAggregate`: space
|
|
31
|
+
* membership matches the on-disk directories, package / ref / graph data come
|
|
32
|
+
* from `aggregate.space(id)`.
|
|
33
|
+
*/
|
|
34
|
+
declare function enumerateCheckSpaces(aggregate: ContractSpaceAggregate, projectMigrationsDir: string): Promise<readonly CheckSpace[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Inputs for {@link runMigrationCheck} — the multi-space policy core of
|
|
37
|
+
* the holistic (no-arg) `migration check`. Enumeration is supplied by the
|
|
38
|
+
* caller (the CLI shell builds it from {@link enumerateCheckSpaces}); the
|
|
39
|
+
* core does not touch config, flags, or streams.
|
|
40
|
+
*/
|
|
41
|
+
interface RunMigrationCheckInputs {
|
|
42
|
+
readonly spaces: readonly CheckSpace[];
|
|
43
|
+
readonly spaceFilter?: string;
|
|
15
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Policy core of the holistic `migration check`: validates `--space`,
|
|
47
|
+
* narrows the pre-enumerated spaces, and runs the per-space explicit graph
|
|
48
|
+
* checks (file-existence, snapshot consistency, reachability, dangling
|
|
49
|
+
* refs), aggregating every failure into one {@link MigrationCheckResult}.
|
|
50
|
+
*
|
|
51
|
+
* `--space` validation mirrors `migration list`: an invalid id →
|
|
52
|
+
* {@link errorInvalidSpaceId}; an id with no on-disk space →
|
|
53
|
+
* {@link errorSpaceNotFound}. Both map to exit `PRECONDITION` at the shell.
|
|
54
|
+
* Aggregate-integrity violations (which already span every space) are folded
|
|
55
|
+
* in by the caller, not here.
|
|
56
|
+
*/
|
|
57
|
+
declare function runMigrationCheck(inputs: RunMigrationCheckInputs): Result<MigrationCheckResult, CliStructuredError>;
|
|
16
58
|
declare function createMigrationCheckCommand(): Command;
|
|
17
59
|
//#endregion
|
|
18
|
-
export { type CheckFailure, MigrationCheckResult, createMigrationCheckCommand };
|
|
60
|
+
export { type CheckFailure, CheckSpace, type MigrationCheckResult, RunMigrationCheckInputs, createMigrationCheckCommand, enumerateCheckSpaces, migrationCheckResultSchema, runMigrationCheck };
|
|
19
61
|
//# sourceMappingURL=migration-check.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-check.d.mts","names":[],"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"migration-check.d.mts","names":[],"sources":["../../src/commands/migration-check.ts"],"mappings":";;;;;;;;;;AAoIA;;;;;;;AAAA,UAAiB,UAAA;EAAA,SACN,OAAA;EAAA,SACA,QAAA,WAAmB,sBAAA;EAAA,SACnB,IAAA,EAAM,IAAA;EAAA,SACN,KAAA,EAAO,cAAA;EAAA,SACP,aAAA;EAAA,SACA,OAAA;AAAA;;;;AAAO;AAWlB;;;;iBAAsB,oBAAA,CACpB,SAAA,EAAW,sBAAA,EACX,oBAAA,WACC,OAAA,UAAiB,UAAA;;;;;;;UAyGH,uBAAA;EAAA,SACN,MAAA,WAAiB,UAAU;EAAA,SAC3B,WAAA;AAAA;AAFX;;;;;;;;AAEsB;AAetB;;;AAjBA,iBAiBgB,iBAAA,CACd,MAAA,EAAQ,uBAAA,GACP,MAAA,CAAO,oBAAA,EAAsB,kBAAA;AAAA,iBA+ShB,2BAAA,IAA+B,OAAO"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { t as createMigrationCheckCommand } from "../migration-check-
|
|
2
|
-
|
|
1
|
+
import { n as enumerateCheckSpaces, r as runMigrationCheck, t as createMigrationCheckCommand } from "../migration-check-soB5uZEQ.mjs";
|
|
2
|
+
import { t as migrationCheckResultSchema } from "../schemas-KhXMzNA_.mjs";
|
|
3
|
+
export { createMigrationCheckCommand, enumerateCheckSpaces, migrationCheckResultSchema, runMigrationCheck };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { N as CliStructuredError } from "../types-
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import { t as TerminalUI } from "../terminal-ui-
|
|
1
|
+
import { N as CliStructuredError } from "../types-C_tYiJYx.mjs";
|
|
2
|
+
import { o as MigrationSpaceGraphEntry } from "../schemas-CeGMYFYX.mjs";
|
|
3
|
+
import { n as GlobalFlags, t as CommonCommandOptions } from "../global-flags-BpoOYtNZ.mjs";
|
|
4
|
+
import { t as TerminalUI } from "../terminal-ui-DGRNFWna.mjs";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { Result } from "@prisma-next/utils/result";
|
|
7
7
|
import { MigrationGraph } from "@prisma-next/migration-tools/graph";
|
|
@@ -10,18 +10,27 @@ import { MigrationGraph } from "@prisma-next/migration-tools/graph";
|
|
|
10
10
|
interface MigrationGraphOptions extends CommonCommandOptions {
|
|
11
11
|
readonly config?: string;
|
|
12
12
|
readonly dot?: boolean;
|
|
13
|
-
readonly
|
|
13
|
+
readonly space?: string;
|
|
14
14
|
readonly ascii?: boolean;
|
|
15
|
+
readonly legend?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface MigrationGraphTreeSection {
|
|
18
|
+
readonly space: string;
|
|
19
|
+
readonly tree: string;
|
|
20
|
+
readonly showHeading: boolean;
|
|
15
21
|
}
|
|
16
22
|
interface MigrationGraphResult {
|
|
17
23
|
readonly ok: true;
|
|
24
|
+
/** App-space graph for the `--dot` Graphviz output. */
|
|
18
25
|
readonly graph: MigrationGraph;
|
|
19
|
-
|
|
20
|
-
readonly
|
|
26
|
+
/** Nested per-space contracts + migrations for `--json`. */
|
|
27
|
+
readonly spaces: readonly MigrationSpaceGraphEntry[];
|
|
28
|
+
readonly treeSections: readonly MigrationGraphTreeSection[];
|
|
21
29
|
readonly summary: string;
|
|
22
30
|
}
|
|
31
|
+
declare function formatMigrationGraphHumanOutput(result: MigrationGraphResult): string;
|
|
23
32
|
declare function executeMigrationGraphCommand(options: MigrationGraphOptions, flags: GlobalFlags, ui: TerminalUI): Promise<Result<MigrationGraphResult, CliStructuredError>>;
|
|
24
33
|
declare function createMigrationGraphCommand(): Command;
|
|
25
34
|
//#endregion
|
|
26
|
-
export { MigrationGraphResult, createMigrationGraphCommand, executeMigrationGraphCommand };
|
|
35
|
+
export { MigrationGraphResult, MigrationGraphTreeSection, createMigrationGraphCommand, executeMigrationGraphCommand, formatMigrationGraphHumanOutput };
|
|
27
36
|
//# sourceMappingURL=migration-graph.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/commands/migration-graph.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"migration-graph.d.mts","names":[],"sources":["../../src/commands/migration-graph.ts"],"mappings":";;;;;;;;;UAmCU,qBAAA,SAA8B,oBAAoB;EAAA,SACjD,MAAA;EAAA,SACA,GAAA;EAAA,SACA,KAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,yBAAA;EAAA,SACN,KAAA;EAAA,SACA,IAAA;EAAA,SACA,WAAA;AAAA;AAAA,UAGM,oBAAA;EAAA,SACN,EAAA;EAP+B;EAAA,SAS/B,KAAA,EAAO,cAAA;EATwB;EAAA,SAW/B,MAAA,WAAiB,wBAAA;EAAA,SACjB,YAAA,WAAuB,yBAAA;EAAA,SACvB,OAAA;AAAA;AAAA,iBASK,+BAAA,CAAgC,MAA4B,EAApB,oBAAoB;AAAA,iBAiBtD,4BAAA,CACpB,OAAA,EAAS,qBAAA,EACT,KAAA,EAAO,WAAA,EACP,EAAA,EAAI,UAAA,GACH,OAAA,CAAQ,MAAA,CAAO,oBAAA,EAAsB,kBAAA;AAAA,iBA0HxB,2BAAA,IAA+B,OAAO"}
|
|
@@ -1,2 +1,185 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { t as loadConfig } from "../config-loader-p9JMrekQ.mjs";
|
|
2
|
+
import { A as formatStyledHeader, _ as createTerminalUI, d as setCommandSeeAlso, g as parseGlobalFlagsOrExit, l as setCommandDescriptions, s as resolveMigrationPaths, t as addGlobalOptions, u as setCommandExamples, y as handleResult } from "../command-helpers-DGMvGBeX.mjs";
|
|
3
|
+
import { n as buildReadAggregate } from "../contract-space-aggregate-loader-ClI1KN6d.mjs";
|
|
4
|
+
import { a as renderMigrationGraphLegend, f as indentMigrationGraphTreeBlock, l as computeGlobalMaxDirNameWidth, p as renderMigrationGraphSpaceTree, u as computeGlobalMaxEdgeTreePrefixWidth } from "../migration-graph-command-render-CEez7YUK.mjs";
|
|
5
|
+
import { c as validateLegendOptions, i as migrationSpaceListEntriesFromAggregate, o as runMigrationList, r as listRefsByContractHash, s as shouldShowLegend } from "../migration-list-DlJJ_38Z.mjs";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
8
|
+
import { ok } from "@prisma-next/utils/result";
|
|
9
|
+
import { EMPTY_CONTRACT_HASH } from "@prisma-next/migration-tools/constants";
|
|
10
|
+
//#region src/commands/migration-graph.ts
|
|
11
|
+
function computeGraphSummary(spaces) {
|
|
12
|
+
const contractCount = spaces.reduce((count, space) => count + space.contracts.length, 0);
|
|
13
|
+
const migrationCount = spaces.reduce((count, space) => count + space.migrations.length, 0);
|
|
14
|
+
return `${spaces.length} space(s), ${contractCount} contract(s), ${migrationCount} migration(s)`;
|
|
15
|
+
}
|
|
16
|
+
function formatMigrationGraphHumanOutput(result) {
|
|
17
|
+
const sections = [];
|
|
18
|
+
for (const section of result.treeSections) {
|
|
19
|
+
if (section.showHeading) sections.push(`${section.space}:`);
|
|
20
|
+
if (section.tree.length > 0) sections.push(section.tree);
|
|
21
|
+
else sections.push("(no migrations)");
|
|
22
|
+
sections.push("");
|
|
23
|
+
}
|
|
24
|
+
sections.push(result.summary);
|
|
25
|
+
return sections.join("\n").trimEnd();
|
|
26
|
+
}
|
|
27
|
+
async function executeMigrationGraphCommand(options, flags, ui) {
|
|
28
|
+
const config = await loadConfig(options.config);
|
|
29
|
+
const { configPath, migrationsRelative, migrationsDir } = resolveMigrationPaths(options.config, config);
|
|
30
|
+
if (!flags.json && !flags.quiet) {
|
|
31
|
+
const header = formatStyledHeader({
|
|
32
|
+
command: "migration graph",
|
|
33
|
+
description: "Show the migration graph topology",
|
|
34
|
+
details: [
|
|
35
|
+
{
|
|
36
|
+
label: "config",
|
|
37
|
+
value: configPath
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: "migrations",
|
|
41
|
+
value: migrationsRelative
|
|
42
|
+
},
|
|
43
|
+
...options.space !== void 0 ? [{
|
|
44
|
+
label: "space",
|
|
45
|
+
value: options.space
|
|
46
|
+
}] : []
|
|
47
|
+
],
|
|
48
|
+
flags
|
|
49
|
+
});
|
|
50
|
+
ui.stderr(header);
|
|
51
|
+
if (shouldShowLegend(options, flags)) {
|
|
52
|
+
ui.stderr(renderMigrationGraphLegend({
|
|
53
|
+
colorize: flags.color !== false,
|
|
54
|
+
glyphMode: ui.resolveGlyphMode(options.ascii === true)
|
|
55
|
+
}));
|
|
56
|
+
ui.stderr("");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const loaded = await buildReadAggregate(config, { migrationsDir });
|
|
60
|
+
if (!loaded.ok) return loaded;
|
|
61
|
+
const { aggregate, contractHash: liveContractHash } = loaded.value;
|
|
62
|
+
const appGraph = aggregate.app.graph();
|
|
63
|
+
const listResult = runMigrationList({
|
|
64
|
+
spaces: await migrationSpaceListEntriesFromAggregate(aggregate, migrationsDir),
|
|
65
|
+
...ifDefined("spaceFilter", options.space)
|
|
66
|
+
});
|
|
67
|
+
if (!listResult.ok) return listResult;
|
|
68
|
+
const scopedSpaces = listResult.value.spaces;
|
|
69
|
+
const showSpaceHeadings = scopedSpaces.length > 1;
|
|
70
|
+
const glyphMode = ui.resolveGlyphMode(options.ascii === true);
|
|
71
|
+
const colorize = flags.color !== false;
|
|
72
|
+
const globalLayoutInputs = showSpaceHeadings ? scopedSpaces.filter((spaceEntry) => spaceEntry.migrations.length > 0).map((spaceEntry) => ({
|
|
73
|
+
graph: aggregate.space(spaceEntry.space).graph(),
|
|
74
|
+
liveContractHash
|
|
75
|
+
})) : [];
|
|
76
|
+
const globalMaxEdgeTreePrefixWidth = globalLayoutInputs.length > 0 ? computeGlobalMaxEdgeTreePrefixWidth(globalLayoutInputs) : void 0;
|
|
77
|
+
const globalMaxDirNameWidth = globalLayoutInputs.length > 0 ? computeGlobalMaxDirNameWidth(globalLayoutInputs) : void 0;
|
|
78
|
+
const treeSections = [];
|
|
79
|
+
const spaces = [];
|
|
80
|
+
for (const spaceEntry of scopedSpaces) {
|
|
81
|
+
const member = aggregate.space(spaceEntry.space);
|
|
82
|
+
if (member === void 0) continue;
|
|
83
|
+
const graph = member.graph();
|
|
84
|
+
const isAppSpace = spaceEntry.space === aggregate.app.spaceId;
|
|
85
|
+
const refsByHash = listRefsByContractHash(member);
|
|
86
|
+
const tree = spaceEntry.migrations.length === 0 ? "" : renderMigrationGraphSpaceTree({
|
|
87
|
+
graph,
|
|
88
|
+
migrations: spaceEntry.migrations,
|
|
89
|
+
liveContractHash,
|
|
90
|
+
glyphMode,
|
|
91
|
+
colorize,
|
|
92
|
+
isAppSpace,
|
|
93
|
+
refsByHash,
|
|
94
|
+
...globalMaxEdgeTreePrefixWidth !== void 0 ? { globalMaxEdgeTreePrefixWidth } : {},
|
|
95
|
+
...globalMaxDirNameWidth !== void 0 ? { globalMaxDirNameWidth } : {}
|
|
96
|
+
});
|
|
97
|
+
const displayTree = showSpaceHeadings && tree.length > 0 ? indentMigrationGraphTreeBlock(tree, " ") : tree;
|
|
98
|
+
treeSections.push({
|
|
99
|
+
space: spaceEntry.space,
|
|
100
|
+
tree: displayTree,
|
|
101
|
+
showHeading: showSpaceHeadings
|
|
102
|
+
});
|
|
103
|
+
spaces.push({
|
|
104
|
+
space: spaceEntry.space,
|
|
105
|
+
contracts: [...graph.nodes].map((hash) => ({
|
|
106
|
+
hash,
|
|
107
|
+
refs: [...refsByHash.get(hash) ?? []]
|
|
108
|
+
})),
|
|
109
|
+
migrations: [...graph.migrationByHash.values()].map((edge) => ({
|
|
110
|
+
name: edge.dirName,
|
|
111
|
+
hash: edge.migrationHash,
|
|
112
|
+
fromContract: edge.from === EMPTY_CONTRACT_HASH ? null : edge.from,
|
|
113
|
+
toContract: edge.to
|
|
114
|
+
}))
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return ok({
|
|
118
|
+
ok: true,
|
|
119
|
+
graph: appGraph,
|
|
120
|
+
spaces,
|
|
121
|
+
treeSections,
|
|
122
|
+
summary: computeGraphSummary(spaces)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function createMigrationGraphCommand() {
|
|
126
|
+
const command = new Command("graph");
|
|
127
|
+
setCommandDescriptions(command, "Show the migration graph topology", "Renders the migration graph topology.\nOffline — does not consult the database.\n--ascii swaps box-drawing for pipe-friendly ASCII glyphs.\nUse --json for machine-readable output, or --dot for Graphviz DOT\nformat.");
|
|
128
|
+
setCommandExamples(command, [
|
|
129
|
+
"prisma-next migration graph",
|
|
130
|
+
"prisma-next migration graph --json",
|
|
131
|
+
"prisma-next migration graph --dot",
|
|
132
|
+
"prisma-next migration graph --ascii",
|
|
133
|
+
"prisma-next migration graph --legend",
|
|
134
|
+
"prisma-next migration graph --space app"
|
|
135
|
+
]);
|
|
136
|
+
setCommandSeeAlso(command, [
|
|
137
|
+
{
|
|
138
|
+
verb: "migration status",
|
|
139
|
+
oneLiner: "Show migration path and pending status"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
verb: "migration log",
|
|
143
|
+
oneLiner: "Show executed migration history"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
verb: "migration list",
|
|
147
|
+
oneLiner: "List on-disk migrations"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
verb: "migration show",
|
|
151
|
+
oneLiner: "Display migration package contents"
|
|
152
|
+
}
|
|
153
|
+
]);
|
|
154
|
+
addGlobalOptions(command).option("--config <path>", "Path to prisma-next.config.ts").option("--space <id>", "Narrow output to a single contract space").option("--dot", "Output in Graphviz DOT format").option("--ascii", "Use ASCII glyphs (pipe-friendly)").option("--legend", "Print a key for the tree glyphs and lane colors").action(async (options) => {
|
|
155
|
+
const flags = parseGlobalFlagsOrExit(options);
|
|
156
|
+
const ui = createTerminalUI(flags);
|
|
157
|
+
const legendValidation = validateLegendOptions(options, flags);
|
|
158
|
+
if (!legendValidation.ok) process.exit(handleResult(legendValidation, flags, ui));
|
|
159
|
+
const exitCode = handleResult(await executeMigrationGraphCommand(options, flags, ui), flags, ui, (graphResult) => {
|
|
160
|
+
if (options.dot) {
|
|
161
|
+
const lines = ["digraph migrations {"];
|
|
162
|
+
for (const edge of graphResult.graph.migrationByHash.values()) {
|
|
163
|
+
const from = edge.from.slice(0, 12);
|
|
164
|
+
const to = edge.to.slice(0, 12);
|
|
165
|
+
lines.push(` "${from}" -> "${to}" [label="${edge.dirName}"];`);
|
|
166
|
+
}
|
|
167
|
+
lines.push("}");
|
|
168
|
+
ui.output(lines.join("\n"));
|
|
169
|
+
} else if (flags.json) {
|
|
170
|
+
const jsonResult = {
|
|
171
|
+
ok: true,
|
|
172
|
+
spaces: [...graphResult.spaces],
|
|
173
|
+
summary: graphResult.summary
|
|
174
|
+
};
|
|
175
|
+
ui.output(JSON.stringify(jsonResult, null, 2));
|
|
176
|
+
} else if (!flags.quiet) ui.output(formatMigrationGraphHumanOutput(graphResult));
|
|
177
|
+
});
|
|
178
|
+
process.exit(exitCode);
|
|
179
|
+
});
|
|
180
|
+
return command;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
export { createMigrationGraphCommand, executeMigrationGraphCommand, formatMigrationGraphHumanOutput };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=migration-graph.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-graph.mjs","names":[],"sources":["../../src/commands/migration-graph.ts"],"sourcesContent":["import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport type { MigrationGraph } from '@prisma-next/migration-tools/graph';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport type { CliStructuredError } from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n} from '../utils/command-helpers';\nimport { buildReadAggregate } from '../utils/contract-space-aggregate-loader';\nimport { renderMigrationGraphLegend } from '../utils/formatters/migration-graph-labels';\nimport {\n computeGlobalMaxDirNameWidth,\n computeGlobalMaxEdgeTreePrefixWidth,\n indentMigrationGraphTreeBlock,\n renderMigrationGraphSpaceTree,\n} from '../utils/formatters/migration-graph-space-render';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { shouldShowLegend, validateLegendOptions } from '../utils/legend';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\nimport type { MigrationGraphJsonResult, MigrationSpaceGraphEntry } from './json/schemas';\nimport {\n listRefsByContractHash,\n migrationSpaceListEntriesFromAggregate,\n runMigrationList,\n} from './migration-list';\n\ninterface MigrationGraphOptions extends CommonCommandOptions {\n readonly config?: string;\n readonly dot?: boolean;\n readonly space?: string;\n readonly ascii?: boolean;\n readonly legend?: boolean;\n}\n\nexport interface MigrationGraphTreeSection {\n readonly space: string;\n readonly tree: string;\n readonly showHeading: boolean;\n}\n\nexport interface MigrationGraphResult {\n readonly ok: true;\n /** App-space graph for the `--dot` Graphviz output. */\n readonly graph: MigrationGraph;\n /** Nested per-space contracts + migrations for `--json`. */\n readonly spaces: readonly MigrationSpaceGraphEntry[];\n readonly treeSections: readonly MigrationGraphTreeSection[];\n readonly summary: string;\n}\n\nfunction computeGraphSummary(spaces: readonly MigrationSpaceGraphEntry[]): string {\n const contractCount = spaces.reduce((count, space) => count + space.contracts.length, 0);\n const migrationCount = spaces.reduce((count, space) => count + space.migrations.length, 0);\n return `${spaces.length} space(s), ${contractCount} contract(s), ${migrationCount} migration(s)`;\n}\n\nexport function formatMigrationGraphHumanOutput(result: MigrationGraphResult): string {\n const sections: string[] = [];\n for (const section of result.treeSections) {\n if (section.showHeading) {\n sections.push(`${section.space}:`);\n }\n if (section.tree.length > 0) {\n sections.push(section.tree);\n } else {\n sections.push('(no migrations)');\n }\n sections.push('');\n }\n sections.push(result.summary);\n return sections.join('\\n').trimEnd();\n}\n\nexport async function executeMigrationGraphCommand(\n options: MigrationGraphOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationGraphResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, migrationsRelative, migrationsDir } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration graph',\n description: 'Show the migration graph topology',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: migrationsRelative },\n ...(options.space !== undefined ? [{ label: 'space', value: options.space }] : []),\n ],\n flags,\n });\n ui.stderr(header);\n if (shouldShowLegend(options, flags)) {\n ui.stderr(\n renderMigrationGraphLegend({\n colorize: flags.color !== false,\n glyphMode: ui.resolveGlyphMode(options.ascii === true),\n }),\n );\n ui.stderr('');\n }\n }\n\n const loaded = await buildReadAggregate(config, { migrationsDir });\n if (!loaded.ok) {\n return loaded;\n }\n\n const { aggregate, contractHash: liveContractHash } = loaded.value;\n const appGraph = aggregate.app.graph();\n\n const listSpaces = await migrationSpaceListEntriesFromAggregate(aggregate, migrationsDir);\n const listResult = runMigrationList({\n spaces: listSpaces,\n ...ifDefined('spaceFilter', options.space),\n });\n if (!listResult.ok) {\n return listResult;\n }\n\n const scopedSpaces = listResult.value.spaces;\n const showSpaceHeadings = scopedSpaces.length > 1;\n const glyphMode = ui.resolveGlyphMode(options.ascii === true);\n const colorize = flags.color !== false;\n\n const globalLayoutInputs = showSpaceHeadings\n ? scopedSpaces\n .filter((spaceEntry) => spaceEntry.migrations.length > 0)\n .map((spaceEntry) => ({\n graph: aggregate.space(spaceEntry.space)!.graph(),\n liveContractHash,\n }))\n : [];\n const globalMaxEdgeTreePrefixWidth =\n globalLayoutInputs.length > 0\n ? computeGlobalMaxEdgeTreePrefixWidth(globalLayoutInputs)\n : undefined;\n const globalMaxDirNameWidth =\n globalLayoutInputs.length > 0 ? computeGlobalMaxDirNameWidth(globalLayoutInputs) : undefined;\n\n const treeSections: MigrationGraphTreeSection[] = [];\n const spaces: MigrationSpaceGraphEntry[] = [];\n for (const spaceEntry of scopedSpaces) {\n const member = aggregate.space(spaceEntry.space);\n if (member === undefined) {\n continue;\n }\n const graph = member.graph();\n const isAppSpace = spaceEntry.space === aggregate.app.spaceId;\n const refsByHash = listRefsByContractHash(member);\n const tree =\n spaceEntry.migrations.length === 0\n ? ''\n : renderMigrationGraphSpaceTree({\n graph,\n migrations: spaceEntry.migrations,\n liveContractHash,\n glyphMode,\n colorize,\n isAppSpace,\n refsByHash,\n ...(globalMaxEdgeTreePrefixWidth !== undefined ? { globalMaxEdgeTreePrefixWidth } : {}),\n ...(globalMaxDirNameWidth !== undefined ? { globalMaxDirNameWidth } : {}),\n });\n const displayTree =\n showSpaceHeadings && tree.length > 0 ? indentMigrationGraphTreeBlock(tree, ' ') : tree;\n treeSections.push({\n space: spaceEntry.space,\n tree: displayTree,\n showHeading: showSpaceHeadings,\n });\n spaces.push({\n space: spaceEntry.space,\n contracts: [...graph.nodes].map((hash) => ({\n hash,\n refs: [...(refsByHash.get(hash) ?? [])],\n })),\n migrations: [...graph.migrationByHash.values()].map((edge) => ({\n name: edge.dirName,\n hash: edge.migrationHash,\n fromContract: edge.from === EMPTY_CONTRACT_HASH ? null : edge.from,\n toContract: edge.to,\n })),\n });\n }\n\n return ok({\n ok: true,\n graph: appGraph,\n spaces,\n treeSections,\n summary: computeGraphSummary(spaces),\n });\n}\n\nexport function createMigrationGraphCommand(): Command {\n const command = new Command('graph');\n setCommandDescriptions(\n command,\n 'Show the migration graph topology',\n 'Renders the migration graph topology.\\n' +\n 'Offline — does not consult the database.\\n' +\n '--ascii swaps box-drawing for pipe-friendly ASCII glyphs.\\n' +\n 'Use --json for machine-readable output, or --dot for Graphviz DOT\\n' +\n 'format.',\n );\n setCommandExamples(command, [\n 'prisma-next migration graph',\n 'prisma-next migration graph --json',\n 'prisma-next migration graph --dot',\n 'prisma-next migration graph --ascii',\n 'prisma-next migration graph --legend',\n 'prisma-next migration graph --space app',\n ]);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration log', oneLiner: 'Show executed migration history' },\n { verb: 'migration list', oneLiner: 'List on-disk migrations' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--space <id>', 'Narrow output to a single contract space')\n .option('--dot', 'Output in Graphviz DOT format')\n .option('--ascii', 'Use ASCII glyphs (pipe-friendly)')\n .option('--legend', 'Print a key for the tree glyphs and lane colors')\n .action(async (options: MigrationGraphOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const legendValidation = validateLegendOptions(options, flags);\n if (!legendValidation.ok) {\n process.exit(handleResult(legendValidation, flags, ui));\n }\n const result = await executeMigrationGraphCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (graphResult) => {\n if (options.dot) {\n const lines = ['digraph migrations {'];\n for (const edge of graphResult.graph.migrationByHash.values()) {\n const from = edge.from.slice(0, 12);\n const to = edge.to.slice(0, 12);\n lines.push(` \"${from}\" -> \"${to}\" [label=\"${edge.dirName}\"];`);\n }\n lines.push('}');\n ui.output(lines.join('\\n'));\n } else if (flags.json) {\n const jsonResult: MigrationGraphJsonResult = {\n ok: true,\n spaces: [...graphResult.spaces],\n summary: graphResult.summary,\n };\n ui.output(JSON.stringify(jsonResult, null, 2));\n } else if (!flags.quiet) {\n ui.output(formatMigrationGraphHumanOutput(graphResult));\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":";;;;;;;;;;AA2DA,SAAS,oBAAoB,QAAqD;CAChF,MAAM,gBAAgB,OAAO,QAAQ,OAAO,UAAU,QAA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KAAK;EACjC,MAAM,mBAAmB,sBAAsB,SAAS,KAAK;EAC7D,IAAI,CAAC,iBAAiB,IACpB,QAAQ,KAAK,aAAa,kBAAkB,OAAO,EAAE,CAAC;EAGxD,MAAM,WAAW,aAAa,MADT,6BAA6B,SAAS,OAAO,EAAE,GAC9B,OAAO,KAAK,gBAAgB;GAChE,IAAI,QAAQ,KAAK;IACf,MAAM,QAAQ,CAAC,sBAAsB;IACrC,KAAK,MAAM,QAAQ,YAAY,MAAM,gBAAgB,OAAO,GAAG;KAC7D,MAAM,OAAO,KAAK,KAAK,MAAM,GAAG,EAAE;KAClC,MAAM,KAAK,KAAK,GAAG,MAAM,GAAG,EAAE;KAC9B,MAAM,KAAK,MAAM,KAAK,QAAQ,GAAG,YAAY,KAAK,QAAQ,IAAI;IAChE;IACA,MAAM,KAAK,GAAG;IACd,GAAG,OAAO,MAAM,KAAK,IAAI,CAAC;GAC5B,OAAO,IAAI,MAAM,MAAM;IACrB,MAAM,aAAuC;KAC3C,IAAI;KACJ,QAAQ,CAAC,GAAG,YAAY,MAAM;KAC9B,SAAS,YAAY;IACvB;IACA,GAAG,OAAO,KAAK,UAAU,YAAY,MAAM,CAAC,CAAC;GAC/C,OAAO,IAAI,CAAC,MAAM,OAChB,GAAG,OAAO,gCAAgC,WAAW,CAAC;EAE1D,CAAC;EACD,QAAQ,KAAK,QAAQ;CACvB,CAAC;CACH,OAAO;AACT"}
|
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
import { N as CliStructuredError } from "../types-
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
1
|
+
import { N as CliStructuredError } from "../types-C_tYiJYx.mjs";
|
|
2
|
+
import { r as MigrationListResult, s as MigrationSpaceListEntry } from "../schemas-CeGMYFYX.mjs";
|
|
3
|
+
import { n as GlobalFlags, t as CommonCommandOptions } from "../global-flags-BpoOYtNZ.mjs";
|
|
4
|
+
import { n as GlyphMode, t as TerminalUI } from "../terminal-ui-DGRNFWna.mjs";
|
|
4
5
|
import { Command } from "commander";
|
|
5
6
|
import { Result } from "@prisma-next/utils/result";
|
|
6
|
-
import { ContractSpaceAggregate } from "@prisma-next/migration-tools/aggregate";
|
|
7
|
+
import { ContractSpaceAggregate, ContractSpaceMember } from "@prisma-next/migration-tools/aggregate";
|
|
8
|
+
import { MigrationGraph } from "@prisma-next/migration-tools/graph";
|
|
7
9
|
|
|
8
|
-
//#region src/utils/formatters/migration-list-types.d.ts
|
|
9
|
-
interface MigrationListEntry {
|
|
10
|
-
readonly dirName: string;
|
|
11
|
-
readonly from: string | null;
|
|
12
|
-
readonly to: string;
|
|
13
|
-
readonly migrationHash: string;
|
|
14
|
-
readonly operationCount: number;
|
|
15
|
-
readonly createdAt: string;
|
|
16
|
-
readonly refs: readonly string[];
|
|
17
|
-
readonly providedInvariants: readonly string[];
|
|
18
|
-
}
|
|
19
|
-
interface MigrationSpaceListEntry {
|
|
20
|
-
readonly spaceId: string;
|
|
21
|
-
readonly migrations: readonly MigrationListEntry[];
|
|
22
|
-
}
|
|
23
|
-
interface MigrationListResult {
|
|
24
|
-
readonly ok: true;
|
|
25
|
-
readonly spaces: readonly MigrationSpaceListEntry[];
|
|
26
|
-
readonly summary: string;
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
10
|
//#region src/commands/migration-list.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Ref names decorating a space's destination contract hashes. The
|
|
13
|
+
* tolerant `member.refs` deliberately omits the structural `head.json`;
|
|
14
|
+
* for extension spaces the old enumerator surfaced it as a `head`
|
|
15
|
+
* decoration on the tip migration, so fold `member.headRef` back in to
|
|
16
|
+
* keep that output. The app space synthesises its head, so it carries
|
|
17
|
+
* no on-disk `head` ref to restore.
|
|
18
|
+
*/
|
|
19
|
+
declare function listRefsByContractHash(member: ContractSpaceMember): ReadonlyMap<string, readonly string[]>;
|
|
30
20
|
/**
|
|
31
21
|
* Project the loaded {@link ContractSpaceAggregate} into the render-ready
|
|
32
22
|
* {@link MigrationSpaceListEntry} rows `migration list` displays.
|
|
@@ -40,10 +30,19 @@ interface MigrationListOptions extends CommonCommandOptions {
|
|
|
40
30
|
readonly config?: string;
|
|
41
31
|
readonly space?: string;
|
|
42
32
|
readonly ascii?: boolean;
|
|
33
|
+
readonly legend?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface MigrationListExecuteResult {
|
|
36
|
+
readonly list: MigrationListResult;
|
|
37
|
+
readonly liveContractHash: string;
|
|
38
|
+
readonly aggregate: ContractSpaceAggregate;
|
|
43
39
|
}
|
|
44
40
|
interface MigrationListHumanRenderOptions {
|
|
45
41
|
readonly glyphMode: GlyphMode;
|
|
46
42
|
readonly useColor: boolean;
|
|
43
|
+
readonly liveContractHash: string;
|
|
44
|
+
readonly graphForSpace: (spaceId: string) => MigrationGraph | undefined;
|
|
45
|
+
readonly appSpaceId?: string;
|
|
47
46
|
}
|
|
48
47
|
declare function renderMigrationListHumanOutput(result: MigrationListResult, options: MigrationListHumanRenderOptions): string;
|
|
49
48
|
/**
|
|
@@ -73,8 +72,8 @@ declare function runMigrationList(inputs: RunMigrationListInputs): Result<Migrat
|
|
|
73
72
|
* stderr (interactive mode only), and delegates to {@link runMigrationList}.
|
|
74
73
|
* Kept intentionally thin so the unit-testable surface lives in the core.
|
|
75
74
|
*/
|
|
76
|
-
declare function executeMigrationListCommand(options: MigrationListOptions, flags: GlobalFlags, ui: TerminalUI): Promise<Result<
|
|
75
|
+
declare function executeMigrationListCommand(options: MigrationListOptions, flags: GlobalFlags, ui: TerminalUI): Promise<Result<MigrationListExecuteResult, CliStructuredError>>;
|
|
77
76
|
declare function createMigrationListCommand(): Command;
|
|
78
77
|
//#endregion
|
|
79
|
-
export { MigrationListHumanRenderOptions, RunMigrationListInputs, createMigrationListCommand, executeMigrationListCommand, migrationSpaceListEntriesFromAggregate, renderMigrationListHumanOutput, runMigrationList };
|
|
78
|
+
export { MigrationListExecuteResult, MigrationListHumanRenderOptions, RunMigrationListInputs, createMigrationListCommand, executeMigrationListCommand, listRefsByContractHash, migrationSpaceListEntriesFromAggregate, renderMigrationListHumanOutput, runMigrationList };
|
|
80
79
|
//# sourceMappingURL=migration-list.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-list.d.mts","names":[],"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"migration-list.d.mts","names":[],"sources":["../../src/commands/migration-list.ts"],"mappings":";;;;;;;;;;AAmEA;;;;;;;;AAAA,iBAAgB,sBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,WAAW;AA4Bd;;;;;;;;AAAA,iBAAsB,sCAAA,CACpB,SAAA,EAAW,sBAAA,EACX,oBAAA,WACC,OAAA,UAAiB,uBAAA;AAAA,UA6BV,oBAAA,SAA6B,oBAAoB;EAAA,SAChD,MAAA;EAAA,SACA,KAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,0BAAA;EAAA,SACN,IAAA,EAAM,mBAAA;EAAA,SACN,gBAAA;EAAA,SACA,SAAA,EAAW,sBAAsB;AAAA;AAAA,UAG3B,+BAAA;EAAA,SACN,SAAA,EAAW,SAAA;EAAA,SACX,QAAA;EAAA,SACA,gBAAA;EAAA,SACA,aAAA,GAAgB,OAAA,aAAoB,cAAc;EAAA,SAClD,UAAA;AAAA;AAAA,iBAGK,8BAAA,CACd,MAAA,EAAQ,mBAAA,EACR,OAAA,EAAS,+BAA+B;;;;;;;;;UAmBzB,sBAAA;EAAA,SACN,MAAA,WAAiB,uBAAuB;EAAA,SACxC,WAAA;AAAA;;;;;;;;;;iBAoBK,gBAAA,CACd,MAAA,EAAQ,sBAAA,GACP,MAAA,CAAO,mBAAA,EAAqB,kBAAA;AAhDV;AAGrB;;;;AAHqB,iBA6EC,2BAAA,CACpB,OAAA,EAAS,oBAAA,EACT,KAAA,EAAO,WAAA,EACP,EAAA,EAAI,UAAA,GACH,OAAA,CAAQ,MAAA,CAAO,0BAAA,EAA4B,kBAAA;AAAA,iBAiD9B,0BAAA,IAA8B,OAAO"}
|