fix(backend): Fix foreign key constraint error in tenant registration
Root Cause: - Schema mismatch between user_tenant_roles table (identity schema) and users/tenants tables (default/public schema) - PostgreSQL FK constraints couldn't find referenced tables due to schema mismatch - Error: "violates foreign key constraint FK_user_tenant_roles_tenants_tenant_id" Solution: 1. Moved users and tenants tables to identity schema 2. Created migration MoveTablesToIdentitySchemaAndAddIndexes 3. All Identity module tables now in consistent identity schema 4. Added performance index for users.email lookups Changes: - Updated TenantConfiguration.cs to use identity schema - Updated UserConfiguration.cs to use identity schema - Created migration to move tables to identity schema - Removed old AddPerformanceIndexes migration (referenced wrong schema) - Created new AddPerformanceIndexes migration - Added test script test-tenant-registration.ps1 Test Results: - Tenant registration now works successfully - User, Tenant, and UserTenantRole all insert correctly - FK constraints validate properly - Access token and refresh token generated successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
35
colaflow-api/test-tenant-registration.ps1
Normal file
35
colaflow-api/test-tenant-registration.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
# Test Tenant Registration API
|
||||
|
||||
$body = @{
|
||||
tenantName = "Test Corp"
|
||||
tenantSlug = "test-corp-$(Get-Random)"
|
||||
subscriptionPlan = "Professional"
|
||||
adminEmail = "admin@testcorp.com"
|
||||
adminPassword = "Admin@1234"
|
||||
adminFullName = "Test Admin"
|
||||
} | ConvertTo-Json
|
||||
|
||||
Write-Host "Testing Tenant Registration API..." -ForegroundColor Cyan
|
||||
Write-Host "Request Body:" -ForegroundColor Yellow
|
||||
Write-Host $body
|
||||
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri "http://localhost:5167/api/tenants/register" `
|
||||
-Method Post `
|
||||
-ContentType "application/json" `
|
||||
-Body $body
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "SUCCESS! Registration completed successfully!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Response:" -ForegroundColor Yellow
|
||||
Write-Host ($response | ConvertTo-Json -Depth 10)
|
||||
Write-Host ""
|
||||
Write-Host "Access Token:" -ForegroundColor Cyan
|
||||
Write-Host $response.accessToken
|
||||
} catch {
|
||||
Write-Host ""
|
||||
Write-Host "FAILED! Registration failed!" -ForegroundColor Red
|
||||
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
|
||||
Write-Host "Details: $($_.ErrorDetails.Message)" -ForegroundColor Red
|
||||
}
|
||||
Reference in New Issue
Block a user