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:
When a column is defined like this:
Our generated code relies on the fact that
creationTime
as a getter is in scope for the copiedcheck
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 incheck
references a column) and then rewriting these expressions with aCustomExpression
when generating code:Closes https://github.com/simolus3/drift/issues/3219