import { Pool } from 'pg'; import { drizzle } from 'drizzle-orm/node-postgres'; import { agents, rooms, roomMembers } from '../src/db/schema.js'; import { v7 as uuidv7 } from 'uuid'; async function main() { const pool = new Pool({ host: process.env.POSTGRES_HOST || 'localhost', port: Number(process.env.POSTGRES_PORT) || 5432, user: process.env.POSTGRES_USER || 'agenthub', password: process.env.POSTGRES_PASSWORD || 'agenthub', database: process.env.POSTGRES_DB || 'agenthub', }); pool.on('connect', (client) => { client.query("SET TIME ZONE 'UTC'"); }); const db = drizzle(pool); console.log('[seed] Creating test agents...'); try { const aliceId = uuidv7(); const bobId = uuidv7(); const cliId = uuidv7(); await db.insert(agents).values([ { id: aliceId, name: 'alice', displayName: 'Alice (Admin)', role: 'admin', }, { id: bobId, name: 'bob', displayName: 'Bob (Agent)', role: 'agent', }, { id: cliId, name: 'cli', displayName: 'CLI Bot', role: 'agent', }, ]); console.log('[seed] ✓ Created 3 agents: alice (admin), bob (agent), cli (agent)'); console.log('[seed] Creating test rooms...'); const generalId = uuidv7(); const incidentsId = uuidv7(); await db.insert(rooms).values([ { id: generalId, slug: 'general', name: 'General Discussion', createdBy: aliceId, }, { id: incidentsId, slug: 'incidents', name: 'Incident Response', createdBy: aliceId, }, ]); console.log('[seed] ✓ Created 2 rooms: general, incidents'); console.log('[seed] Adding room memberships...'); await db.insert(roomMembers).values([ { roomId: generalId, agentId: aliceId }, { roomId: generalId, agentId: bobId }, { roomId: generalId, agentId: cliId }, { roomId: incidentsId, agentId: aliceId }, { roomId: incidentsId, agentId: bobId }, ]); console.log('[seed] ✓ Added room memberships'); console.log('[seed] ✓ Seed completed successfully.'); } catch (error) { console.error('[seed] ✗ Seed failed:', error); process.exit(1); } finally { await pool.end(); } } main();