Repository navigation
dialect/sql/schema: a directory of what the schema cannot state, with a history of its own - #7
Merged
Merged
Conversation
… a history of its own An exclusion constraint over a time range, or a foreign key that carries the tenant, is something a database holds and no ent schema can state. Written into the ent directory, it is what the next Plan proposes to drop. Written into a second directory applied with the same Apply, it shares schema_revisions, so the two directories are one history ordered by version: a file written on one branch before a plan made on another is refused as out of order once that plan has run. So Migrations can be a directory beside the ent one: - Revisions names the table its history is kept in, so the two are two histories (ExtraRevisionTable for the conventional one); - Atop applies it onto a database another directory already built, which atlas otherwise refuses as not clean; - Extra(dir) is both, with the ent directory's dialect; - Write puts a file written by hand into a directory and rehashes its sum, so OpenDir opens it without the Atlas CLI, and refuses a version that is already there; Rehash is for the file still being written; - Plan refuses a directory with no Tables (ErrNoSchema), which it would otherwise plan into a file that drops every table. Checked: TestExtra on SQLite -- a file older than the plan runs, the histories hold only their own, Atop is what lets it start, the next plan and Check leave it alone, there is nothing to plan; and the same on PostgreSQL 17 with a CHECK and an EXCLUDE (a throwaway program, since this module has no PostgreSQL driver). go test -race in dialect and in the integration module under Go 1.27.2; lint.sh on the three files. Reported as lesomnus/payday#33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk
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.
For lesomnus/payday#33: a supported place for DDL the ent schema cannot state.
The problem
An exclusion constraint over a time range, or a foreign key that carries the tenant, is something a database holds and no ent schema can state.
Planproposes to drop. That is by design: planning brings the directory into line with the schema.Apply, it sharesschema_revisions. The two directories then form one history ordered by version. A file written on one branch before a plan made on another is refused as out of order once that plan has run.What this adds
Migrations.Revisionsschema_revisions, as before.ExtraRevisionTableisschema_revisions_extra.Migrations.AtopMigrations.Extra(dir)DefaultExtraDirismigrations/extra. A directory reads its files and not its subdirectories, so nesting it is safe.Migrations.Write/Rehash/Versionatlas.sum, soOpenDiropens it without the Atlas CLI. A version already present is refused.Rehashis for a file still being written, never one that has been applied.PlanTables(ErrNoSchema). Otherwise it would plan a file that drops every table.Everything is additive. A
Migrationsthat sets none of the new fields behaves exactly as before.Tests
TestExtra(SQLite):Atopis what lets the first file run on a database the ent directory built;Checkboth leave its index alone;Planrefuses the extra directory and writes nothing;Writerefuses a version that is already there.On PostgreSQL 17 I ran the same flow with a throwaway program, since this module has no PostgreSQL driver. A hand-written file older than the plan added a
CHECKand abtree_gistEXCLUDE, and applied atop the ent schema. Each history held one row, nothing was pending,Checkpassed, and re-applying was a no-op.go test -racepasses indialectand in the integration module under Go 1.27.2, andlint.shis clean on the three files.🤖 Generated with Claude Code
https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk