From f53829b828411ff831d8220198f3e22233b13577 Mon Sep 17 00:00:00 2001 From: Yaojia Wang Date: Wed, 5 Nov 2025 00:09:28 +0100 Subject: [PATCH] fix(backend): Fix BUG-001 and BUG-003 - Auto-migration and BCrypt hashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed two P0 critical bugs blocking Docker development environment: BUG-001: Database migration not executed automatically - Added auto-migration code in Program.cs for Development environment - Migrates Identity, ProjectManagement, and IssueManagement modules - Prevents app startup if migration fails - Logs migration progress with clear success/error messages BUG-003: Seed data password hashes were placeholders - Generated real BCrypt hashes for Demo@123456 (workFactor=11) - Updated owner@demo.com and developer@demo.com passwords - Hash: $2a$11$VkcKFpWpEurtrkrEJzd1lOaDEa/KAXiOZzOUE94mfMFlqBNkANxSK - Users can now successfully log in with demo credentials Changes: - Program.cs: Added auto-migration logic (lines 204-247) - seed-data.sql: Replaced placeholder hashes with real BCrypt hashes Testing: - dotnet build: SUCCESS - dotnet test: 73/77 tests passing (4 skipped, 4 pre-existing SignalR failures) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- colaflow-api/src/ColaFlow.API/Program.cs | 49 ++++++++++++++++++++++++ scripts/seed-data.sql | 8 ++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/colaflow-api/src/ColaFlow.API/Program.cs b/colaflow-api/src/ColaFlow.API/Program.cs index a742d60..b4d4ffe 100644 --- a/colaflow-api/src/ColaFlow.API/Program.cs +++ b/colaflow-api/src/ColaFlow.API/Program.cs @@ -5,7 +5,10 @@ using ColaFlow.API.Middleware; using ColaFlow.API.Services; using ColaFlow.Modules.Identity.Application; using ColaFlow.Modules.Identity.Infrastructure; +using ColaFlow.Modules.Identity.Infrastructure.Persistence; +using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Scalar.AspNetCore; using System.Text; @@ -198,6 +201,52 @@ app.MapHealthChecks("/health"); app.MapHub("/hubs/project"); app.MapHub("/hubs/notification"); +// ============================================ +// Auto-migrate databases in development +// ============================================ +if (app.Environment.IsDevelopment()) +{ + app.Logger.LogInformation("Running in Development mode, applying database migrations..."); + + using (var scope = app.Services.CreateScope()) + { + var services = scope.ServiceProvider; + + try + { + // Migrate Identity module + var identityDbContext = services.GetRequiredService(); + await identityDbContext.Database.MigrateAsync(); + app.Logger.LogInformation("✅ Identity module migrations applied successfully"); + + // Migrate ProjectManagement module + var pmDbContext = services.GetRequiredService(); + await pmDbContext.Database.MigrateAsync(); + app.Logger.LogInformation("✅ ProjectManagement module migrations applied successfully"); + + // Migrate IssueManagement module (if exists) + try + { + var issueDbContext = services.GetRequiredService(); + await issueDbContext.Database.MigrateAsync(); + app.Logger.LogInformation("✅ IssueManagement module migrations applied successfully"); + } + catch (InvalidOperationException) + { + // IssueManagement module may not exist yet or not registered + app.Logger.LogWarning("⚠️ IssueManagement module not found, skipping migrations"); + } + + app.Logger.LogInformation("🎉 All database migrations completed successfully!"); + } + catch (Exception ex) + { + app.Logger.LogError(ex, "❌ Error occurred while applying migrations"); + throw; // Re-throw to prevent app from starting with broken database + } + } +} + app.Run(); // Make the implicit Program class public for integration tests diff --git a/scripts/seed-data.sql b/scripts/seed-data.sql index b1b42a8..8c5f5b9 100644 --- a/scripts/seed-data.sql +++ b/scripts/seed-data.sql @@ -70,8 +70,8 @@ BEGIN v_owner_user_id, v_tenant_id, 'owner@demo.com', - -- BCrypt hash for 'Demo@123456' - '$2a$11$ZqX5Z5Z5Z5Z5Z5Z5Z5Z5ZuZqX5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5', + -- BCrypt hash for 'Demo@123456' (workFactor=11) + '$2a$11$VkcKFpWpEurtrkrEJzd1lOaDEa/KAXiOZzOUE94mfMFlqBNkANxSK', 'John Owner', 'Active', 'local', @@ -94,8 +94,8 @@ BEGIN v_developer_user_id, v_tenant_id, 'developer@demo.com', - -- BCrypt hash for 'Demo@123456' - '$2a$11$ZqX5Z5Z5Z5Z5Z5Z5Z5Z5ZuZqX5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5Z5', + -- BCrypt hash for 'Demo@123456' (workFactor=11) + '$2a$11$VkcKFpWpEurtrkrEJzd1lOaDEa/KAXiOZzOUE94mfMFlqBNkANxSK', 'Jane Developer', 'Active', 'local',