Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions lib/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,35 @@ export interface Database {
indexed_at?: string;
};
};
ratings: {
Row: {
id: number;
storyline_id: number;
rater_address: string;
rating: number;
comment: string | null;
created_at: string;
updated_at: string;
};
Insert: {
id?: never;
storyline_id: number;
rater_address: string;
rating: number;
comment?: string | null;
created_at?: string;
updated_at?: string;
};
Update: {
id?: never;
storyline_id?: number;
rater_address?: string;
rating?: number;
comment?: string | null;
created_at?: string;
updated_at?: string;
};
};
};
};
}
Expand All @@ -174,3 +203,4 @@ export interface Database {
export type Storyline = Database["public"]["Tables"]["storylines"]["Row"];
export type Plot = Database["public"]["Tables"]["plots"]["Row"];
export type Donation = Database["public"]["Tables"]["donations"]["Row"];
export type Rating = Database["public"]["Tables"]["ratings"]["Row"];
19 changes: 19 additions & 0 deletions supabase/migrations/00005_ratings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Ratings table: one rating per user per storyline (upsert pattern)
-- Public read, no public write (writes via service role only)

CREATE TABLE ratings (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
storyline_id BIGINT NOT NULL REFERENCES storylines(storyline_id),
rater_address TEXT NOT NULL,
rating SMALLINT NOT NULL CHECK (rating >= 1 AND rating <= 5),
comment TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (storyline_id, rater_address)
);

CREATE INDEX idx_ratings_storyline ON ratings (storyline_id);

ALTER TABLE ratings ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Public read" ON ratings FOR SELECT USING (true);
Loading