mirror of https://github.com/AMT-Cheif/drift.git
More lenient `strict` column type handling
This commit is contained in:
parent
7d56497c18
commit
aa38ab42f2
|
@ -1,3 +1,7 @@
|
|||
## 0.19.2
|
||||
|
||||
- Improve handling of drift-specific column types in `STRICT` tables.
|
||||
|
||||
## 0.19.1
|
||||
|
||||
- Make the result of `group_concat` nullable.
|
||||
|
|
|
@ -135,6 +135,11 @@ 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);
|
||||
|
@ -161,24 +166,20 @@ class SchemaFromCreateTable {
|
|||
return const ResolvedType(type: BasicType.int);
|
||||
}
|
||||
}
|
||||
|
||||
return const ResolvedType(type: BasicType.real);
|
||||
}
|
||||
|
||||
bool isValidTypeNameForStrictTable(String typeName) {
|
||||
// See https://www.sqlite.org/draft/stricttables.html
|
||||
const allowed = {'INT', 'INTEGER', 'REAL', 'TEXT', 'BLOB', 'ANY'};
|
||||
const alsoAllowedInMoor = {'BOOL', 'DATE'};
|
||||
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;
|
||||
} else {
|
||||
// See https://www.sqlite.org/draft/stricttables.html
|
||||
const allowed = {'INT', 'INTEGER', 'REAL', 'TEXT', 'BLOB', 'ANY'};
|
||||
final upper = typeName.toUpperCase();
|
||||
|
||||
final upper = typeName.toUpperCase();
|
||||
|
||||
if (allowed.contains(upper) ||
|
||||
(moorExtensions &&
|
||||
(alsoAllowedInMoor.contains(upper) || upper.contains('ENUM')))) {
|
||||
return true;
|
||||
return allowed.contains(upper);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Looks up the correct column affinity for a declared type name with the
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: sqlparser
|
||||
description: Parses sqlite statements and performs static analysis on them
|
||||
version: 0.19.1
|
||||
version: 0.19.2-dev
|
||||
homepage: https://github.com/simolus3/moor/tree/develop/sqlparser
|
||||
#homepage: https://moor.simonbinder.eu/
|
||||
issue_tracker: https://github.com/simolus3/moor/issues
|
||||
|
|
|
@ -6,6 +6,8 @@ import 'utils.dart';
|
|||
void main() {
|
||||
final oldEngine = SqlEngine(EngineOptions(version: SqliteVersion.v3_35));
|
||||
final engine = SqlEngine(EngineOptions(version: SqliteVersion.v3_37));
|
||||
final engineInDriftMode = SqlEngine(
|
||||
EngineOptions(version: SqliteVersion.v3_37, useMoorExtensions: true));
|
||||
|
||||
group('using STRICT', () {
|
||||
test('with an old sqlite3 version', () {
|
||||
|
@ -34,6 +36,13 @@ 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;')
|
||||
.expectNoError();
|
||||
});
|
||||
});
|
||||
|
||||
test('using WITHOUT ROWID and then not declaring a primary key', () {
|
||||
|
|
Loading…
Reference in New Issue