Files
Sauci/apps/supabase/migrations/20260109100000_add_match_archives.sql
T
jjbrunton 494ed17fe2 Add streaks, scheduled releases, and notification settings
- Couple streaks with milestone notifications
- Scheduled pack releases with admin UI
- Notification preferences screen
- Refactored profile settings screens
- Partner activity notifications
2026-01-17 16:38:47 +00:00

40 lines
1.6 KiB
SQL

-- Create match_archives table for per-user match archiving
-- Similar pattern to message_deletions table
CREATE TABLE match_archives (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
match_id UUID NOT NULL REFERENCES matches(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
archived_at TIMESTAMPTZ DEFAULT now(),
UNIQUE(match_id, user_id)
);
-- Index for efficient lookup when filtering matches
CREATE INDEX idx_match_archives_user_match ON match_archives(user_id, match_id);
-- Enable RLS on match_archives
ALTER TABLE match_archives ENABLE ROW LEVEL SECURITY;
-- RLS Policies for match_archives
-- Users can view their own archives (needed for filtering)
CREATE POLICY "Users can view own archives"
ON match_archives FOR SELECT
USING (user_id = auth.uid());
-- Users can insert their own archives (for matches in their couples)
CREATE POLICY "Users can archive matches"
ON match_archives FOR INSERT
WITH CHECK (
user_id = auth.uid() AND
EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE m.id = match_archives.match_id
AND p.id = auth.uid()
)
);
-- Users can delete their own archives (for unarchiving)
CREATE POLICY "Users can unarchive matches"
ON match_archives FOR DELETE
USING (user_id = auth.uid());
-- Add to realtime for live updates
ALTER PUBLICATION supabase_realtime ADD TABLE match_archives;
-- Documentation
COMMENT ON TABLE match_archives IS 'Per-user match archives. Partner still sees the match. Delete record to unarchive.';