DB migrations: bundled SQL applied automatically after install
Each PROSERVE ZIP can now ship a _migrations/ subfolder with versioned SQL scripts. The launcher applies them right after extraction, in the same install session as the binary copy, so the user never lands on a PROSERVE build whose schema doesn't match its code. Service (PSLauncher.Core/Migrations) - IDatabaseMigrationService + DatabaseMigrationService (MySqlConnector, BSD-licensed). Each .sql runs in a transaction; on failure the DB state is rolled back and the install completes (files only) but the user is warned to fix the connection / replay later. - Tracking table _launcher_migrations (filename, applied_at, checksum, duration_ms) — same model as Flyway / Doctrine. Already-applied scripts are skipped on subsequent installs. Modified scripts trigger a warning log without blocking. - Custom SQL splitter that respects strings/comments/backticks so a single .sql file can contain multiple statements separated by `;`. - DatabasePasswordProtector: DPAPI CurrentUser scope for the MySQL password in config.json (same protection as the license key). Config (PSLauncher.Models/LocalConfig.cs) - New DatabaseConfig section: Host=localhost, Port=3306, User=root, empty password, Database=proserve, AutoApplyMigrations=true. Defaults match a fresh XAMPP install. Override via Settings (next commit). Install pipeline (MainViewModel) - After ZipInstaller.InstallAsync and before declaring the install complete, if AutoApplyMigrations and a _migrations/ folder exists, run ApplyMigrationsAsync with progress reporting (per-file %, filename in footer). Failure shows MsgMigrationFailed dialog explaining XAMPP must be running and pointing to Settings → Database for connection params. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,45 @@ public sealed class LocalConfig
|
||||
public bool VerifyDownloadHash { get; set; } = true;
|
||||
|
||||
public LicenseConfig License { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Connexion à la base MySQL locale (XAMPP) utilisée par PROSERVE pour ses
|
||||
/// statistiques. Le launcher s'en sert pour appliquer les migrations bundled
|
||||
/// dans <c>_migrations/</c> au moment de l'install d'une nouvelle version.
|
||||
/// </summary>
|
||||
public DatabaseConfig Database { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Paramètres de connexion à la base MySQL locale. Les valeurs par défaut
|
||||
/// correspondent à un XAMPP standard fraîchement installé. Override possible
|
||||
/// via Settings → Base de données.
|
||||
/// </summary>
|
||||
public sealed class DatabaseConfig
|
||||
{
|
||||
public string Host { get; set; } = "localhost";
|
||||
public uint Port { get; set; } = 3306;
|
||||
public string User { get; set; } = "root";
|
||||
|
||||
/// <summary>
|
||||
/// Mot de passe MySQL stocké chiffré DPAPI (CurrentUser scope) en base64.
|
||||
/// Vide = pas de password (config XAMPP par défaut). NE PAS écrire en clair.
|
||||
/// </summary>
|
||||
public string? EncryptedPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Nom de la base de données qui contient les tables de PROSERVE.
|
||||
/// Default "proserve" — change si ton install crée la DB sous un autre nom.
|
||||
/// </summary>
|
||||
public string Database { get; set; } = "proserve";
|
||||
|
||||
/// <summary>
|
||||
/// Si true, le launcher applique automatiquement les migrations SQL bundled
|
||||
/// dans <c>_migrations/</c> de chaque ZIP, juste après l'extraction.
|
||||
/// Sécurité : on n'applique JAMAIS sans cette opt-in (au cas où certains users
|
||||
/// auraient une config DB exotique non gérée par le defaut).
|
||||
/// </summary>
|
||||
public bool AutoApplyMigrations { get; set; } = true;
|
||||
}
|
||||
|
||||
public sealed class LicenseConfig
|
||||
|
||||
Reference in New Issue
Block a user