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:
@@ -401,6 +401,30 @@ public static class Strings
|
||||
$"🔍 التحقق من SHA-256 v{version}: {percent}%"
|
||||
);
|
||||
|
||||
// ==================== DB MIGRATIONS ====================
|
||||
public static string StatusApplyingMigrations(string version) => T(
|
||||
$"Application des migrations base de données v{version}…",
|
||||
$"Applying database migrations for v{version}…",
|
||||
$"正在应用 v{version} 的数据库迁移…",
|
||||
$"กำลังปรับใช้การโยกย้ายฐานข้อมูล v{version}…",
|
||||
$"جارٍ تطبيق ترقيات قاعدة البيانات v{version}…"
|
||||
);
|
||||
public static string ProgressMigration(int done, int total, string filename) => T(
|
||||
$"🗄 Migration {done}/{total} : {filename}",
|
||||
$"🗄 Migration {done}/{total}: {filename}",
|
||||
$"🗄 迁移 {done}/{total}:{filename}",
|
||||
$"🗄 การโยกย้าย {done}/{total}: {filename}",
|
||||
$"🗄 الترقية {done}/{total}: {filename}"
|
||||
);
|
||||
public static string MsgBoxMigrationFailed => T("Migration DB échouée", "DB migration failed", "数据库迁移失败", "การโยกย้าย DB ล้มเหลว", "فشل ترقية قاعدة البيانات");
|
||||
public static string MsgMigrationFailed(string detail) => T(
|
||||
$"Une migration de la base de données a échoué :\n\n{detail}\n\nLa version a été extraite mais la base n'a PAS été modifiée (rollback automatique).\nVérifie que XAMPP est démarré et que les paramètres de connexion sont corrects (Settings → Base de données), puis clique « Rejouer les migrations » dans Settings.",
|
||||
$"A database migration failed:\n\n{detail}\n\nThe version was extracted but the database was NOT modified (automatic rollback).\nMake sure XAMPP is running and the connection settings are correct (Settings → Database), then click « Replay migrations » in Settings.",
|
||||
$"数据库迁移失败:\n\n{detail}\n\n版本已解压,但数据库未被修改(自动回滚)。\n请确保 XAMPP 正在运行并且连接设置正确(设置 → 数据库),然后点击设置中的「重新执行迁移」。",
|
||||
$"การโยกย้ายฐานข้อมูลล้มเหลว:\n\n{detail}\n\nเวอร์ชันถูกแตกแล้วแต่ฐานข้อมูลไม่ถูกแก้ไข (rollback อัตโนมัติ)\nตรวจสอบว่า XAMPP กำลังทำงานและการตั้งค่าการเชื่อมต่อถูกต้อง (ตั้งค่า → ฐานข้อมูล) จากนั้นคลิก « เรียกใช้การโยกย้ายอีกครั้ง » ในการตั้งค่า",
|
||||
$"فشلت ترقية قاعدة البيانات:\n\n{detail}\n\nتم استخراج النسخة لكن قاعدة البيانات لم تُعدَّل (rollback تلقائي).\nتأكد من تشغيل XAMPP وأن إعدادات الاتصال صحيحة (الإعدادات → قاعدة البيانات)، ثم انقر « إعادة تشغيل الترقيات » في الإعدادات."
|
||||
);
|
||||
|
||||
public static string StatusPreparingDownload(string version) => T(
|
||||
$"Préparation du téléchargement v{version}…",
|
||||
$"Preparing download for v{version}…",
|
||||
|
||||
Reference in New Issue
Block a user