Repository navigation
dialect/sql/schema: Check leaves a foreign key or a check the schema does not declare alone - #6
Merged
Merged
Conversation
…does not declare alone Check says it asks whether the database is missing anything, and leaves alone what the app does not know about. It skipped only columns and indexes, which is ent's default for a migration -- so a foreign key or a check constraint a deployment added beside the schema came back as a drop and was read as drift, and a database stricter than the schema did not start. Those two are what a deployment adds that the ent schema cannot state: a foreign key that carries the tenant, a non-negative quantity. It now skips every kind of drop, spelled out, since WithSkipChanges replaces the default rather than adding to it. A foreign key the schema declares and the database lacks is still refused. Reported as lesomnus/payday#33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk
`setup-go` with `1.27` now installs Go 1.27.2, whose export data is version 5, and x/tools v0.49.0 reads no further than 4: entc/load fails to import "context" and the cmd tests fail on any change. v0.51.0 reads it. Bumped in every module that requires it, so that `go mod tidy` in the generate job leaves nothing behind. Checked under GOTOOLCHAIN=go1.27.2: the unit job's seven test steps with -race, and the generate job's three `go generate ./... && go mod tidy` with no diff. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk
This was referenced Oct 10, 2026
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.
Reported as lesomnus/payday#33 (the
Checkhalf of it).The bug
Check's comment says it asks whether the database is missing anything, and leaves alone what the app does not know about. It passed no skip option of its own, so it got ent's migration default, which skips onlyDropColumn | DropIndex.So a foreign key or a check constraint that a deployment added beside the schema came back from the diff as
DropForeignKey/DropCheck, and was reported as drift. A database stricter than the schema then refused to start:Those two are exactly what a deployment adds that the ent schema cannot state: a foreign key that carries the tenant (so a reference cannot cross tenants), or a non-negative quantity.
The fix
WithSkipChanges(DropSchema|DropTable|DropColumn|DropIndex|DropForeignKey|DropCheck): every kind of drop, spelled out.WithSkipChangesreplaces the default mask rather than adding to it (Atlas.init), so leaving out the column and index kinds would have started refusing those instead. Additions and modifications still count. A foreign key that the schema declares and the database lacks is still refused.Tests
Three new cases in
TestCheck, all on SQLite:go test -racepasses indialect/sql/schemaanddialect/sql/schema/integration, and.github/lint.shis clean on the two files.Second commit: x/tools for Go 1.27.2
CI now installs Go 1.27.2 for
1.27. Its export data is version 5, and x/tools v0.49.0 cannot read it, soentc/loadfails to importcontext. That breaks thecmdtests on every change, not only this one: master reproduces it locally underGOTOOLCHAIN=go1.27.2. The second commit bumps x/tools to v0.51.0 in all four modules that require it. Under Go 1.27.2 the unit job's seven test steps pass with-race, and the generate job'sgo generate ./... && go mod tidyleaves no diff.Not in this PR
Plandropping extra objects in the ent directory is by design. The missing supported place for DDL the schema cannot state is the other half of payday#33, and stays open there.🤖 Generated with Claude Code
https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk