diff --git a/src/hooks.server.ts b/src/hooks.server.ts index d5436be..94dc2e3 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,8 +1,11 @@ import type { Handle } from '@sveltejs/kit'; -import { resolveTenant } from '$lib/server/tenant.js'; +import { resolveTenant, seedSystemTemplates } from '$lib/server/tenant.js'; import { validateSession, sessionCookieName } from '$lib/server/auth.js'; import { logger } from '$lib/server/logger.js'; +// One-time seed on startup +seedSystemTemplates().catch((e) => logger.error({ err: e }, 'Failed to seed system templates')); + export const handle: Handle = async ({ event, resolve }) => { const start = Date.now(); // 1. Resolve tenant from hostname diff --git a/src/lib/server/tenant.ts b/src/lib/server/tenant.ts index 011ae29..da04e60 100644 --- a/src/lib/server/tenant.ts +++ b/src/lib/server/tenant.ts @@ -103,3 +103,42 @@ function humanizeDomain(host: string): string { export function clearTenantCache() { tenantCache.clear(); } + +// ─── System board templates (tenantId = null) ─────────────── +const SYSTEM_TEMPLATES = [ + { + name: 'Kanban', + description: 'Classic kanban workflow with backlog and review stages', + template: { columns: [{ title: 'Backlog' }, { title: 'To Do' }, { title: 'In Progress' }, { title: 'Review' }, { title: 'Done' }] } + }, + { + name: 'Simple', + description: 'Minimal three-column board', + template: { columns: [{ title: 'To Do' }, { title: 'Doing' }, { title: 'Done' }] } + }, + { + name: 'Sprint', + description: 'Agile sprint workflow with testing phase', + template: { columns: [{ title: 'Sprint Backlog' }, { title: 'In Progress' }, { title: 'Testing' }, { title: 'Done' }] } + }, + { + name: 'Bug Tracking', + description: 'Issue lifecycle from report to resolution', + template: { columns: [{ title: 'Reported' }, { title: 'Triaging' }, { title: 'Fixing' }, { title: 'Verifying' }, { title: 'Closed' }] } + } +]; + +/** Seed system board templates if none exist. Call once at startup. */ +export async function seedSystemTemplates() { + const count = await prisma.boardTemplate.count({ where: { tenantId: null } }); + if (count > 0) return; + + await prisma.boardTemplate.createMany({ + data: SYSTEM_TEMPLATES.map((t) => ({ + tenantId: null, + name: t.name, + description: t.description, + template: t.template + })) + }); +}