canMigrateTo method
Whether this column can be altered in place to match other.
This method ignores the physical name of the column.
Implementation
bool canMigrateTo(ColumnDefinition other) {
// It's ok to change column default or nullability.
if (other.dartType != null &&
dartType != null &&
!_canMigrateType(dartType!, other.dartType!)) {
return false;
}
// Adding a serial (auto-increment) default requires creating a sequence,
// which can only be done by (re)creating the column with the serial
// pseudo-type. An in-place "ALTER COLUMN ... SET DEFAULT" would reference a
// sequence that is never created, so the column must be dropped and
// recreated instead.
if (other.columnDefault == db.defaultIntSerial &&
columnDefault != db.defaultIntSerial) {
return false;
}
// Vector dimension changes require dropping and recreating the column.
if (vectorDimension != other.vectorDimension) {
return false;
}
const jsonEquivalentTypes = {ColumnType.json, ColumnType.jsonb};
if (jsonEquivalentTypes.contains(columnType) &&
jsonEquivalentTypes.contains(other.columnType)) {
return true;
}
return other.columnType == columnType;
}