Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ ORDER BY total_translations DESC;

-- Fixed view: previous LEFT JOIN book_isbns ON true produced a cartesian product.
-- Now we join through book_translations on language_code, then isbns, then clicks.
CREATE OR REPLACE VIEW v_affiliate_performance AS
CREATE OR REPLACE VIEW v_affiliate_performance WITH (security_invoker = true) AS
SELECT
ar.language_code,
ar.retailer_name,
Expand Down Expand Up @@ -744,6 +744,7 @@ ALTER TABLE annotations ENABLE ROW LEVEL SECURITY;
ALTER TABLE reading_sessions ENABLE ROW LEVEL SECURITY;
ALTER TABLE premium_subscriptions ENABLE ROW LEVEL SECURITY;
ALTER TABLE donations ENABLE ROW LEVEL SECURITY;
ALTER TABLE affiliate_retailers ENABLE ROW LEVEL SECURITY;

-- Helper that returns NULL outside Supabase (so the schema still loads in plain docker)
CREATE OR REPLACE FUNCTION current_auth_uid() RETURNS UUID AS $$
Expand Down Expand Up @@ -813,6 +814,11 @@ CREATE POLICY donations_self ON donations FOR SELECT
USING (user_id = current_auth_uid() OR anonymous = FALSE);
-- Writes via service_role only.

-- Affiliate retailer rows include partner tags, commission rates, inactive
-- routing config, and operator notes. Keep direct anon/authenticated access
-- closed; affiliate URL generation and revenue dashboards should run through
-- trusted server/service-role code.

-- ============================================================
-- SAMPLE DATA (dev only)
-- ============================================================
Expand Down