mirror of https://github.com/AMT-Cheif/drift.git
Respect db options in runtime schema validation
This commit is contained in:
parent
77e7b99f2f
commit
9158c31240
|
@ -0,0 +1,24 @@
|
|||
@TestOn('vm')
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift_dev/api/migrations.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../generated/custom_tables.dart';
|
||||
import '../test_utils/test_utils.dart';
|
||||
|
||||
void main() {
|
||||
test('finds mismatch for datetime format', () async {
|
||||
final db = CustomTablesDb.connect(testInMemoryDatabase())
|
||||
..options = const DriftDatabaseOptions(storeDateTimeAsText: false);
|
||||
await db.customSelect('SELECT 1').get(); // Open db, setup tables
|
||||
|
||||
db.options = const DriftDatabaseOptions(storeDateTimeAsText: true);
|
||||
// Validation should fail now because datetimes are in the wrong format.
|
||||
|
||||
await expectLater(
|
||||
db.validateDatabaseSchema(),
|
||||
throwsA(isA<SchemaMismatch>().having(
|
||||
(e) => e.toString(), 'toString()', contains('TEXT and INTEGER'))),
|
||||
);
|
||||
});
|
||||
}
|
|
@ -29,4 +29,8 @@ class CustomTablesDb extends _$CustomTablesDb {
|
|||
|
||||
@override
|
||||
MigrationStrategy migration = MigrationStrategy();
|
||||
|
||||
@override
|
||||
DriftDatabaseOptions options =
|
||||
const DriftDatabaseOptions(storeDateTimeAsText: true);
|
||||
}
|
||||
|
|
|
@ -103,6 +103,9 @@ class _GenerateFromScratch extends GeneratedDatabase {
|
|||
_GenerateFromScratch(this.reference, QueryExecutor executor)
|
||||
: super(executor);
|
||||
|
||||
@override
|
||||
DriftDatabaseOptions get options => reference.options;
|
||||
|
||||
@override
|
||||
Iterable<TableInfo<Table, dynamic>> get allTables => reference.allTables;
|
||||
|
||||
|
|
Loading…
Reference in New Issue