mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Initial commit
This commit is contained in:
commit
4d53d83769
73 files changed
+37728
No files matched your search
@@ -0,0 +1,41 @@
|
||||
-- Create couple_packs table to track enabled packs per couple
|
||||
CREATE TABLE public.couple_packs (
|
||||
couple_id UUID NOT NULL REFERENCES public.couples(id) ON DELETE CASCADE,
|
||||
pack_id UUID NOT NULL REFERENCES public.question_packs(id) ON DELETE CASCADE,
|
||||
enabled BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
PRIMARY KEY (couple_id, pack_id)
|
||||
);
|
||||
|
||||
-- RLS Policies
|
||||
ALTER TABLE public.couple_packs ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Couples can view their own pack settings
|
||||
CREATE POLICY "Couples can view their own pack settings"
|
||||
ON public.couple_packs
|
||||
FOR SELECT
|
||||
USING (
|
||||
EXISTS (
|
||||
SELECT 1 FROM public.profiles
|
||||
WHERE profiles.id = auth.uid()
|
||||
AND profiles.couple_id = couple_packs.couple_id
|
||||
)
|
||||
);
|
||||
|
||||
-- Couples can insert/update their own pack settings
|
||||
CREATE POLICY "Couples can modify their own pack settings"
|
||||
ON public.couple_packs
|
||||
FOR ALL
|
||||
USING (
|
||||
EXISTS (
|
||||
SELECT 1 FROM public.profiles
|
||||
WHERE profiles.id = auth.uid()
|
||||
AND profiles.couple_id = couple_packs.couple_id
|
||||
)
|
||||
);
|
||||
|
||||
-- Function to handle default packs for new couples (Optional, but good UX)
|
||||
-- For now, we'll just assume if no record exists, it's not enabled?
|
||||
-- Or maybe better: if no record exists, it IS enabled if it's not premium?
|
||||
-- Actually, the user wants to "select which packs are active".
|
||||
-- Let's stick to explicit records.
|
||||
Reference in new issue
Block a user