ensureOpen method

  1. @override
Future<bool> ensureOpen(
  1. QueryExecutorUser user
)
override

Opens the executor, if it has not yet been opened.

Implementation

@override
Future<bool> ensureOpen(QueryExecutorUser user) {
  return _openingLock.synchronized(() async {
    if (_closed) {
      return Future.error(StateError(
          "Can't re-open a database after closing it. Please create a new "
          'database connection and open that instead.'));
    }

    // If we have been unable to run migrations, the database is likely in an
    // inconsistent state and we should prevent subsequent operations on it.
    if (_migrationError case (var err, var trace)?) {
      Error.throwWithStackTrace(err, trace);
    }

    final alreadyOpen = await delegate.isOpen;
    if (alreadyOpen) {
      _ensureOpenCalled = true;
      return true;
    }

    await delegate.open(user);
    _ensureOpenCalled = true;

    try {
      await _runMigrations(user);
      return true;
    } catch (e, s) {
      _migrationError = (e, s);
      rethrow;
    }
  });
}