17 lines
630 B
SQL
17 lines
630 B
SQL
-- Streak Events Tabelle für Timeline/Verlauf
|
|
CREATE TABLE IF NOT EXISTS rebreak.streak_events (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
|
|
type TEXT NOT NULL, -- 'started' | 'reset' | 'milestone' | 'relapse'
|
|
meta JSONB,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX idx_streak_events_user ON rebreak.streak_events(user_id, created_at DESC);
|
|
|
|
-- RLS
|
|
ALTER TABLE rebreak.streak_events ENABLE ROW LEVEL SECURITY;
|
|
CREATE POLICY "streak_events: own all"
|
|
ON rebreak.streak_events FOR ALL
|
|
USING (auth.uid() = user_id);
|