fix: wire database and repositories into server startup for tRPC context

The server never created a database or instantiated repositories, so all
tRPC procedures requiring initiativeRepository (and other repos) threw
"Initiative repository not available" on every request.

- Create ensureSchema() for shared database table initialization
- Extend TrpcAdapterOptions to accept all repository/manager dependencies
- Add ServerContextDeps to CoordinationServer for dependency injection
- Wire database, schema, and repositories in CLI startServer()
- Refactor test-helpers to use shared ensureSchema()
This commit is contained in:
Lukas May
2026-02-04 21:18:30 +01:00
parent 078e1dde30
commit cbf0ed28cb
8 changed files with 327 additions and 105 deletions

View File

@@ -13,6 +13,15 @@ import { ProcessManager, ProcessRegistry } from '../process/index.js';
import { LogManager } from '../logging/index.js';
import { createEventBus } from '../events/index.js';
import { createDefaultTrpcClient } from './trpc-client.js';
import {
createDatabase,
ensureSchema,
DrizzleInitiativeRepository,
DrizzlePhaseRepository,
DrizzlePlanRepository,
DrizzleTaskRepository,
DrizzleMessageRepository,
} from '../db/index.js';
/** Environment variable for custom port */
const CW_PORT_ENV = 'CW_PORT';
@@ -32,12 +41,30 @@ async function startServer(port?: number): Promise<void> {
const processManager = new ProcessManager(registry, eventBus);
const logManager = new LogManager();
// Create database and ensure schema
const db = createDatabase();
ensureSchema(db);
// Create repositories
const initiativeRepository = new DrizzleInitiativeRepository(db);
const phaseRepository = new DrizzlePhaseRepository(db);
const planRepository = new DrizzlePlanRepository(db);
const taskRepository = new DrizzleTaskRepository(db);
const messageRepository = new DrizzleMessageRepository(db);
// Create and start server
const server = new CoordinationServer(
{ port: serverPort },
processManager,
logManager,
eventBus
eventBus,
{
initiativeRepository,
phaseRepository,
planRepository,
taskRepository,
messageRepository,
}
);
try {