fix: don't report a boolean default TRUE/1 as a schema difference (#3738) - #3835
Conversation
There was a problem hiding this comment.
Thanks! I'm still not entirely sure why we'd sometimes generate it as a boolean literal or a expression, but I agree it makes sense to treat TRUE and 1 as equal for default constraints.
There's a second schema verifier implementation for an upcoming drift release in future/drift_sqlite/lib/src/schema_verifier/find_differences.dart, could you please apply the changes there as well?
| final actValue = _booleanOrNumericLiteral(act.expression); | ||
|
|
||
| if (refValue != null && actValue != null) { | ||
| if (refValue != actValue) return false; |
There was a problem hiding this comment.
These are rarely used, but constraints can also have a name attached to them and we should check that those are equal.
There was a problem hiding this comment.
Good catch. The TRUE/1 tolerance now only applies when both Default constraints have the same name; when the names differ it falls through to enforceEqual, which already asserts name equality in visitColumnConstraint, so a differently-named (or named-vs-unnamed) default is still reported. Added a regression test — with a boolean default under a different constraint name — covering equal default values under different CONSTRAINT names.
ba24d11 to
8829f4d
Compare
|
Thanks for the quick review! Pushed an update:
On why both forms show up: from what I've seen it's a cross-version rendering difference rather than one version emitting both — the reference schema (a serialized snapshot) renders the boolean default as |
|
Released in |
I'm a bit late, but a few weeks ago, I looked into this with |
A boolean column with a default value fails
SchemaVerifier.migrateAndValidate, even though the schema is semantically identical:Booleans are stored as integers in SQLite, so a
DEFAULT TRUEemitted by one schema snapshot and aDEFAULT 1emitted by another describe the same column. Butfind_differencescompared the default expressions textually and flagged a spurious difference, which breaks migration tests for any table with a boolean default (#3738).Fix
When comparing column constraints, a boolean default written as
TRUE/FALSEis now treated as equal to the same value written in its integer form1/0. Genuinely different defaults are still reported as differences.Tests
Added cases to
find_differences_test.dart: a boolean default written as an integer, the exact #3738 scenario (boolean default +IN (0, 1)check), and a guard that a genuinely different default is still detected as a change. Reverting the fix makes the first two fail; with the fix the wholefind_differencessuite passes.Closes #3738.