-- Add an "Owner's Drawings" equity account (code 3200, role 'owner_drawings')
-- for every farm. Money the owner takes out of the farm for personal / non-farm
-- use is a DRAWING — a reduction of owner's equity — not an expense. Recording a
-- withdrawal debits this account and credits Cash / Bank / Mobile Money.
--
-- On the Balance Sheet the equity section sums each equity account as
-- (credit - debit), so a debit balance here shows as a reduction of total
-- equity automatically — no report change needed.
--
-- Idempotent — safe to re-run.

INSERT INTO chart_of_accounts (farm_id, code, name, type, role, map_key, is_system, sort_order)
SELECT f.id, '3200', 'Owner''s Drawings', 'equity', 'owner_drawings', NULL, 1, 8
FROM farms f
WHERE NOT EXISTS (
  SELECT 1 FROM chart_of_accounts c
  WHERE c.farm_id = f.id AND c.role = 'owner_drawings'
);
