Context
This is a stacksjs/stacks framework fix, worked in ~/Code/stacks, not in this repo - but it blocks #4, so it lives on this board.
When loghq added models for its membership tables, buddy generate:migrations renumbered existing migration files, so loghq fell back to hand-written raw SQL migrations (database/migrations/0000000006-*.sql) with no model on top. ReportsHQ bans hand-written migrations outright, so the generator has to be fixed at the root: adding a new model must produce a stable, append-only migration - existing files and their ordering are immutable history.
Scope
- Reproduce: in a scratch Stacks app with several models already migrated, add a new model (with relations to existing tables) and run
buddy generate:migrations. Document exactly what gets renumbered/rewritten and why (the generator lives aroundstorage/framework/core/database// thegenerate:migrationsaction path). - Fix the generator so new models append new migration files; previously emitted files are never renamed, renumbered, or rewritten. Diffing against the live schema (the model-snapshot mechanism) must keep working for
migrate:fresh. - Cover pivot/membership-shaped models explicitly: email-keyed membership tables, tokened invite tables, composite uniques, partial indexes (loghq's
LogEntryuses partial indexes ontrace_id/request_id- the model attribute API must be able to express whatever #4 and #9 need; extenddefineModelif it cannot). - Tests in the framework repo for: append-only behavior, new-model-with-FK-to-existing-table, and re-running the generator twice being a no-op.
- Release the framework packages touched (
bun run release:patchper the owning package convention) and bump reportshq to the released versions.
Acceptance
- In reportshq, defining
ProjectMember/ProjectInvitemodels (#4) and runningbuddy generate:migrationstwice yields: new append-only migration files on the first run, no changes on the second, and untouched prior migrations - verified in a feature test or scripted check.
Blocks #4 and #9. Part of #1 (M1 Foundation). Ground rules: see #1.