refactor(views): unify view DDL into the single schema-diff path#69
Merged
Conversation
The schema-diff now owns ALL view DDL for every dialect, replacing the parallel computeProjectionMigrations / source-aware-diff emitter. One generator (emitViewDdl via buildProjectionViews) produces every CREATE VIEW; the diff produces create/drop/replace plus a dependency-recreate pass; each dialect renderer emits it. - migrate-ts: port view rendering into the sqlite/d1 emitter, drop the postgres-only guard; add diff Pass 2c (drop+recreate a view around a column-altering change to a table it reads), driven by a new ViewDescriptor.dependsOn; sqlite STAGE_ORDER drop-view=0 (before the recreate-and-copy, mirroring postgres); introspectD1 reads view bodies. - codegen-ts: buildProjectionViews is the single expected-view source (name/body/schema/dependsOn); emitViewDdl gains bodyOnly; resolve JOIN FK/PK to physical columns (naming strategy + @column) instead of a hardcoded snake_case guess; quote identifiers that need it so literal/ kebab columns survive postgres case-folding. - cli: emit all diff changes (tables + views) through one path; delete computeProjectionMigrations + the view-diff stack. Deletes source-aware-diff, view-diff, view-ddl-{postgres,sqlite}, expected-views, projection-migrations and their tests; removes the corresponding migrate-ts barrel exports. Validated: full unit suites green, postgres persistence-conformance (incl. a new recreate-view-on-column-type-change scenario), and a live from-empty platform migrate emitting exactly one correct CREATE VIEW. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The single emitViewDdl emitter renders aggregate views as one LEFT JOIN + GROUP BY (COUNT(DISTINCT) to survive the join), whereas the deleted migrate-ts emitter used correlated subqueries. The two are data-equivalent for a single has-many join — pinned by the projection-aggregate query scenarios (populated rows + the empty-program NULL case), which pass against real Postgres. Regenerate the committed canonical schema.postgres.sql (bun run gen:schema) and update the schema-artifact Phase B assertions from the correlated- subquery form to the JOIN+GROUP BY form. Also reflects view-body identifier quoting + strategy-resolved JOIN columns. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
dmealing
added a commit
that referenced
this pull request
Jun 22, 2026
Unifies all view DDL onto the single schema-diff path (PR #69): one emitter (emitViewDdl) for every CREATE VIEW, dependency-aware drop+ recreate in the diff, sqlite/d1 view rendering, naming-strategy-correct JOIN columns + identifier quoting. Aggregate views now render as LEFT JOIN + GROUP BY (data-equivalent to the prior correlated-subquery form). Bumps the 13 publish-candidate packages 0.11.4 → 0.11.5. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unify view DDL into the single schema-diff path
The schema-diff now owns all view DDL for every dialect, replacing the parallel
computeProjectionMigrations/source-aware-diffemitter. One generator (emitViewDdlviabuildProjectionViews) produces everyCREATE VIEW; the diff produces create/drop/replace plus a dependency-recreate pass; each dialect renderer emits it. This removes the "two places create views" duplication.Changes
ViewDescriptor.dependsOn); sqliteSTAGE_ORDERsetsdrop-view: 0so it precedes the recreate-and-copy (mirrors postgres);introspectD1now reads view bodies.buildProjectionViewsis the single expected-view source (name/body/schema/dependsOn);emitViewDdlgainsbodyOnly; JOIN FK/PK resolve to physical columns (naming strategy +@column) instead of a hardcoded snake_case guess; identifiers are quoted when needed soliteral/kebab-casecolumns survive postgres case-folding.computeProjectionMigrations+ the whole view-diff stack.Removed
source-aware-diff,view-diff,view-ddl-{postgres,sqlite},expected-views,projection-migrationsand their tests, plus the corresponding migrate-ts barrel exports.Validation
recreate-view-on-column-type-changescenario.CREATE VIEW.🤖 Generated with Claude Code
Unifying onto
emitViewDdlchanges how aggregate views are rendered: the deleted migrate-ts emitter used correlated subqueries; the unified emitter uses a single LEFT JOIN + GROUP BY withCOUNT(DISTINCT …). The two are data-equivalent for a single has-many join — verified by theprojection-aggregatequery scenarios (populated rows + the empty-programNULLcase) against real Postgres, and the committedcanonical/schema.postgres.sqlwas regenerated to match.