restoreSnapshot static method

Future<void> restoreSnapshot(
  1. Client cloudApiClient, {
  2. required CommandLogger logger,
  3. required String projectId,
  4. required String snapshotId,
  5. bool skipConfirmation = false,
})

Restores the project's live database to a snapshot.

Implementation

static Future<void> restoreSnapshot(
  final Client cloudApiClient, {
  required final CommandLogger logger,
  required final String projectId,
  required final String snapshotId,
  final bool skipConfirmation = false,
}) async {
  if (!skipConfirmation) {
    final confirmed = await logger.confirm('''
WARNING: Restores the database for project "$projectId" to snapshot "$snapshotId".
The live database is replaced with the data from the snapshot.
This action cannot be undone.

Do you want to proceed?''', defaultValue: false);
    if (!confirmed) {
      throw UserAbortException();
    }
  }

  try {
    await logger.progress(
      'Restoring database for project "$projectId"',
      () async {
        await cloudApiClient.database.restoreFromSnapshot(
          cloudCapsuleId: projectId,
          snapshotId: snapshotId,
        );
        return true;
      },
      successMessage: 'Database restored.',
      newParagraph: true,
    );
  } on Exception catch (e, s) {
    throw FailureException.nested(e, s, 'Failed to restore snapshot');
  }
}