prisma-next 0.5.0-dev.7 → 0.5.0-dev.70

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.
Files changed (129) hide show
  1. package/dist/cli-errors-D3_sMh2K.mjs +33 -0
  2. package/dist/cli-errors-D3_sMh2K.mjs.map +1 -0
  3. package/dist/cli-errors-QH8kf-C2.d.mts +3 -0
  4. package/dist/cli.mjs +16 -78
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/client-0ZX24FXF.mjs +1398 -0
  7. package/dist/client-0ZX24FXF.mjs.map +1 -0
  8. package/dist/commands/contract-emit.d.mts.map +1 -1
  9. package/dist/commands/contract-emit.mjs +2 -4
  10. package/dist/commands/contract-infer.d.mts.map +1 -1
  11. package/dist/commands/contract-infer.mjs +2 -4
  12. package/dist/commands/db-init.d.mts.map +1 -1
  13. package/dist/commands/db-init.mjs +14 -13
  14. package/dist/commands/db-init.mjs.map +1 -1
  15. package/dist/commands/db-schema.d.mts.map +1 -1
  16. package/dist/commands/db-schema.mjs +5 -7
  17. package/dist/commands/db-schema.mjs.map +1 -1
  18. package/dist/commands/db-sign.d.mts.map +1 -1
  19. package/dist/commands/db-sign.mjs +8 -9
  20. package/dist/commands/db-sign.mjs.map +1 -1
  21. package/dist/commands/db-update.d.mts.map +1 -1
  22. package/dist/commands/db-update.mjs +13 -13
  23. package/dist/commands/db-update.mjs.map +1 -1
  24. package/dist/commands/db-verify.d.mts.map +1 -1
  25. package/dist/commands/db-verify.mjs +1 -321
  26. package/dist/commands/migration-apply.d.mts +5 -2
  27. package/dist/commands/migration-apply.d.mts.map +1 -1
  28. package/dist/commands/migration-apply.mjs +64 -66
  29. package/dist/commands/migration-apply.mjs.map +1 -1
  30. package/dist/commands/migration-new.d.mts +0 -1
  31. package/dist/commands/migration-new.d.mts.map +1 -1
  32. package/dist/commands/migration-new.mjs +33 -40
  33. package/dist/commands/migration-new.mjs.map +1 -1
  34. package/dist/commands/migration-plan.d.mts +14 -5
  35. package/dist/commands/migration-plan.d.mts.map +1 -1
  36. package/dist/commands/migration-plan.mjs +1 -347
  37. package/dist/commands/migration-ref.d.mts +1 -1
  38. package/dist/commands/migration-ref.d.mts.map +1 -1
  39. package/dist/commands/migration-ref.mjs +7 -12
  40. package/dist/commands/migration-ref.mjs.map +1 -1
  41. package/dist/commands/migration-show.d.mts +13 -7
  42. package/dist/commands/migration-show.d.mts.map +1 -1
  43. package/dist/commands/migration-show.mjs +34 -36
  44. package/dist/commands/migration-show.mjs.map +1 -1
  45. package/dist/commands/migration-status.d.mts +23 -5
  46. package/dist/commands/migration-status.d.mts.map +1 -1
  47. package/dist/commands/migration-status.mjs +2 -4
  48. package/dist/{config-loader-C25b63rJ.mjs → config-loader-B6sJjXTv.mjs} +3 -5
  49. package/dist/config-loader-B6sJjXTv.mjs.map +1 -0
  50. package/dist/config-loader.d.mts +0 -1
  51. package/dist/config-loader.d.mts.map +1 -1
  52. package/dist/config-loader.mjs +2 -3
  53. package/dist/contract-emit-B3ChISB_.mjs +338 -0
  54. package/dist/contract-emit-B3ChISB_.mjs.map +1 -0
  55. package/dist/contract-emit-DkMqO7f2.mjs +148 -0
  56. package/dist/contract-emit-DkMqO7f2.mjs.map +1 -0
  57. package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-CF6ogEJ_.mjs} +4 -6
  58. package/dist/contract-enrichment-CF6ogEJ_.mjs.map +1 -0
  59. package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-BDKAE0B0.mjs} +12 -22
  60. package/dist/contract-infer-BDKAE0B0.mjs.map +1 -0
  61. package/dist/db-verify-B4TdDKOI.mjs +403 -0
  62. package/dist/db-verify-B4TdDKOI.mjs.map +1 -0
  63. package/dist/exports/config-types.mjs +1 -2
  64. package/dist/exports/control-api.d.mts +287 -29
  65. package/dist/exports/control-api.d.mts.map +1 -1
  66. package/dist/exports/control-api.mjs +4 -6
  67. package/dist/exports/index.d.mts.map +1 -1
  68. package/dist/exports/index.mjs +28 -30
  69. package/dist/exports/index.mjs.map +1 -1
  70. package/dist/exports/init-output.d.mts +2 -4
  71. package/dist/exports/init-output.d.mts.map +1 -1
  72. package/dist/exports/init-output.mjs +2 -3
  73. package/dist/{framework-components-Cr--XBKy.mjs → framework-components-gwAHl7ml.mjs} +3 -4
  74. package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-gwAHl7ml.mjs.map} +1 -1
  75. package/dist/{init-C5220SY9.mjs → init-Deo7U8_U.mjs} +26 -35
  76. package/dist/init-Deo7U8_U.mjs.map +1 -0
  77. package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-BAgQMYpD.mjs} +10 -11
  78. package/dist/inspect-live-schema-BAgQMYpD.mjs.map +1 -0
  79. package/dist/migration-cli.d.mts +41 -12
  80. package/dist/migration-cli.d.mts.map +1 -1
  81. package/dist/migration-cli.mjs +309 -86
  82. package/dist/migration-cli.mjs.map +1 -1
  83. package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-B8J702Uh.mjs} +8 -9
  84. package/dist/migration-command-scaffold-B8J702Uh.mjs.map +1 -0
  85. package/dist/migration-plan-BcKNnTM7.mjs +530 -0
  86. package/dist/migration-plan-BcKNnTM7.mjs.map +1 -0
  87. package/dist/{migration-status-DUMiH8_G.mjs → migration-status-CjwB2of-.mjs} +117 -64
  88. package/dist/migration-status-CjwB2of-.mjs.map +1 -0
  89. package/dist/{migrations-Bo5WtTla.mjs → migrations-CIK94AJf.mjs} +43 -23
  90. package/dist/migrations-CIK94AJf.mjs.map +1 -0
  91. package/dist/{output-BpcQrnnq.mjs → output-DnjfCC_u.mjs} +9 -3
  92. package/dist/output-DnjfCC_u.mjs.map +1 -0
  93. package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-xASh41wr.mjs} +2 -2
  94. package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-xASh41wr.mjs.map} +1 -1
  95. package/dist/{result-handler-Ba3zWQsI.mjs → result-handler-DWb1rFS-.mjs} +52 -27
  96. package/dist/result-handler-DWb1rFS-.mjs.map +1 -0
  97. package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-zaRDhJnP.mjs} +2 -6
  98. package/dist/{terminal-ui-C3ZLwQxK.mjs.map → terminal-ui-zaRDhJnP.mjs.map} +1 -1
  99. package/dist/{verify-Bkycc-Tf.mjs → verify-BEIa9638.mjs} +3 -4
  100. package/dist/verify-BEIa9638.mjs.map +1 -0
  101. package/package.json +19 -17
  102. package/dist/cli-errors-BFYgBH3L.d.mts +0 -4
  103. package/dist/cli-errors-Cd79vmTH.mjs +0 -5
  104. package/dist/client-CrsnY58k.mjs +0 -997
  105. package/dist/client-CrsnY58k.mjs.map +0 -1
  106. package/dist/commands/db-verify.mjs.map +0 -1
  107. package/dist/commands/migration-plan.mjs.map +0 -1
  108. package/dist/config-loader-C25b63rJ.mjs.map +0 -1
  109. package/dist/contract-emit--feXyNd7.mjs +0 -4
  110. package/dist/contract-emit-NJ01hiiv.mjs +0 -195
  111. package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
  112. package/dist/contract-emit-V5SSitUT.mjs +0 -122
  113. package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
  114. package/dist/contract-enrichment-CAOELa-H.mjs.map +0 -1
  115. package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
  116. package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
  117. package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
  118. package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
  119. package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
  120. package/dist/init-C5220SY9.mjs.map +0 -1
  121. package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
  122. package/dist/migration-command-scaffold-B3B09et6.mjs.map +0 -1
  123. package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
  124. package/dist/migrations-Bo5WtTla.mjs.map +0 -1
  125. package/dist/output-BpcQrnnq.mjs.map +0 -1
  126. package/dist/result-handler-Ba3zWQsI.mjs.map +0 -1
  127. package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
  128. package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
  129. package/dist/verify-Bkycc-Tf.mjs.map +0 -1
