mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-10-18 04:47:04 +02:00
1.4.1a
- Minor changes
This commit is contained in:
parent
806b5038ca
commit
aefa6c6355
28 changed files with 1268 additions and 1351 deletions
|
|
@ -9,19 +9,21 @@ public class Migration(Database database)
|
|||
|
||||
public void ExecuteMigrations()
|
||||
{
|
||||
string migrationsDirectory = CS2_SimpleAdmin.Instance.ModuleDirectory + "/Database/Migrations";
|
||||
var migrationsDirectory = CS2_SimpleAdmin.Instance.ModuleDirectory + "/Database/Migrations";
|
||||
|
||||
var files = Directory.GetFiles(migrationsDirectory, "*.sql")
|
||||
.OrderBy(f => f);
|
||||
|
||||
using MySqlConnection connection = _database.GetConnection();
|
||||
using var connection = _database.GetConnection();
|
||||
|
||||
// Create sa_migrations table if not exists
|
||||
using var cmd = new MySqlCommand(@"
|
||||
CREATE TABLE IF NOT EXISTS `sa_migrations` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||
`version` VARCHAR(255) NOT NULL
|
||||
);", connection);
|
||||
using var cmd = new MySqlCommand("""
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `sa_migrations` (
|
||||
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||
`version` VARCHAR(255) NOT NULL
|
||||
);
|
||||
""", connection);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
|
@ -33,18 +35,16 @@ public class Migration(Database database)
|
|||
var version = Path.GetFileNameWithoutExtension(file);
|
||||
|
||||
// Check if the migration has already been applied
|
||||
if (string.Compare(version, lastAppliedVersion, StringComparison.OrdinalIgnoreCase) > 0)
|
||||
{
|
||||
var sqlScript = File.ReadAllText(file);
|
||||
if (string.Compare(version, lastAppliedVersion, StringComparison.OrdinalIgnoreCase) <= 0) continue;
|
||||
var sqlScript = File.ReadAllText(file);
|
||||
|
||||
using var cmdMigration = new MySqlCommand(sqlScript, connection);
|
||||
cmdMigration.ExecuteNonQuery();
|
||||
using var cmdMigration = new MySqlCommand(sqlScript, connection);
|
||||
cmdMigration.ExecuteNonQuery();
|
||||
|
||||
// Update the last applied migration version
|
||||
UpdateLastAppliedVersion(connection, version);
|
||||
// Update the last applied migration version
|
||||
UpdateLastAppliedVersion(connection, version);
|
||||
|
||||
CS2_SimpleAdmin._logger?.LogInformation($"Migration \"{version}\" successfully applied.");
|
||||
}
|
||||
CS2_SimpleAdmin._logger?.LogInformation($"Migration \"{version}\" successfully applied.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue