From a41911db3912101bfcf82ec65f0abfee7687a698 Mon Sep 17 00:00:00 2001 From: gabdevele Date: Tue, 2 Jun 2026 19:26:27 +0200 Subject: [PATCH] Fix startup migrations --- README.md | 18 ++++++++++++++++++ docs/MILESTONE_01.md | 2 +- main.cc | 12 +++++++++++- migrations/002_seed_admin_password.sql | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 migrations/002_seed_admin_password.sql diff --git a/README.md b/README.md index 77710ed..b1bff42 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,24 @@ cmake --build build The API listens on `http://localhost:5555`. MailHog listens on `http://localhost:8025`. +Local seeded admin: + +- email: `admin@visione.local` +- password: `ChangeMe123!` +- the account has `must_change_password = true` and is for local development only. + +If you already had a MySQL volume from the old scaffold, create the local +database/user once: + +```bash +docker compose exec -T mysql mysql -uroot -proot -e \ + "CREATE DATABASE IF NOT EXISTS visione CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; \ + CREATE USER IF NOT EXISTS 'visione'@'%' IDENTIFIED BY 'visione'; \ + ALTER USER 'visione'@'%' IDENTIFIED BY 'visione'; \ + GRANT ALL PRIVILEGES ON visione.* TO 'visione'@'%'; \ + FLUSH PRIVILEGES;" +``` + ```bash curl http://localhost:5555/api/v1/health curl http://localhost:5555/api/v1/ready diff --git a/docs/MILESTONE_01.md b/docs/MILESTONE_01.md index 5c0ed70..ea105f3 100644 --- a/docs/MILESTONE_01.md +++ b/docs/MILESTONE_01.md @@ -8,6 +8,7 @@ - Drogon backend structure for auth, reports, admin data and stats. - OTP email delivery through MailHog. - Focused regression tests for technical endpoints and core validation helpers. +- Local admin seed: `admin@visione.local` / `ChangeMe123!`, with forced password change flag. ## To do next - Harden password hashing with Argon2id or bcrypt before production. @@ -17,4 +18,3 @@ - Add file upload handling for real multipart photo upload. - Add notification channels, route optimization and open-data exports. - Dockerize the backend only for final delivery/deployment. - diff --git a/main.cc b/main.cc index 1667b8b..c68a423 100644 --- a/main.cc +++ b/main.cc @@ -21,7 +21,17 @@ int main(int argc, char *argv[]) .getCustomConfig() .get("migrations_path", "migrations") .asString(); - visione::repositories::MigrationRunner::run(migrationsPath); + drogon::app().getLoop()->runAfter(0.0, [migrationsPath]() { + try + { + visione::repositories::MigrationRunner::run(migrationsPath); + } + catch (const std::exception &error) + { + LOG_FATAL << "Migration failed: " << error.what(); + drogon::app().quit(); + } + }); drogon::app().run(); return 0; diff --git a/migrations/002_seed_admin_password.sql b/migrations/002_seed_admin_password.sql new file mode 100644 index 0000000..57164b4 --- /dev/null +++ b/migrations/002_seed_admin_password.sql @@ -0,0 +1,4 @@ +UPDATE users +SET password_hash = 'sha256$local-dev-salt$CD4FF6AC8C9685D08E55AF693970F15F9BFCD4C0DC9F4D3001D202C9DB00291F', + must_change_password = TRUE +WHERE email = 'admin@visione.local';