Foundation: Drizzle setup + nuke 17 hand-rolled migrations #839
Labels
No labels
area:agents
area:dashboard
area:database
area:design
area:design-review
area:flows
area:infra
area:meta
area:security
area:sessions
area:webhook
area:workdir
security
type:bug
type:chore
type:meta
type:user-story
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/claude-hooks#839
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As a maintainer, I want Drizzle wired up alongside
bun:sqlitewith current schema captured as a single snapshot and all 17 hand-rolled migrations deleted, so that future schema changes are TS-driven and the migration ladder no longer carries dead one-shot data backfills.Decision context (chat 2026-05-04): repo is pure-dev, no prod, no preservation needed. Wipe-and-reseed is acceptable.
Acceptance criteria
Deps + config
drizzle-orm+drizzle-kitadded toapps/server/package.json.drizzle.config.tsatapps/server/, dialectsqlite, driverbun:sqlite, outputapps/server/src/infrastructure/database/drizzle/.apps/server/src/infrastructure/database/schema/created (one file per aggregate, populated incrementally by later stories).docs/database.md.Snapshot generation
drizzle-kit generateproduces0000_init.sqlcapturing every table currently inagents.db.tasks.db→0000_init_tasks.sql.sqlite3 .schemanormalized vs generated SQL) is empty before merge.Migration runner
ensureSchema(db)indb.tsrewritten: ifagentstable absent → run0000_init.sql; else assume up-to-date.drizzle-kit migratestyle — read SQL files fromdrizzle/, apply in order, track applied set in__drizzle_migrationstable.runXxxMigrationfiles inapps/server/src/infrastructure/database/migrations/deleted.runXxxMigrationimports + calls indb.tsremoved.task-store.ts::ensureSchemarewritten same pattern overtasks.db.Tooling
just db-generaterecipe — callsdrizzle-kit generate.just db-checkrecipe — fails CI ifschema/has drifted from generated SQL (no uncommitted migration)..forgejo/workflows/qa.ymlrunsjust db-check.Wipe + reseed
~/.local/state/claude-hooks/agents.dbandtasks.dbwiped manually before first boot.seedDefaultAgents+ensureDefaultForTypespopulate defaults; OAuth re-flows trigger on next webhook.just qagreen.Tests
*.test.tsininfrastructure/database/pass against newensureSchema.ensureSchemaon fresh DB produces schema bit-identical to liveagents.db .schema(after normalization).Out of scope
db.tsgod-file (begins in pilot story).db.tsitself (final cleanup story).References
docs/inheritance-contract.md— Drizzle migrations must respect add-only.apps/server/src/infrastructure/database/db.ts:64-600— currentensureSchema.holdsaggregate to Drizzle #840operator_sessions.tsto Drizzle #841dead_letter_prs+watched_reposaggregates #842flowsaggregate (flows + runs + audit + legacy_forge_calls) #843agentsaggregate (preserveonAgentDeletehook) #844service_config+label_catalog+agent_type_*aggregates #845task-store.tsto Drizzle (separatetasks.dbclient) #847sessions.tsto Drizzle #848