src/db/databaseconnection.cpp
QStringList DatabaseConnection::getUnappliedMigrations() {
  QDir migrationsDir(":/migrations");

  auto allMigrations = migrationsDir.entryList(QDir::Files, QDir::Name);
  QStringList appliedMigrations;
  QStringList migrationsToApply;

  QSqlQuery dbMigrations("SELECT migration_name FROM migrations");

  if (dbMigrations.exec()) {
    while (dbMigrations.next()) {
      appliedMigrations << dbMigrations.value("migration_name").toString();
    }
  }
  // compare the two list to find gaps
  for (const QString &possibleMigration : allMigrations) {
    if (possibleMigration.right(4) != ".sql") {
      continue;  // assume non-sql files aren't actual migrations.
    }
    auto foundIndex = appliedMigrations.indexOf(possibleMigration);
    if (foundIndex == -1) {
      migrationsToApply << possibleMigration;
    }
    else {
      appliedMigrations.removeAt(foundIndex);
    }
  }
  if (!appliedMigrations.empty()) {
    throw BadDatabaseStateError();
  }
  return migrationsToApply;
}
// getUnappliedMigrations retrieves a list of all of the migrations that have not been applied
// to the local database.
//
// Note: All sql files must end in ".sql" to be picked up
//
// Throws:
//   * BadDatabaseStateError if some migrations have been applied that are not known
//   * QSqlError if database queries fail
getUnappliedMigrations retrieves a list of all of the migrations that have not been applied
to the local database.

All sql files must end in ".sql" to be picked up

BadDatabaseStateError if some migrations have been applied that are not known
QSqlError if database queries fail
getUnappliedMigrations retrieves a list of all of the migrations that have not been applied to the local database . All sql files must end in " . sql " to be picked up BadDatabaseStateError if some migrations have been applied that are not known QSqlError if database queries fail
QStringList DatabaseConnection::getUnappliedMigrations() {
  QDir migrationsDir(":/migrations");
  auto allMigrations = migrationsDir.entryList(QDir::Files, QDir::Name);
  QStringList appliedMigrations;
  QStringList migrationsToApply;
  QSqlQuery dbMigrations("SELECT migration_name FROM migrations");
  if (dbMigrations.exec()) {
    while (dbMigrations.next()) {
      appliedMigrations << dbMigrations.value("migration_name").toString();
    }
  }
  for (const QString &possibleMigration : allMigrations) {
    if (possibleMigration.right(4) != ".sql") {
      continue;  
    }
    auto foundIndex = appliedMigrations.indexOf(possibleMigration);
    if (foundIndex == -1) {
      migrationsToApply << possibleMigration;
    }
    else {
      appliedMigrations.removeAt(foundIndex);
    }
  }
  if (!appliedMigrations.empty()) {
    throw BadDatabaseStateError();
  }
  return migrationsToApply;
}
QStringList DatabaseConnection :: getUnappliedMigrations ( ) { QDir migrationsDir ( " " ) ; auto allMigrations = migrationsDir . entryList ( QDir :: Files , QDir :: Name ) ; QStringList appliedMigrations ; QStringList migrationsToApply ; QSqlQuery dbMigrations ( " " ) ; if ( dbMigrations . exec ( ) ) { while ( dbMigrations . next ( ) ) { appliedMigrations << dbMigrations . value ( " " ) . toString ( ) ; } } for ( const QString & possibleMigration : allMigrations ) { if ( possibleMigration . right ( 4 ) != " " ) { continue ; } auto foundIndex = appliedMigrations . indexOf ( possibleMigration ) ; if ( foundIndex == -1 ) { migrationsToApply << possibleMigration ; } else { appliedMigrations . removeAt ( foundIndex ) ; } } if ( ! appliedMigrations . empty ( ) ) { throw BadDatabaseStateError ( ) ; } return migrationsToApply ; }
getUnappliedMigrations retrieves a list of all of the migrations that have not been applied
to the local database.
getUnappliedMigrations retrieves a list of all of the migrations that have not been applied to the local database .
// compare the two list to find gaps // assume non-sql files aren't actual migrations.