fix(auto-migrate): tenant_categories on-the-fly erstellung + migrate.js fail-fast
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 10m41s

This commit is contained in:
Pepe Ziberi
2026-05-21 13:40:34 +02:00
parent 3722a04091
commit 3606c9a2a4
3 changed files with 202 additions and 35 deletions

View File

@@ -212,7 +212,7 @@ async function migrate() {
console.log(' Privacy consent columns skipped:', e.message)
}
// ─── Step 12: Create tenant_symbols table ───
// ─── Step 12: Create tenant_symbols table (CRITICAL — fail-fast) ───
console.log(' [12] Creating tenant_symbols table...')
try {
await prisma.$executeRawUnsafe(`
@@ -226,7 +226,8 @@ async function migrate() {
`)
console.log(' tenant_symbols table created (or already exists)')
} catch (e) {
console.log(' tenant_symbols table skipped:', e.message)
console.error(' ❌ CRITICAL: tenant_symbols table creation failed:', e.message)
throw e
}
// ─── Step 13: Create symbol_templates table ───
@@ -251,7 +252,7 @@ async function migrate() {
console.log(' symbol_templates table skipped:', e.message)
}
// ─── Step 14: Create tenant_categories table ───
// ─── Step 14: Create tenant_categories table (CRITICAL — fail-fast) ───
console.log(' [14] Creating tenant_categories table...')
try {
await prisma.$executeRawUnsafe(`
@@ -268,7 +269,20 @@ async function migrate() {
`)
console.log(' tenant_categories table created (or already exists)')
} catch (e) {
console.log(' tenant_categories table skipped:', e.message)
console.error(' ❌ CRITICAL: tenant_categories table creation failed:', e.message)
throw e
}
// ─── Step 14b: Ensure tenant_categories has NOT NULL defaults ───
console.log(' [14b] Ensuring tenant_categories columns...')
const tcColumns = [
`ALTER TABLE tenant_categories ALTER COLUMN "isActive" SET DEFAULT true`,
`ALTER TABLE tenant_categories ALTER COLUMN "sortOrder" SET DEFAULT 0`,
`ALTER TABLE tenant_categories ALTER COLUMN "createdAt" SET DEFAULT CURRENT_TIMESTAMP`,
`ALTER TABLE tenant_categories ALTER COLUMN "updatedAt" SET DEFAULT CURRENT_TIMESTAMP`,
]
for (const sql of tcColumns) {
try { await prisma.$executeRawUnsafe(sql) } catch (e) { /* ignore */ }
}
// ─── Step 15: Extend tenant_symbols with Phase 1 columns ───