src/db/databaseconnection.cpp
void DatabaseConnection::migrateDB() {
  std::cout << "Checking database state" << std::endl;
  auto migrationsToApply = DatabaseConnection::getUnappliedMigrations();

  for (const QString &newMigration : migrationsToApply) {
    QFile migrationFile(":/migrations/" + newMigration);
    auto ok = migrationFile.open(QFile::ReadOnly);
    if (!ok) {
      throw FileError::mkError("Error reading migration file",
                               migrationFile.fileName().toStdString(), migrationFile.error());
    }
    auto content = QString(migrationFile.readAll());
    migrationFile.close();

    std::cout << "Applying Migration: " << newMigration.toStdString() << std::endl;
    auto upScript = extractMigrateUpContent(content);
    executeQuery(&db, upScript);
    executeQuery(&db,
                 "INSERT INTO migrations (migration_name, applied_at) VALUES (?, datetime('now'))",
                 {newMigration});
  }
  std::cout << "All migrations applied" << std::endl;
}
// migrateDB checks the migration status and then performs the full migration for any
// lacking update.
//
// Throws exceptions/FileError if a migration file cannot be found.
migrateDB checks the migration status and then performs the full migration for any
lacking update.

Throws exceptions/FileError if a migration file cannot be found.
migrateDB checks the migration status and then performs the full migration for any lacking update . Throws exceptions / FileError if a migration file cannot be found .
void DatabaseConnection::migrateDB() {
  std::cout << "Checking database state" << std::endl;
  auto migrationsToApply = DatabaseConnection::getUnappliedMigrations();
  for (const QString &newMigration : migrationsToApply) {
    QFile migrationFile(":/migrations/" + newMigration);
    auto ok = migrationFile.open(QFile::ReadOnly);
    if (!ok) {
      throw FileError::mkError("Error reading migration file",
                               migrationFile.fileName().toStdString(), migrationFile.error());
    }
    auto content = QString(migrationFile.readAll());
    migrationFile.close();
    std::cout << "Applying Migration: " << newMigration.toStdString() << std::endl;
    auto upScript = extractMigrateUpContent(content);
    executeQuery(&db, upScript);
    executeQuery(&db,
                 "INSERT INTO migrations (migration_name, applied_at) VALUES (?, datetime('now'))",
                 {newMigration});
  }
  std::cout << "All migrations applied" << std::endl;
}
void DatabaseConnection :: migrateDB ( ) { std :: cout << " " << std :: endl ; auto migrationsToApply = DatabaseConnection :: getUnappliedMigrations ( ) ; for ( const QString & newMigration : migrationsToApply ) { QFile migrationFile ( " " + newMigration ) ; auto ok = migrationFile . open ( QFile :: ReadOnly ) ; if ( ! ok ) { throw FileError :: mkError ( " " , migrationFile . fileName ( ) . toStdString ( ) , migrationFile . error ( ) ) ; } auto content = QString ( migrationFile . readAll ( ) ) ; migrationFile . close ( ) ; std :: cout << " " << newMigration . toStdString ( ) << std :: endl ; auto upScript = extractMigrateUpContent ( content ) ; executeQuery ( & db , upScript ) ; executeQuery ( & db , " " , { newMigration } ) ; } std :: cout << " " << std :: endl ; }
migrateDB checks the migration status and then performs the full migration for any
lacking update.
migrateDB checks the migration status and then performs the full migration for any lacking update .