Report more errors when database is opened

This commit is contained in:
Simon Binder 2019-09-04 21:20:09 +02:00
parent 3c56e0ad6e
commit a17ad13542
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 17 additions and 5 deletions

View File

@ -240,14 +240,26 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
logStatements ??= false;
}
var _ensureOpenCalledCounter = 0; // todo remove
@override
Future<bool> ensureOpen() {
return _openingLock.synchronized(() async {
final alreadyOpen = await delegate.isOpen;
if (alreadyOpen) return true;
final call = ++_ensureOpenCalledCounter;
print('ensure_open_$call: called');
return _openingLock.synchronized(() async {
print('ensure_open_$call: lock aquired');
final alreadyOpen = await delegate.isOpen;
if (alreadyOpen) {
print('ensure_open_$call: was already open');
return true;
}
print('ensure_open_$call: opening database');
await delegate.open(databaseInfo);
print('ensure_open_$call: running migrations');
await _runMigrations();
print('ensure_open_$call: done with opening');
return true;
});
}

View File

@ -53,11 +53,11 @@ class _SqfliteDelegate extends DatabaseDelegate with _SqfliteExecutor {
@override
Future<void> open([GeneratedDatabase db]) async {
print('uses fix for the opening problem.');
assert(
!_debugIsOpening && !isOpen,
'Database opened multiple times, this should never happen. '
'Please report this at https://github.com/simolus3/moor/issues/135 to help fix this!');
'Please report this at https://github.com/simolus3/moor/issues/135 to help fix this!'
'Db already opened: $isOpen. Other operation in progress: $_debugIsOpening');
_debugIsOpening = true;
try {