mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
1.4.1a
- Minor changes
This commit is contained in:
@@ -46,7 +46,7 @@ public class Database(string dbConnectionString)
|
||||
|
||||
public bool CheckDatabaseConnection()
|
||||
{
|
||||
using MySqlConnection connection = GetConnection();
|
||||
using var connection = GetConnection();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user