-- Track whether a cc_expense_lines row's assignment came from an
-- auto-rule (vs a user save). Lets the UI paint auto-matched rows
-- orange (needs review) vs user-saved rows green (confirmed).
--
-- Lifecycle:
--   - On paste / re-apply: set TRUE when a cc_auto_rules match fills
--     in the assignment.
--   - On updateCcLine (any user save): set FALSE — the user is
--     confirming the row.
--   - On delete-and-reinsert: same as paste.
--
-- Default FALSE so older lines (pre-Phase-2) render green as before.

alter table public.cc_expense_lines
  add column if not exists auto_assigned boolean not null default false;

comment on column public.cc_expense_lines.auto_assigned is
  'TRUE if the row''s assignment was filled in by a cc_auto_rules match (at paste time or via Re-apply rules) and the user has not saved the row since. Any updateCcLine call flips it to FALSE.';
