Accept any type name for strict drift tables

This commit is contained in:
Simon Binder 2022-01-25 13:21:40 +01:00
parent aa38ab42f2
commit 130517473b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 8 additions and 10 deletions

View File

@ -135,11 +135,6 @@ class SchemaFromCreateTable {
return const ResolvedType(type: BasicType.blob);
}
return _handleColumnTypeWithoutDefault(typeName) ??
const ResolvedType(type: BasicType.real);
}
ResolvedType? _handleColumnTypeWithoutDefault(String typeName) {
final upper = typeName.toUpperCase();
if (upper.contains('INT')) {
return const ResolvedType(type: BasicType.int);
@ -166,15 +161,18 @@ class SchemaFromCreateTable {
return const ResolvedType(type: BasicType.int);
}
}
return const ResolvedType(type: BasicType.real);
}
bool isValidTypeNameForStrictTable(String typeName) {
if (moorExtensions) {
// Anything accepted by drift_dev goes, the generated table will have
// a correct column type for that either way (it's transformed).
return _handleColumnTypeWithoutDefault(typeName) != null;
// Drift_dev will use resolveColumnType to analyze the actual type of the
// column, and the generated code will always use a valid type name for
// that type. So, anything goes!
return true;
} else {
// See https://www.sqlite.org/draft/stricttables.html
// See https://www.sqlite.org/stricttables.html
const allowed = {'INT', 'INTEGER', 'REAL', 'TEXT', 'BLOB', 'ANY'};
final upper = typeName.toUpperCase();

View File

@ -40,7 +40,7 @@ void main() {
test('with a type that is only valid in drift mode', () {
// https://github.com/simolus3/moor/discussions/1651
engineInDriftMode
.analyze('CREATE TABLE a (c IS_DATETIME) STRICT;')
.analyze('CREATE TABLE a (c IS_DATETIME, b DECIMAL, c REAL) STRICT;')
.expectNoError();
});
});