toPgSql method

String toPgSql({
  1. required List<DatabaseMigrationVersion> installedModules,
  2. required List<DatabaseMigrationVersion> removedModules,
})

Implementation

String toPgSql({
  required List<DatabaseMigrationVersion> installedModules,
  required List<DatabaseMigrationVersion> removedModules,
}) {
  var out = '';

  // Start transaction
  out += 'BEGIN;\n';
  out += '\n';

  var foreignKeyActions = '';
  for (var action in actions) {
    out += action.toPgSql();
    foreignKeyActions += action.foreignRelationToSql();
  }

  // Append all foreign key operations at the end
  out += foreignKeyActions;

  if (installedModules.isNotEmpty) {
    out += '\n';
  }

  for (var module in installedModules) {
    out += _sqlStoreMigrationVersion(
      module: module.module,
      version: module.version,
    );
  }

  if (removedModules.isNotEmpty) {
    out += '\n';
    out += _sqlRemoveMigrationVersion(removedModules);
  }

  out += '\n';
  out += 'COMMIT;\n';

  return out;
}