Database & Migration Rules
Migration Discipline
- Forward-only SQL files: Never edit an already-committed migration file in
migrations/. Always add a new numbered migration file. - Additive first: When renaming or dropping a column, deploy code that tolerates both old and new schemas before executing destructive DDL.
- Parameterized queries only: Every SQL statement must bind user input via positional parameters (
?). Never interpolate search strings or identifiers directly into SQL text.
Indexing & Search
- Filter queries by
workspace_idandstatus = 'active'before joining revision or analytics tables. - Exclude automated bot traffic (
COALESCE(json_extract(metadata, '$.isBot'), 0) = 0) from human view counts and trending scores.