Respect db options in runtime schema validation

This commit is contained in:
Simon Binder 2022-07-26 18:33:09 +02:00
parent 77e7b99f2f
commit 9158c31240
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 31 additions and 0 deletions

View File

@ -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'))),
);
});
}

View File

@ -29,4 +29,8 @@ class CustomTablesDb extends _$CustomTablesDb {
@override
MigrationStrategy migration = MigrationStrategy();
@override
DriftDatabaseOptions options =
const DriftDatabaseOptions(storeDateTimeAsText: true);
}

View File

@ -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;