-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix column references in versioned schema code (#3259)
When a column is defined like this: ```dart DateTimeColumn get creationTime => dateTime() .check(creationTime.isBiggerThan(Constant(DateTime(2020)))) .withDefault(Constant(DateTime(2024, 1, 1)))(); ``` Our generated code relies on the fact that `creationTime` as a getter is in scope for the copied `check` code (it is because we're generating columns in table classes). With versioned schemas however, we have an optimization that tries to not re-generate column code if it hasn't changed between different schema versions. With this generation mode, columns are no longer in scope for check constraints. This fix relies on detecting columns in Dart code (so we see that the `creationTime` reference in `check` references a column) and then rewriting these expressions with a `CustomExpression` when generating code: ```dart i1.GeneratedColumn<DateTime> _column_18(String aliasedName) => i1.GeneratedColumn<DateTime>('birthday', aliasedName, true, check: () => i2.ComparableExpr((i0.VersionedTable.col<DateTime>('birthday'))) .isBiggerThan(i2.Constant(DateTime(1900))), type: i1.DriftSqlType.dateTime); ``` Closes #3219
- Loading branch information
Showing
30 changed files
with
1,372 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.