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:
@@ -16,6 +16,7 @@ using PSLauncher.Core.Integrity;
|
||||
using PSLauncher.Core.Licensing;
|
||||
using PSLauncher.Core.Localization;
|
||||
using PSLauncher.Core.Manifests;
|
||||
using PSLauncher.Core.Migrations;
|
||||
using PSLauncher.Core.Process;
|
||||
using PSLauncher.Core.Updates;
|
||||
using PSLauncher.Models;
|
||||
@@ -162,6 +163,17 @@ public partial class App : Application
|
||||
|
||||
services.AddSingleton<IToastService, ToastService>();
|
||||
|
||||
// Migration DB MySQL : appliquée juste après extraction d'un build PROSERVE
|
||||
// si le ZIP contient un sous-répertoire _migrations/. La config DB et le
|
||||
// password (DPAPI) sont lus à la demande pour refléter les changements
|
||||
// utilisateur dans Settings sans recréer le service.
|
||||
services.AddSingleton<IDatabaseMigrationService>(sp =>
|
||||
new DatabaseMigrationService(
|
||||
configProvider: () => sp.GetRequiredService<LocalConfig>().Database,
|
||||
passwordProvider: () => DatabasePasswordProtector.Unprotect(
|
||||
sp.GetRequiredService<LocalConfig>().Database.EncryptedPassword),
|
||||
sp.GetRequiredService<ILogger<DatabaseMigrationService>>()));
|
||||
|
||||
services.AddTransient<SettingsViewModel>();
|
||||
services.AddSingleton<MainViewModel>();
|
||||
services.AddSingleton<MainWindow>();
|
||||
|
||||
Reference in New Issue
Block a user