Add system board templates seeded at startup
Four templates (Kanban, Simple, Sprint, Bug Tracking) with tenantId=null are auto-seeded on first startup if none exist. Available to all tenants in the board creation dropdown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+4
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user