-- Add a backlink from task_task to task_tasktemplate so that tasks created from -- a template (e.g. onboarding suggestions or the template catalog) can be -- reported on and filtered. Nullable — user-created custom tasks remain unset. ALTER TABLE task_task ADD COLUMN IF NOT EXISTS task_template_id BIGINT NULL; CREATE INDEX IF NOT EXISTS idx_task_task_task_template_id ON task_task (task_template_id); -- Deferred FK — not enforced at the DB level because task_tasktemplate rows -- may be renamed/retired; application code is the source of truth for the -- relationship and already tolerates nil.