@@ -1,14 +1,12 @@
1
- import "../config-loader-C25b63rJ.mjs";
2
- import { _ as errorUnexpected, a as errorContractValidationFailed, f as errorMigrationPlanningFailed, n as ERROR_CODE_DESTRUCTIVE_CHANGES, p as errorRunnerFailed, s as errorDestructiveChanges, t as CliStructuredError } from "../cli-errors-Cd79vmTH.mjs";
3
- import { n as ContractValidationError } from "../client-CrsnY58k.mjs";
4
- import { t as TerminalUI } from "../terminal-ui-C3ZLwQxK.mjs";
5
- import { d as setCommandExamples, l as sanitizeErrorMessage, m as parseGlobalFlags, t as handleResult, u as setCommandDescriptions } from "../result-handler-Ba3zWQsI.mjs";
6
- import { i as formatMigrationPlanOutput, n as formatMigrationApplyOutput, r as formatMigrationJson } from "../migrations-Bo5WtTla.mjs";
7
- import { n as prepareMigrationContext, t as addMigrationCommandOptions } from "../migration-command-scaffold-B3B09et6.mjs";
1
+ import { _ as errorUnexpected, a as errorContractValidationFailed, f as errorMigrationPlanningFailed, n as ERROR_CODE_DESTRUCTIVE_CHANGES, p as errorRunnerFailed, s as errorDestructiveChanges, t as CliStructuredError } from "../cli-errors-D3_sMh2K.mjs";
2
+ import { t as TerminalUI } from "../terminal-ui-zaRDhJnP.mjs";
3
+ import { d as setCommandDescriptions, f as setCommandExamples, g as parseGlobalFlags, l as resolveMigrationPaths, t as handleResult, u as sanitizeErrorMessage } from "../result-handler-DWb1rFS-.mjs";
4
+ import { a as ContractValidationError } from "../client-0ZX24FXF.mjs";
5
+ import { i as formatMigrationPlanOutput, n as formatMigrationApplyOutput, r as formatMigrationJson } from "../migrations-CIK94AJf.mjs";
6
+ import { n as prepareMigrationContext, t as addMigrationCommandOptions } from "../migration-command-scaffold-B8J702Uh.mjs";
8
7
  import { Command } from "commander";
9
- import { notOk, ok } from "@prisma-next/utils/result";
10
8
  import { ifDefined } from "@prisma-next/utils/defined";
11
-
9
+ import { notOk, ok } from "@prisma-next/utils/result";
12
10
  //#region src/commands/db-update.ts
