diff --git a/moor/lib/src/runtime/executor/helpers/engines.dart b/moor/lib/src/runtime/executor/helpers/engines.dart index 105e3171..bfa56029 100644 --- a/moor/lib/src/runtime/executor/helpers/engines.dart +++ b/moor/lib/src/runtime/executor/helpers/engines.dart @@ -240,14 +240,26 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate { logStatements ??= false; } + var _ensureOpenCalledCounter = 0; // todo remove + @override Future 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; }); } diff --git a/moor_flutter/lib/moor_flutter.dart b/moor_flutter/lib/moor_flutter.dart index 0965521e..8271e22f 100644 --- a/moor_flutter/lib/moor_flutter.dart +++ b/moor_flutter/lib/moor_flutter.dart @@ -53,11 +53,11 @@ class _SqfliteDelegate extends DatabaseDelegate with _SqfliteExecutor { @override Future 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 {