-
Notifications
You must be signed in to change notification settings - Fork 12
refactor(postgres): schema-node tree restructure — database→namespace→table→policy diff tree #894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
58b4a5a
17148dd
6705391
c446373
87ee213
e3524e1
519b8f9
912b2f0
5e11ab3
9096215
50692f4
c4d939b
1e0f676
03271fe
b3fe123
722d873
a834a40
a43576b
91248f6
a491335
e12408f
b696c21
349b1e4
fb34d8c
92a4a6b
7489e4f
3c3a96f
833e054
e9ed2aa
973000e
4e256f8
0627b8b
4db45b5
a836ec6
0bc6c36
70345d4
d4040d3
2ae324e
b85526c
e5c51a0
5e36733
689f650
a61c3f1
9e2e80f
8c3d4a1
9309fd0
14f5b7a
5fc61c8
9d56e8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { readFile } from 'node:fs/promises'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { loadConfig } from '@prisma-next/config-loader'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Contract } from '@prisma-next/contract/types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VerifyDatabaseResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VerifyDatabaseSchemaResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@prisma-next/framework-components/control'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { VerifyDatabaseResult } from '@prisma-next/framework-components/control'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createControlStack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VERIFY_CODE_HASH_MISMATCH, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -29,7 +26,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorTargetMismatch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errorUnexpected, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '../utils/cli-errors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { combineSchemaResults } from '../utils/combine-schema-results'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { type CombinedVerifyResult, combineVerifyResults } from '../utils/combine-verify-results'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addGlobalOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maskConnectionUrl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,7 +100,7 @@ function mapVerifyFailure(verifyResult: VerifyDatabaseResult): CliStructuredErro | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errorRuntime(verifyResult.summary); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type DbVerifyFailure = CliStructuredError | VerifyDatabaseSchemaResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type DbVerifyFailure = CliStructuredError | CombinedVerifyResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function errorInvalidVerifyMode(options: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readonly why: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -419,12 +416,13 @@ async function executeDbVerifyCommand( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const combined = combineSchemaResults( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const combined = combineVerifyResults( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.schemaResults, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.appSpaceId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options.strict ?? false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.unclaimed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!combined.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!combined.result.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return notOk(combined); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -438,10 +436,11 @@ async function executeDbVerifyCommand( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...ifDefined('missingCodecs', verifyResult.missingCodecs), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...ifDefined('codecCoverageSkipped', verifyResult.codecCoverageSkipped), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: combined.summary, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| counts: combined.schema.counts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strict: combined.meta?.strict ?? false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: combined.result.summary, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| counts: combined.result.schema.counts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| strict: combined.result.meta?.strict ?? false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unclaimed: combined.unclaimed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(verifyResult.meta ?? {}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaVerification: 'performed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -459,7 +458,7 @@ async function executeDbSchemaOnlyVerifyCommand( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options: DbVerifyOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flags: GlobalFlags, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui: TerminalUI, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<Result<VerifyDatabaseSchemaResult, CliStructuredError>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<Result<CombinedVerifyResult, CliStructuredError>> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const paths = await resolveVerifyPaths(options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderVerifyHeader(paths, options, 'schema-only', flags, ui); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -484,10 +483,11 @@ async function executeDbSchemaOnlyVerifyCommand( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!aggregateResult.ok) return notOk(aggregateResult.failure); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ok( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| combineSchemaResults( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| combineVerifyResults( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.schemaResults, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.appSpaceId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options.strict ?? false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aggregateResult.value.unclaimed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -542,18 +542,18 @@ export function createDbVerifyCommand(): Command { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (mode === 'schema-only') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await executeDbSchemaOnlyVerifyCommand(options, flags, ui); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const exitCode = handleResult(result, flags, ui, (schemaVerifyResult) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const exitCode = handleResult(result, flags, ui, (combined) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (flags.json) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.output(formatSchemaVerifyJson(schemaVerifyResult)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.output(formatSchemaVerifyJson(combined.result, combined.unclaimed)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const output = formatSchemaVerifyOutput(schemaVerifyResult, flags); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const output = formatSchemaVerifyOutput(combined.result, flags, combined.unclaimed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (output) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.log(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.ok && !result.value.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (result.ok && !result.value.result.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+545
to
+556
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Schema-only failures can exit silently under Unlike the full-mode failure branch below (Lines 583-591) which explicitly forces The line-range change summary for this segment describes "a forced 🐛 Proposed fix to force diagnostics on schema-only failures const exitCode = handleResult(result, flags, ui, (combined) => {
if (flags.json) {
ui.output(formatSchemaVerifyJson(combined.result, combined.unclaimed));
} else {
- const output = formatSchemaVerifyOutput(combined.result, flags, combined.unclaimed);
+ const outputFlags = combined.result.ok ? flags : { ...flags, quiet: false };
+ const output = formatSchemaVerifyOutput(combined.result, outputFlags, combined.unclaimed);
if (output) {
ui.log(output);
}
}
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -580,11 +580,15 @@ export function createDbVerifyCommand(): Command { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (flags.json) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.output(formatSchemaVerifyJson(result.failure)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.output(formatSchemaVerifyJson(result.failure.result, result.failure.unclaimed)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Always show schema-drift failures, even in quiet mode — exiting 1 without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // diagnostics is unhelpful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const output = formatSchemaVerifyOutput(result.failure, { ...flags, quiet: false }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const output = formatSchemaVerifyOutput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.failure.result, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { ...flags, quiet: false }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.failure.unclaimed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (output) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.log(output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird inversion of control. Why not just give it the list of issues?