First time? Run this SQL in Supabase → SQL Editor:
CREATE TABLE envelopes (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
date date NOT NULL DEFAULT CURRENT_DATE,
label text, -- 'HTS', 'Fiore', or 'Noir'
budget numeric NOT NULL DEFAULT 0,
color text DEFAULT '#E8A020',
created_at timestamptz DEFAULT now()
);
ALTER TABLE envelopes ALTER COLUMN name DROP NOT NULL;
CREATE TABLE staff (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name text NOT NULL,
pin text NOT NULL,
created_at timestamptz DEFAULT now()
);
CREATE TABLE transactions (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
envelope_id uuid REFERENCES envelopes(id) ON DELETE CASCADE,
staff_id uuid REFERENCES staff(id) ON DELETE SET NULL,
type text CHECK (type IN ('add','deduct')),
amount numeric NOT NULL,
note text,
receipt_url text,
created_at timestamptz DEFAULT now()
);
ALTER TABLE envelopes ENABLE ROW LEVEL SECURITY;
ALTER TABLE staff ENABLE ROW LEVEL SECURITY;
ALTER TABLE transactions ENABLE ROW LEVEL SECURITY;
CREATE POLICY "All" ON envelopes FOR ALL USING (true) WITH CHECK (true);
CREATE POLICY "All" ON staff FOR ALL USING (true) WITH CHECK (true);
CREATE POLICY "All" ON transactions FOR ALL USING (true) WITH CHECK (true);
-- Budget edit audit log
CREATE TABLE envelope_edits (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
envelope_id uuid REFERENCES envelopes(id) ON DELETE CASCADE,
staff_id uuid REFERENCES staff(id) ON DELETE SET NULL,
old_budget numeric,
new_budget numeric,
created_at timestamptz DEFAULT now()
);
ALTER TABLE envelope_edits ENABLE ROW LEVEL SECURITY;
CREATE POLICY "All" ON envelope_edits FOR ALL USING (true) WITH CHECK (true);
-- Storage bucket for receipt photos (run in SQL Editor)
INSERT INTO storage.buckets (id, name, public)
VALUES ('receipts', 'receipts', true)
ON CONFLICT DO NOTHING;
CREATE POLICY "All storage" ON storage.objects
FOR ALL USING (bucket_id = 'receipts') WITH CHECK (bucket_id = 'receipts');