# Database Instructions ## Scope - Applies to GORM models in `internal/models` and migration behavior in `internal/database/database.go`. ## Rules - Define explicit foreign keys for non-trivial relations (`foreignKey`, `references`) to avoid inference errors. - Avoid introducing `NOT NULL` constraints on existing populated tables without a backfill plan. - Keep `AutoMigrate` additive-first; prefer safe schema transitions over breaking changes. - Use deterministic ordering fields (`position`) for UI-driven entities (kanban sections/tasks). - Ensure seed data aligns with current schema and relation requirements. ## Migration Safety - For legacy data, introduce nullable columns first, backfill, then tighten constraints in a later step. - Never assume empty tables in shared dev environments.