Skip to content

fix(codegen): write prettier-stable schema snapshot - #43985

Open
kitlangton wants to merge 1 commit into
v2from
schema-snapshot-format
Open

fix(codegen): write prettier-stable schema snapshot#43985
kitlangton wants to merge 1 commit into
v2from
schema-snapshot-format

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Regenerating a database migration reformats the entire checked-in packages/core/schema.json, burying the real change in hundreds of lines of array-reflow noise. This applies the same treatment #23228 gave the OpenAPI documents: format the generated snapshot in place so regeneration diffs contain only real schema changes.

Before / After

Before: bun script/migration.ts raw-copies drizzle's snapshot.json, which emits every array multi-line. The checked-in snapshot is prettier-styled (short arrays collapsed), so adding a single column reflows every "columns": [...] array in the file — a 3-column addition produced a 206-line diff, ~170 of them formatting churn.

After: the snapshot is piped through prettier (parser: "json", printWidth: 120) before writing. The formatter is a byte-for-byte no-op on the current checked-in snapshot, and a test column addition now produces a 14-line diff.

How

  • packages/core/script/migration.ts: replaces the fs.copyFile of drizzle's snapshot with a formatted Bun.write, adding a formatJson helper mirroring the existing formatTypescript.
  • No behavior change for consumers: --check feeds the snapshot to drizzle as a parsed baseline and never byte-compares it, so formatting is invisible to validation.

Testing

  • Verified the formatter is a no-op on the checked-in schema.json (byte-identical input/output).
  • Exercised the write path with a throwaway column: generated migration, confirmed the new snapshot stays prettier-compact and diffs at 14 lines, then reverted.
  • bun script/migration.ts --check and bun typecheck clean from packages/core.

@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

No blocking issues found.

Nit: packages/core/script/migration.ts:200-203 — formatJson hardcodes the prettier options (parser: "json", printWidth: 120) rather than resolving the repo's shared prettier config. If the checked-in .prettierrc ever diverges (different print width, trailing-comma policy, etc.), regenerated snapshots will silently stop matching the prettier-styled copies again — the exact problem this fix addresses. Consider prettier.resolveConfig (or importing the shared config) so the two stay in sync automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants