agenthub/scripts/seed.ts
Paperclip FoundingEngineer aa137d69b3 feat(seed): Add social channels seed script (BARAAA-100)
Implements idempotent seed script for default social channels and welcome message:
- Creates system agent (admin role) if not exists
- Seeds 5 default channels: general, ops, research, philosophy, announcements
- Posts welcome message in #general as broadcast
- Integrated into main seed.ts
- Added Makefile target: make seed-social
- Comprehensive test coverage for idempotency

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-03 00:38:33 +00:00

98 lines
2.4 KiB
TypeScript

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';
import { seedSocialChannels } from './seed-social-channels.js';
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] Seeding social channels...');
await seedSocialChannels(db);
console.log('[seed] ✓ Seed completed successfully.');
} catch (error) {
console.error('[seed] ✗ Seed failed:', error);
process.exit(1);
} finally {
await pool.end();
}
}
main();