mirror of
https://github.com/mvschwarz/openrig.git
synced 2026-11-07 05:56:21 -10:00
Scaffold (T01-T04): - npm workspaces monorepo with @rigged/daemon and @rigged/ui - Shared tsconfig.base.json with strict mode - Hono server with /healthz endpoint, guarded index.ts (no side-effect on import) - SQLite connection factory (WAL, FK enforcement) and migration runner - Vite/React shell with dev proxy to daemon Schema (T05-T07, QA-approved HIGH risk): - 001_core_schema: rigs, nodes (id=opaque PK, logical_id=spec name), edges with same-rig trigger enforcing source/target/rig_id consistency - 002_bindings_sessions: bindings (optional, 1:1 with node) and sessions (status includes detached). No resume_token (Phase 2). - 003_events: append-only event log with seq AUTOINCREMENT for SSE replay. events.node_id is intentionally NOT an FK — events survive node deletion. 42 tests, all passing. tsc clean in both packages. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
23 lines
856 B
TypeScript
23 lines
856 B
TypeScript
import type { Migration } from "../migrate.js";
|
|
|
|
export const eventsSchema: Migration = {
|
|
name: "003_events.sql",
|
|
sql: `
|
|
CREATE TABLE events (
|
|
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
rig_id TEXT REFERENCES rigs(id) ON DELETE CASCADE,
|
|
-- INTENTIONALLY NOT AN FK to nodes(id).
|
|
-- Events are an append-only history log. They must survive node deletion
|
|
-- so the full timeline is preserved for replay and audit. An FK with
|
|
-- CASCADE would destroy history; SET NULL would lose the node reference.
|
|
node_id TEXT,
|
|
type TEXT NOT NULL,
|
|
payload TEXT NOT NULL,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
-- Primary query pattern: "all events for rig X after sequence N" (SSE replay)
|
|
CREATE INDEX idx_events_rig_seq ON events(rig_id, seq);
|
|
`,
|
|
};
|