13
11
  /**
14
12
  * Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.
@@ -38,12 +36,14 @@ async function executeDbUpdateCommand(options, flags, ui, startTime) {
38
36
  url: "https://pris.ly/db-update"
39
37
  });
40
38
  if (!ctxResult.ok) return ctxResult;
41
- const { client, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
39
+ const { client, config, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;
40
+ const { migrationsDir } = resolveMigrationPaths(options.config, config);
42
41
  try {
42
+ await client.connect(dbConnection);
43
43
  const result = await client.dbUpdate({
44
44
  contract: contractJson,
45
45
  mode: options.dryRun ? "plan" : "apply",
46
- connection: dbConnection,
46
+ migrationsDir,
47
47
  ...flags.yes ? { acceptDataLoss: true } : {},
48
48
  onProgress
49
49
  });
@@ -62,7 +62,7 @@ async function executeDbUpdateCommand(options, flags, ui, startTime) {
62
62
  label: op.label,
63
63
  operationClass: op.operationClass
64
64
  })),
65
- ...ifDefined("sql", result.value.plan.sql)
65
+ ...ifDefined("preview", result.value.plan.preview)
66
66
  },
67
67
  ...ifDefined("execution", result.value.execution ? {
68
68
  operationsPlanned: result.value.execution.operationsPlanned,
@@ -116,7 +116,7 @@ function createDbUpdateCommand() {
116
116
  });
117
117
  return command;
118
118
  }
119
-
120
119
  //#endregion
121
120
  export { createDbUpdateCommand };
121
+
122
122
  //# sourceMappingURL=db-update.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-update.mjs","names":["exhaustive: never"],"sources":["../../src/commands/db-update.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { ContractValidationError } from '../control-api/errors';\nimport type { DbUpdateFailure } from '../control-api/types';\nimport {\n CliStructuredError,\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorContractValidationFailed,\n errorDestructiveChanges,\n errorMigrationPlanningFailed,\n errorRunnerFailed,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport type { MigrationCommandOptions } from '../utils/command-helpers';\nimport {\n sanitizeErrorMessage,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport {\n formatMigrationApplyOutput,\n formatMigrationJson,\n formatMigrationPlanOutput,\n type MigrationCommandResult,\n} from '../utils/formatters/migrations';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport {\n addMigrationCommandOptions,\n prepareMigrationContext,\n} from '../utils/migration-command-scaffold';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ntype DbUpdateOptions = MigrationCommandOptions;\n\n/**\n * Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.\n */\nfunction mapDbUpdateFailure(failure: DbUpdateFailure): CliStructuredError {\n if (failure.code === 'PLANNING_FAILED') {\n return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });\n }\n\n if (failure.code === 'RUNNER_FAILED') {\n return errorRunnerFailed(failure.summary, {\n why: failure.why ?? 'Migration runner failed',\n fix: 'Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n if (failure.code === 'DESTRUCTIVE_CHANGES') {\n return errorDestructiveChanges(failure.summary, {\n ...ifDefined('why', failure.why),\n fix: 'Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n const exhaustive: never = failure.code;\n throw new Error(`Unhandled DbUpdateFailure code: ${exhaustive}`);\n}\n\n/**\n * Executes the db update command and returns a structured Result.\n */\nasync function executeDbUpdateCommand(\n options: DbUpdateOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrationCommandResult, CliStructuredError>> {\n // Prepare shared migration context (config, contract, connection, client)\n const ctxResult = await prepareMigrationContext(options, flags, ui, {\n commandName: 'db update',\n description: 'Update your database schema to match your contract',\n url: 'https://pris.ly/db-update',\n });\n if (!ctxResult.ok) {\n return ctxResult;\n }\n const { client, contractJson, dbConnection, onProgress, contractPathAbsolute } = ctxResult.value;\n\n try {\n // Call dbUpdate with connection and progress callback\n const result = await client.dbUpdate({\n contract: contractJson,\n mode: options.dryRun ? 'plan' : 'apply',\n connection: dbConnection,\n ...(flags.yes ? { acceptDataLoss: true } : {}),\n onProgress,\n });\n\n // Handle failures by mapping to CLI structured error\n if (!result.ok) {\n return notOk(mapDbUpdateFailure(result.failure));\n }\n\n // Convert success result to CLI output format\n const dbUpdateResult: MigrationCommandResult = {\n ok: true,\n mode: result.value.mode,\n plan: {\n targetId: ctxResult.value.config.target.targetId,\n destination: {\n storageHash: result.value.destination.storageHash,\n ...ifDefined('profileHash', result.value.destination.profileHash),\n },\n operations: result.value.plan.operations.map((op) => ({\n id: op.id,\n label: op.label,\n operationClass: op.operationClass,\n })),\n ...ifDefined('sql', result.value.plan.sql),\n },\n ...ifDefined(\n 'execution',\n result.value.execution\n ? {\n operationsPlanned: result.value.execution.operationsPlanned,\n operationsExecuted: result.value.execution.operationsExecuted,\n }\n : undefined,\n ),\n ...ifDefined(\n 'marker',\n result.value.marker\n ? {\n storageHash: result.value.marker.storageHash,\n ...ifDefined('profileHash', result.value.marker.profileHash),\n }\n : undefined,\n ),\n summary: result.value.summary,\n timings: { total: Date.now() - startTime },\n };\n\n return ok(dbUpdateResult);\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n if (error instanceof ContractValidationError) {\n return notOk(\n errorContractValidationFailed(`Contract validation failed: ${error.message}`, {\n where: { path: contractPathAbsolute },\n }),\n );\n }\n\n const rawMessage = error instanceof Error ? error.message : String(error);\n const safeMessage = sanitizeErrorMessage(\n rawMessage,\n typeof dbConnection === 'string' ? dbConnection : undefined,\n );\n return notOk(\n errorUnexpected(safeMessage, {\n why: `Unexpected error during db update: ${safeMessage}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createDbUpdateCommand(): Command {\n const command = new Command('update');\n setCommandDescriptions(\n command,\n 'Update your database schema to match your contract',\n 'Compares your database schema to the emitted contract and applies the necessary\\n' +\n 'changes. Works on any database, whether or not it has been initialized with `db init`.\\n' +\n 'Destructive operations prompt for confirmation in interactive mode. Use -y to\\n' +\n 'auto-accept or --dry-run to preview first.',\n );\n setCommandExamples(command, [\n 'prisma-next db update --db $DATABASE_URL',\n 'prisma-next db update --db $DATABASE_URL --dry-run',\n ]);\n addMigrationCommandOptions(command);\n command.action(async (options: DbUpdateOptions) => {\n const flags = parseGlobalFlags(options);\n const startTime = Date.now();\n\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n\n let result = await executeDbUpdateCommand(options, flags, ui, startTime);\n\n // Interactive confirmation for destructive operations:\n // When the control API rejects destructive changes, prompt the user instead of failing.\n // In non-interactive mode (CI, piped, --no-interactive, --json), the error is returned as-is.\n if (\n !result.ok &&\n result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES &&\n flags.interactive &&\n !flags.json &&\n !flags.yes\n ) {\n const meta = result.failure.meta as\n | { destructiveOperations?: readonly { id: string; label: string }[] }\n | undefined;\n const destructiveOps = meta?.destructiveOperations ?? [];\n\n if (destructiveOps.length > 0) {\n ui.warn(\n `${destructiveOps.length} destructive operation(s) that may cause data loss:\\n${destructiveOps.map((op) => ` ${ui.yellow('▸')} ${op.label}`).join('\\n')}`,\n );\n }\n\n const confirmed = await ui.confirm('Apply destructive changes? This cannot be undone.');\n\n if (confirmed) {\n result = await executeDbUpdateCommand(options, { ...flags, yes: true }, ui, Date.now());\n }\n }\n\n const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {\n if (flags.json) {\n ui.output(formatMigrationJson(dbUpdateResult));\n } else {\n const output =\n dbUpdateResult.mode === 'plan'\n ? formatMigrationPlanOutput(dbUpdateResult, flags)\n : formatMigrationApplyOutput(dbUpdateResult, flags);\n if (output) {\n ui.log(output);\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,mBAAmB,SAA8C;AACxE,KAAI,QAAQ,SAAS,kBACnB,QAAO,6BAA6B,EAAE,WAAW,QAAQ,aAAa,EAAE,EAAE,CAAC;AAG7E,KAAI,QAAQ,SAAS,gBACnB,QAAO,kBAAkB,QAAQ,SAAS;EACxC,KAAK,QAAQ,OAAO;EACpB,KAAK;EACL,GAAG,UAAU,QAAQ,QAAQ,KAAK;EACnC,CAAC;AAGJ,KAAI,QAAQ,SAAS,sBACnB,QAAO,wBAAwB,QAAQ,SAAS;EAC9C,GAAG,UAAU,OAAO,QAAQ,IAAI;EAChC,KAAK;EACL,GAAG,UAAU,QAAQ,QAAQ,KAAK;EACnC,CAAC;CAGJ,MAAMA,aAAoB,QAAQ;AAClC,OAAM,IAAI,MAAM,mCAAmC,aAAa;;;;;AAMlE,eAAe,uBACb,SACA,OACA,IACA,WAC6D;CAE7D,MAAM,YAAY,MAAM,wBAAwB,SAAS,OAAO,IAAI;EAClE,aAAa;EACb,aAAa;EACb,KAAK;EACN,CAAC;AACF,KAAI,CAAC,UAAU,GACb,QAAO;CAET,MAAM,EAAE,QAAQ,cAAc,cAAc,YAAY,yBAAyB,UAAU;AAE3F,KAAI;EAEF,MAAM,SAAS,MAAM,OAAO,SAAS;GACnC,UAAU;GACV,MAAM,QAAQ,SAAS,SAAS;GAChC,YAAY;GACZ,GAAI,MAAM,MAAM,EAAE,gBAAgB,MAAM,GAAG,EAAE;GAC7C;GACD,CAAC;AAGF,MAAI,CAAC,OAAO,GACV,QAAO,MAAM,mBAAmB,OAAO,QAAQ,CAAC;AA0ClD,SAAO,GAtCwC;GAC7C,IAAI;GACJ,MAAM,OAAO,MAAM;GACnB,MAAM;IACJ,UAAU,UAAU,MAAM,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AAM,YAAY,KAAK,KAAK;EAE5B,MAAM,KAAK,IAAI,WAAW;GAAE,OAAO,MAAM;GAAO,aAAa,MAAM;GAAa,CAAC;EAEjF,IAAI,SAAS,MAAM,uBAAuB,SAAS,OAAO,IAAI,UAAU;AAKxE,MACE,CAAC,OAAO,MACR,OAAO,QAAQ,SAAS,kCACxB,MAAM,eACN,CAAC,MAAM,QACP,CAAC,MAAM,KACP;GAIA,MAAM,iBAHO,OAAO,QAAQ,MAGC,yBAAyB,EAAE;AAExD,OAAI,eAAe,SAAS,EAC1B,IAAG,KACD,GAAG,eAAe,OAAO,uDAAuD,eAAe,KAAK,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,KAAK,KAAK,GACzJ;AAKH,OAFkB,MAAM,GAAG,QAAQ,oDAAoD,CAGrF,UAAS,MAAM,uBAAuB,SAAS;IAAE,GAAG;IAAO,KAAK;IAAM,EAAE,IAAI,KAAK,KAAK,CAAC;;EAI3F,MAAM,WAAW,aAAa,QAAQ,OAAO,KAAK,mBAAmB;AACnE,OAAI,MAAM,KACR,IAAG,OAAO,oBAAoB,eAAe,CAAC;QACzC;IACL,MAAM,SACJ,eAAe,SAAS,SACpB,0BAA0B,gBAAgB,MAAM,GAChD,2BAA2B,gBAAgB,MAAM;AACvD,QAAI,OACF,IAAG,IAAI,OAAO;;IAGlB;AACF,UAAQ,KAAK,SAAS;GACtB;AAEF,QAAO"}
1
+ {"version":3,"file":"db-update.mjs","names":[],"sources":["../../src/commands/db-update.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { ContractValidationError } from '../control-api/errors';\nimport type { DbUpdateFailure } from '../control-api/types';\nimport {\n CliStructuredError,\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorContractValidationFailed,\n errorDestructiveChanges,\n errorMigrationPlanningFailed,\n errorRunnerFailed,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport type { MigrationCommandOptions } from '../utils/command-helpers';\nimport {\n resolveMigrationPaths,\n sanitizeErrorMessage,\n setCommandDescriptions,\n setCommandExamples,\n} from '../utils/command-helpers';\nimport {\n formatMigrationApplyOutput,\n formatMigrationJson,\n formatMigrationPlanOutput,\n type MigrationCommandResult,\n} from '../utils/formatters/migrations';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport {\n addMigrationCommandOptions,\n prepareMigrationContext,\n} from '../utils/migration-command-scaffold';\nimport { handleResult } from '../utils/result-handler';\nimport { TerminalUI } from '../utils/terminal-ui';\n\ntype DbUpdateOptions = MigrationCommandOptions;\n\n/**\n * Maps a DbUpdateFailure to a CliStructuredError for consistent error handling.\n */\nfunction mapDbUpdateFailure(failure: DbUpdateFailure): CliStructuredError {\n if (failure.code === 'PLANNING_FAILED') {\n return errorMigrationPlanningFailed({ conflicts: failure.conflicts ?? [] });\n }\n\n if (failure.code === 'RUNNER_FAILED') {\n return errorRunnerFailed(failure.summary, {\n why: failure.why ?? 'Migration runner failed',\n fix: 'Inspect the reported conflict, reconcile schema drift if needed, then re-run `prisma-next db update`',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n if (failure.code === 'DESTRUCTIVE_CHANGES') {\n return errorDestructiveChanges(failure.summary, {\n ...ifDefined('why', failure.why),\n fix: 'Re-run with `-y` to apply destructive changes, or use `--dry-run` to preview first',\n ...ifDefined('meta', failure.meta),\n });\n }\n\n const exhaustive: never = failure.code;\n throw new Error(`Unhandled DbUpdateFailure code: ${exhaustive}`);\n}\n\n/**\n * Executes the db update command and returns a structured Result.\n */\nasync function executeDbUpdateCommand(\n options: DbUpdateOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n startTime: number,\n): Promise<Result<MigrationCommandResult, CliStructuredError>> {\n // Prepare shared migration context (config, contract, connection, client)\n const ctxResult = await prepareMigrationContext(options, flags, ui, {\n commandName: 'db update',\n description: 'Update your database schema to match your contract',\n url: 'https://pris.ly/db-update',\n });\n if (!ctxResult.ok) {\n return ctxResult;\n }\n const { client, config, contractJson, dbConnection, onProgress, contractPathAbsolute } =\n ctxResult.value;\n const { migrationsDir } = resolveMigrationPaths(options.config, config);\n\n try {\n await client.connect(dbConnection);\n\n const result = await client.dbUpdate({\n contract: contractJson,\n mode: options.dryRun ? 'plan' : 'apply',\n migrationsDir,\n ...(flags.yes ? { acceptDataLoss: true } : {}),\n onProgress,\n });\n\n // Handle failures by mapping to CLI structured error\n if (!result.ok) {\n return notOk(mapDbUpdateFailure(result.failure));\n }\n\n // Convert success result to CLI output format\n const dbUpdateResult: MigrationCommandResult = {\n ok: true,\n mode: result.value.mode,\n plan: {\n targetId: ctxResult.value.config.target.targetId,\n destination: {\n storageHash: result.value.destination.storageHash,\n ...ifDefined('profileHash', result.value.destination.profileHash),\n },\n operations: result.value.plan.operations.map((op) => ({\n id: op.id,\n label: op.label,\n operationClass: op.operationClass,\n })),\n ...ifDefined('preview', result.value.plan.preview),\n },\n ...ifDefined(\n 'execution',\n result.value.execution\n ? {\n operationsPlanned: result.value.execution.operationsPlanned,\n operationsExecuted: result.value.execution.operationsExecuted,\n }\n : undefined,\n ),\n ...ifDefined(\n 'marker',\n result.value.marker\n ? {\n storageHash: result.value.marker.storageHash,\n ...ifDefined('profileHash', result.value.marker.profileHash),\n }\n : undefined,\n ),\n summary: result.value.summary,\n timings: { total: Date.now() - startTime },\n };\n\n return ok(dbUpdateResult);\n } catch (error) {\n if (CliStructuredError.is(error)) {\n return notOk(error);\n }\n\n if (error instanceof ContractValidationError) {\n return notOk(\n errorContractValidationFailed(`Contract validation failed: ${error.message}`, {\n where: { path: contractPathAbsolute },\n }),\n );\n }\n\n const rawMessage = error instanceof Error ? error.message : String(error);\n const safeMessage = sanitizeErrorMessage(\n rawMessage,\n typeof dbConnection === 'string' ? dbConnection : undefined,\n );\n return notOk(\n errorUnexpected(safeMessage, {\n why: `Unexpected error during db update: ${safeMessage}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createDbUpdateCommand(): Command {\n const command = new Command('update');\n setCommandDescriptions(\n command,\n 'Update your database schema to match your contract',\n 'Compares your database schema to the emitted contract and applies the necessary\\n' +\n 'changes. Works on any database, whether or not it has been initialized with `db init`.\\n' +\n 'Destructive operations prompt for confirmation in interactive mode. Use -y to\\n' +\n 'auto-accept or --dry-run to preview first.',\n );\n setCommandExamples(command, [\n 'prisma-next db update --db $DATABASE_URL',\n 'prisma-next db update --db $DATABASE_URL --dry-run',\n ]);\n addMigrationCommandOptions(command);\n command.action(async (options: DbUpdateOptions) => {\n const flags = parseGlobalFlags(options);\n const startTime = Date.now();\n\n const ui = new TerminalUI({ color: flags.color, interactive: flags.interactive });\n\n let result = await executeDbUpdateCommand(options, flags, ui, startTime);\n\n // Interactive confirmation for destructive operations:\n // When the control API rejects destructive changes, prompt the user instead of failing.\n // In non-interactive mode (CI, piped, --no-interactive, --json), the error is returned as-is.\n if (\n !result.ok &&\n result.failure.code === ERROR_CODE_DESTRUCTIVE_CHANGES &&\n flags.interactive &&\n !flags.json &&\n !flags.yes\n ) {\n const meta = result.failure.meta as\n | { destructiveOperations?: readonly { id: string; label: string }[] }\n | undefined;\n const destructiveOps = meta?.destructiveOperations ?? [];\n\n if (destructiveOps.length > 0) {\n ui.warn(\n `${destructiveOps.length} destructive operation(s) that may cause data loss:\\n${destructiveOps.map((op) => ` ${ui.yellow('▸')} ${op.label}`).join('\\n')}`,\n );\n }\n\n const confirmed = await ui.confirm('Apply destructive changes? This cannot be undone.');\n\n if (confirmed) {\n result = await executeDbUpdateCommand(options, { ...flags, yes: true }, ui, Date.now());\n }\n }\n\n const exitCode = handleResult(result, flags, ui, (dbUpdateResult) => {\n if (flags.json) {\n ui.output(formatMigrationJson(dbUpdateResult));\n } else {\n const output =\n dbUpdateResult.mode === 'plan'\n ? formatMigrationPlanOutput(dbUpdateResult, flags)\n : formatMigrationApplyOutput(dbUpdateResult, flags);\n if (output) {\n ui.log(output);\n }\n }\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YAAY,KAAK,KAAK;EAE5B,MAAM,KAAK,IAAI,WAAW;GAAE,OAAO,MAAM;GAAO,aAAa,MAAM;GAAa,CAAC;EAEjF,IAAI,SAAS,MAAM,uBAAuB,SAAS,OAAO,IAAI,UAAU;EAKxE,IACE,CAAC,OAAO,MACR,OAAO,QAAQ,SAAS,kCACxB,MAAM,eACN,CAAC,MAAM,QACP,CAAC,MAAM,KACP;GAIA,MAAM,iBAHO,OAAO,QAAQ,MAGC,yBAAyB,EAAE;GAExD,IAAI,eAAe,SAAS,GAC1B,GAAG,KACD,GAAG,eAAe,OAAO,uDAAuD,eAAe,KAAK,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,KAAK,KAAK,GACzJ;GAKH,IAAI,MAFoB,GAAG,QAAQ,oDAAoD,EAGrF,SAAS,MAAM,uBAAuB,SAAS;IAAE,GAAG;IAAO,KAAK;IAAM,EAAE,IAAI,KAAK,KAAK,CAAC;;EAI3F,MAAM,WAAW,aAAa,QAAQ,OAAO,KAAK,mBAAmB;GACnE,IAAI,MAAM,MACR,GAAG,OAAO,oBAAoB,eAAe,CAAC;QACzC;IACL,MAAM,SACJ,eAAe,SAAS,SACpB,0BAA0B,gBAAgB,MAAM,GAChD,2BAA2B,gBAAgB,MAAM;IACvD,IAAI,QACF,GAAG,IAAI,OAAO;;IAGlB;EACF,QAAQ,KAAK,SAAS;GACtB;CAEF,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"db-verify.d.mts","names":[],"sources":["../../src/commands/db-verify.ts"],"sourcesContent":[],"mappings":";;;iBAmcgB,qBAAA,CAAA,GAAyB"}
1
+ {"version":3,"file":"db-verify.d.mts","names":[],"sources":["../../src/commands/db-verify.ts"],"mappings":";;;iBAmegB,qBAAA,CAAA,GAAyB,OAAA"}
@@ -1,322 +1,2 @@
1
- import { t as loadConfig } from "../config-loader-C25b63rJ.mjs";
2
- import { _ as errorUnexpected, a as errorContractValidationFailed, c as errorDriverRequired, d as errorMarkerMissing, g as errorTargetMismatch, l as errorFileNotFound, m as errorRuntime, o as errorDatabaseConnectionRequired, t as CliStructuredError, u as errorHashMismatch } from "../cli-errors-Cd79vmTH.mjs";
3
- import { n as ContractValidationError, t as createControlClient } from "../client-CrsnY58k.mjs";
4
- import { t as TerminalUI } from "../terminal-ui-C3ZLwQxK.mjs";
5
- import { _ as formatStyledHeader, a as maskConnectionUrl, d as setCommandExamples, m as parseGlobalFlags, n as addGlobalOptions, s as resolveContractPath, t as handleResult, u as setCommandDescriptions } from "../result-handler-Ba3zWQsI.mjs";
6
- import { t as createProgressAdapter } from "../progress-adapter-DvQWB1nK.mjs";
7
- import { c as formatVerifyOutput, i as formatSchemaVerifyOutput, r as formatSchemaVerifyJson, s as formatVerifyJson } from "../verify-Bkycc-Tf.mjs";
8
- import { Command } from "commander";
9
- import { notOk, ok } from "@prisma-next/utils/result";
10
- import { relative, resolve } from "pathe";
11
- import { ifDefined } from "@prisma-next/utils/defined";
12
- import { VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH } from "@prisma-next/framework-components/control";
13
- import { readFile } from "node:fs/promises";
14
-
15
- //#region src/commands/db-verify.ts
16
- /**
17
- * Maps a VerifyDatabaseResult failure to a CliStructuredError.
18
- */
19
- function mapVerifyFailure(verifyResult) {
20
- if (!verifyResult.ok && verifyResult.code) {
21
- if (verifyResult.code === VERIFY_CODE_MARKER_MISSING) return errorMarkerMissing();
22
- if (verifyResult.code === VERIFY_CODE_HASH_MISMATCH) {
23
- const storageMatch = verifyResult.marker?.storageHash === verifyResult.contract.storageHash;
24
- const profileMatch = !verifyResult.contract.profileHash || verifyResult.marker?.profileHash === verifyResult.contract.profileHash;
25
- if (!storageMatch) return errorHashMismatch({
26
- why: "Contract storageHash does not match database marker",
27
- expected: verifyResult.contract.storageHash,
28
- ...ifDefined("actual", verifyResult.marker?.storageHash)
29
- });
30
- return errorHashMismatch({
31
- why: profileMatch ? "Contract hash does not match database marker" : "Contract profileHash does not match database marker",
32
- ...ifDefined("expected", verifyResult.contract.profileHash),
33
- ...ifDefined("actual", verifyResult.marker?.profileHash)
34
- });
35
- }
36
- if (verifyResult.code === VERIFY_CODE_TARGET_MISMATCH) return errorTargetMismatch(verifyResult.target.expected, verifyResult.target.actual ?? "unknown");
37
- }
38
- return errorRuntime(verifyResult.summary);
39
- }
40
- function errorInvalidVerifyMode(options) {
41
- return new CliStructuredError("4012", "Invalid verify mode", {
42
- domain: "CLI",
43
- why: options.why,
44
- fix: options.fix,
45
- docsUrl: "https://pris.ly/db-verify"
46
- });
47
- }
48
- function resolveDbVerifyMode(options) {
49
- if (options.markerOnly && options.schemaOnly) return notOk(errorInvalidVerifyMode({
50
- why: "`--marker-only` and `--schema-only` cannot be used together",
51
- fix: "Choose one mode: omit both to check the marker and schema, use `--marker-only` to check only the marker, or use `--schema-only` to check only the live schema."
52
- }));
53
- if (options.markerOnly && options.strict) return notOk(errorInvalidVerifyMode({
54
- why: "`--strict` requires schema verification, but `--marker-only` skips it",
55
- fix: "Remove `--strict`, or use `db verify` / `db verify --schema-only` when you want to check the live schema in strict mode."
56
- }));
57
- if (options.schemaOnly) return ok("schema-only");
58
- if (options.markerOnly) return ok("marker-only");
59
- return ok("full");
60
- }
61
- function formatDbVerifyModeLabel(mode, strict) {
62
- if (mode === "marker-only") return "marker only";
63
- if (mode === "schema-only") return `schema only (${strict ? "strict" : "tolerant"})`;
64
- return `full (marker + schema, ${strict ? "strict" : "tolerant"})`;
65
- }
66
- function formatDbVerifyInvocation(mode, strict) {
67
- const args = ["db verify"];
68
- if (mode === "marker-only") args.push("--marker-only");
69
- if (mode === "schema-only") args.push("--schema-only");
70
- if (strict) args.push("--strict");
71
- return args.join(" ");
72
- }
73
- function createDbVerifyConnectionRequiredError(options) {
74
- const invocation = formatDbVerifyInvocation(options.mode, options.strict);
75
- return errorDatabaseConnectionRequired({
76
- why: `Database connection is required for ${invocation} (set db.connection in ${options.configPath}, or pass --db <url>)`,
77
- retryCommand: `prisma-next ${invocation} --db <url>`
78
- });
79
- }
80
- function renderVerifyHeader(paths, options, mode, flags, ui) {
81
- if (flags.json || flags.quiet) return;
82
- const description = mode === "schema-only" ? "Check whether the live database schema matches your contract" : mode === "marker-only" ? "Check whether the database marker matches your contract" : "Check whether the database marker and live schema match your contract";
83
- const details = [
84
- {
85
- label: "config",
86
- value: paths.configPath
87
- },
88
- {
89
- label: "contract",
90
- value: paths.contractPath
91
- },
92
- {
93
- label: "mode",
94
- value: formatDbVerifyModeLabel(mode, options.strict ?? false)
95
- }
96
- ];
97
- if (options.db) details.push({
98
- label: "database",
99
- value: maskConnectionUrl(options.db)
100
- });
101
- ui.stderr(formatStyledHeader({
102
- command: "db verify",
103
- description,
104
- url: "https://pris.ly/db-verify",
105
- details,
106
- flags
107
- }));
108
- }
109
- async function resolveVerifyPaths(options) {
110
- const config = await loadConfig(options.config);
111
- const configPath = options.config ? relative(process.cwd(), resolve(options.config)) : "prisma-next.config.ts";
112
- const contractPathAbsolute = resolveContractPath(config);
113
- return {
114
- config,
115
- configPath,
116
- contractPathAbsolute,
117
- contractPath: relative(process.cwd(), contractPathAbsolute)
118
- };
119
- }
120
- async function resolveVerifySetup(paths, options, mode) {
121
- const { config, configPath, contractPathAbsolute, contractPath } = paths;
122
- let contractJsonContent;
123
- try {
124
- contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
125
- } catch (error) {
126
- if (error instanceof Error && error.code === "ENOENT") return notOk(errorFileNotFound(contractPathAbsolute, {
127
- why: `Contract file not found at ${contractPathAbsolute}`,
128
- fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
129
- }));
130
- return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}` }));
131
- }
132
- let contractJson;
133
- try {
134
- contractJson = JSON.parse(contractJsonContent);
135
- } catch (error) {
136
- return notOk(errorContractValidationFailed(`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`, { where: { path: contractPathAbsolute } }));
137
- }
138
- const dbConnection = options.db ?? config.db?.connection;
139
- if (typeof dbConnection !== "string" || dbConnection.length === 0) return notOk(createDbVerifyConnectionRequiredError({
140
- configPath,
141
- mode,
142
- strict: options.strict ?? false
143
- }));
144
- if (!config.driver) return notOk(errorDriverRequired({ why: `Config.driver is required for ${formatDbVerifyInvocation(mode, options.strict ?? false)}` }));
145
- return ok({
146
- ...paths,
147
- contractJson,
148
- dbConnection
149
- });
150
- }
151
- function createVerifyClient(setup) {
152
- return createControlClient({
153
- family: setup.config.family,
154
- target: setup.config.target,
155
- adapter: setup.config.adapter,
156
- driver: setup.config.driver,
157
- extensionPacks: setup.config.extensionPacks ?? []
158
- });
159
- }
160
- function wrapVerifyError(error, contractPathAbsolute, modeLabel) {
161
- if (error instanceof CliStructuredError) return notOk(error);
162
- if (error instanceof ContractValidationError) return notOk(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPathAbsolute } }));
163
- return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Unexpected error during ${modeLabel}: ${error instanceof Error ? error.message : String(error)}` }));
164
- }
165
- /**
166
- * Executes the db verify command and returns a structured Result.
167
- */
168
- async function executeDbVerifyCommand(options, flags, ui, mode) {
169
- const startTime = Date.now();
170
- const paths = await resolveVerifyPaths(options);
171
- renderVerifyHeader(paths, options, mode, flags, ui);
172
- const setupResult = await resolveVerifySetup(paths, options, mode);
173
- if (!setupResult.ok) return setupResult;
174
- const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;
175
- const client = createVerifyClient(setupResult.value);
176
- const onProgress = createProgressAdapter({
177
- ui,
178
- flags
179
- });
180
- try {
181
- const verifyResult = await client.verify({
182
- contract: contractJson,
183
- connection: dbConnection,
184
- onProgress
185
- });
186
- if (!verifyResult.ok) return notOk(mapVerifyFailure(verifyResult));
187
- if (mode === "marker-only") return ok({
188
- ok: true,
189
- mode: "marker-only",
190
- summary: "Database marker matches contract",
191
- contract: verifyResult.contract,
192
- marker: verifyResult.marker,
193
- target: verifyResult.target,
194
- ...ifDefined("missingCodecs", verifyResult.missingCodecs),
195
- ...ifDefined("codecCoverageSkipped", verifyResult.codecCoverageSkipped),
196
- warning: "Schema verification skipped because --marker-only was provided",
197
- meta: {
198
- ...verifyResult.meta ?? {},
199
- schemaVerification: "skipped"
200
- },
201
- timings: { total: Date.now() - startTime }
202
- });
203
- const schemaVerifyResult = await client.schemaVerify({
204
- contract: contractJson,
205
- strict: options.strict ?? false,
206
- onProgress
207
- });
208
- if (!schemaVerifyResult.ok) return notOk(schemaVerifyResult);
209
- return ok({
210
- ok: true,
211
- mode: "full",
212
- summary: "Database marker and schema match contract",
213
- contract: verifyResult.contract,
214
- marker: verifyResult.marker,
215
- target: verifyResult.target,
216
- ...ifDefined("missingCodecs", verifyResult.missingCodecs),
217
- ...ifDefined("codecCoverageSkipped", verifyResult.codecCoverageSkipped),
218
- schema: {
219
- summary: schemaVerifyResult.summary,
220
- counts: schemaVerifyResult.schema.counts,
221
- strict: schemaVerifyResult.meta?.strict ?? false
222
- },
223
- meta: {
224
- ...verifyResult.meta ?? {},
225
- schemaVerification: "performed"
226
- },
227
- timings: { total: Date.now() - startTime }
228
- });
229
- } catch (error) {
230
- return wrapVerifyError(error, contractPathAbsolute, "db verify");
231
- } finally {
232
- await client.close();
233
- }
234
- }
235
- async function executeDbSchemaOnlyVerifyCommand(options, flags, ui) {
236
- const paths = await resolveVerifyPaths(options);
237
- renderVerifyHeader(paths, options, "schema-only", flags, ui);
238
- const setupResult = await resolveVerifySetup(paths, options, "schema-only");
239
- if (!setupResult.ok) return setupResult;
240
- const { contractJson, dbConnection, contractPathAbsolute } = setupResult.value;
241
- const client = createVerifyClient(setupResult.value);
242
- const onProgress = createProgressAdapter({
243
- ui,
244
- flags
245
- });
246
- try {
247
- return ok(await client.schemaVerify({
248
- contract: contractJson,
249
- strict: options.strict ?? false,
250
- connection: dbConnection,
251
- onProgress
252
- }));
253
- } catch (error) {
254
- return wrapVerifyError(error, contractPathAbsolute, "db verify --schema-only");
255
- } finally {
256
- await client.close();
257
- }
258
- }
259
- function createDbVerifyCommand() {
260
- const command = new Command("verify");
261
- setCommandDescriptions(command, "Check whether the database marker and live schema match your contract", "Verifies the database marker first, then checks the database schema matches your contract.\nUse `--marker-only` for marker-only verification, `--schema-only` to skip marker checks and\ninspect only the live schema, and `--strict` to fail if the database includes elements\nnot present in the contract.");
262
- setCommandExamples(command, [
263
- "prisma-next db verify --db $DATABASE_URL",
264
- "prisma-next db verify --db $DATABASE_URL --strict",
265
- "prisma-next db verify --db $DATABASE_URL --schema-only",
266
- "prisma-next db verify --db $DATABASE_URL --schema-only --strict",
267
- "prisma-next db verify --db $DATABASE_URL --marker-only",
268
- "prisma-next db verify --db $DATABASE_URL --json"
269
- ]);
270
- addGlobalOptions(command).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--marker-only", "Skip schema verification and only check the database marker").option("--schema-only", "Skip marker verification and only check whether the live schema satisfies the contract").option("--strict", "Strict mode: schema elements not present in the contract are considered an error", false).action(async (options) => {
271
- const flags = parseGlobalFlags(options);
272
- const ui = new TerminalUI({
273
- color: flags.color,
274
- interactive: flags.interactive
275
- });
276
- const modeResult = resolveDbVerifyMode(options);
277
- if (!modeResult.ok) {
278
- const exitCode = handleResult(modeResult, flags, ui);
279
- process.exit(exitCode);
280
- }
281
- const mode = modeResult.value;
282
- if (mode === "schema-only") {
283
- const result$1 = await executeDbSchemaOnlyVerifyCommand(options, flags, ui);
284
- const exitCode = handleResult(result$1, flags, ui, (schemaVerifyResult) => {
285
- if (flags.json) ui.output(formatSchemaVerifyJson(schemaVerifyResult));
286
- else {
287
- const output = formatSchemaVerifyOutput(schemaVerifyResult, flags);
288
- if (output) ui.log(output);
289
- }
290
- });
291
- if (result$1.ok && !result$1.value.ok) process.exit(1);
292
- process.exit(exitCode);
293
- }
294
- const result = await executeDbVerifyCommand(options, flags, ui, mode);
295
- if (result.ok) {
296
- if (flags.json) ui.output(formatVerifyJson(result.value));
297
- else {
298
- const output = formatVerifyOutput(result.value, flags);
299
- if (output) ui.log(output);
300
- }
301
- process.exit(0);
302
- }
303
- if (CliStructuredError.is(result.failure)) {
304
- const exitCode = handleResult(result, flags, ui);
305
- process.exit(exitCode);
306
- }
307
- if (flags.json) ui.output(formatSchemaVerifyJson(result.failure));
308
- else {
309
- const output = formatSchemaVerifyOutput(result.failure, {
310
- ...flags,
311
- quiet: false
312
- });
313
- if (output) ui.log(output);
314
- }
315
- process.exit(1);
316
- });
317
- return command;
318
- }
319
-
320
- //#endregion
1
+ import { t as createDbVerifyCommand } from "../db-verify-B4TdDKOI.mjs";
321
2
  export { createDbVerifyCommand };
322
- //# sourceMappingURL=db-verify.mjs.map
@@ -8,7 +8,7 @@ interface MigrationApplyResult {
8
8
  readonly markerHash: string;
9
9
  readonly applied: readonly {
10
10
  readonly dirName: string;
11
- readonly from: string;
11
+ readonly from: string | null;
12
12
  readonly to: string;
13
13
  readonly operationsExecuted: number;
14
14
  }[];
@@ -19,11 +19,14 @@ interface MigrationApplyResult {
19
19
  readonly alternativeCount: number;
20
20
  readonly tieBreakReasons: readonly string[];
21
21
  readonly refName?: string;
22
+ readonly requiredInvariants: readonly string[];
23
+ readonly satisfiedInvariants: readonly string[];
22
24
  readonly selectedPath: readonly {
23
25
  readonly dirName: string;
24
- readonly migrationId: string;
26
+ readonly migrationHash: string;
25
27
  readonly from: string;
26
28
  readonly to: string;
29
+ readonly invariants: readonly string[];
27
30
  }[];
28
31
  };
29
32
  readonly timings: {
@@ -1 +1 @@
1
- {"version":3,"file":"migration-apply.d.mts","names":[],"sources":["../../src/commands/migration-apply.ts"],"sourcesContent":[],"mappings":";;;UA8CiB,oBAAA;;EAAA,SAAA,iBAAoB,EAAA,MAAA;EAiWrB,SAAA,eAAA,EAAA,MAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA3B,2BAAA,CAAA,GAA+B"}
1
+ {"version":3,"file":"migration-apply.d.mts","names":[],"sources":["../../src/commands/migration-apply.ts"],"mappings":";;;UAqDiB,oBAAA;EAAA,SACN,EAAA;EAAA,SACA,iBAAA;EAAA,SACA,eAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA;IAAA,SACE,OAAA;IAAA,SACA,IAAA;IAAA,SACA,EAAA;IAAA,SACA,kBAAA;EAAA;EAAA,SAEF,OAAA;EAAA,SACA,YAAA;IAAA,SACE,QAAA;IAAA,SACA,MAAA;IAAA,SACA,gBAAA;IAAA,SACA,eAAA;IAAA,SACA,OAAA;IAAA,SACA,kBAAA;IAAA,SACA,mBAAA;IAAA,SACA,YAAA;MAAA,SACE,OAAA;MAAA,SACA,aAAA;MAAA,SACA,IAAA;MAAA,SACA,EAAA;MAAA,SACA,UAAA;IAAA;EAAA;EAAA,SAGJ,OAAA;IAAA,SACE,KAAA;EAAA;AAAA;AAAA,iBAkVG,2BAAA,CAAA,GAA+B,OAAA"}