diff --git a/backend/api/src/star-profile.ts b/backend/api/src/star-profile.ts index fa1e72a6..facffe41 100644 --- a/backend/api/src/star-profile.ts +++ b/backend/api/src/star-profile.ts @@ -14,7 +14,7 @@ export const starProfile: APIHandler<'star-profile'> = async (props, auth) => { if (remove) { const { error } = await tryCatch( pg.none( - 'delete from love_stars where creator_id = $1 and target_id = $2', + 'delete from profile_stars where creator_id = $1 and target_id = $2', [creatorId, targetUserId] ) ) @@ -27,8 +27,8 @@ export const starProfile: APIHandler<'star-profile'> = async (props, auth) => { // Check if star already exists const { data: existing } = await tryCatch( - pg.oneOrNone>( - 'select * from love_stars where creator_id = $1 and target_id = $2', + pg.oneOrNone>( + 'select * from profile_stars where creator_id = $1 and target_id = $2', [creatorId, targetUserId] ) ) @@ -40,7 +40,7 @@ export const starProfile: APIHandler<'star-profile'> = async (props, auth) => { // Insert the new star const { error } = await tryCatch( - insert(pg, 'love_stars', { creator_id: creatorId, target_id: targetUserId }) + insert(pg, 'profile_stars', { creator_id: creatorId, target_id: targetUserId }) ) if (error) { diff --git a/backend/supabase/love_stars.sql b/backend/supabase/love_stars.sql deleted file mode 100644 index ecc93c4f..00000000 --- a/backend/supabase/love_stars.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE IF NOT EXISTS love_stars ( - created_time TIMESTAMPTZ DEFAULT now() NOT NULL, - creator_id TEXT NOT NULL, - star_id TEXT DEFAULT random_alphanumeric(12) NOT NULL, - target_id TEXT NOT NULL, - CONSTRAINT love_stars_pkey PRIMARY KEY (creator_id, star_id) -); - --- Row Level Security -ALTER TABLE love_stars ENABLE ROW LEVEL SECURITY; - --- Policies -DROP POLICY IF EXISTS "public read" ON love_stars; -CREATE POLICY "public read" ON love_stars -FOR SELECT USING (true); - --- Indexes --- The primary key already creates a unique index on (creator_id, star_id), so no need to recreate it. - -DROP INDEX IF EXISTS love_stars_target_id_idx; -CREATE INDEX love_stars_target_id_idx ON public.love_stars USING btree (target_id); diff --git a/backend/supabase/migration.sql b/backend/supabase/migration.sql index e8b0c4c2..b380977f 100644 --- a/backend/supabase/migration.sql +++ b/backend/supabase/migration.sql @@ -14,7 +14,7 @@ BEGIN; \i backend/supabase/profile_likes.sql \i backend/supabase/compatibility_prompts.sql \i backend/supabase/profile_ships.sql -\i backend/supabase/love_stars.sql +\i backend/supabase/profile_stars.sql \i backend/supabase/love_waitlist.sql \i backend/supabase/user_events.sql \i backend/supabase/user_notifications.sql diff --git a/backend/supabase/profile_stars.sql b/backend/supabase/profile_stars.sql new file mode 100644 index 00000000..a1d89000 --- /dev/null +++ b/backend/supabase/profile_stars.sql @@ -0,0 +1,21 @@ +CREATE TABLE IF NOT EXISTS profile_stars ( + created_time TIMESTAMPTZ DEFAULT now() NOT NULL, + creator_id TEXT NOT NULL, + star_id TEXT DEFAULT random_alphanumeric(12) NOT NULL, + target_id TEXT NOT NULL, + CONSTRAINT profile_stars_pkey PRIMARY KEY (creator_id, star_id) +); + +-- Row Level Security +ALTER TABLE profile_stars ENABLE ROW LEVEL SECURITY; + +-- Policies +DROP POLICY IF EXISTS "public read" ON profile_stars; +CREATE POLICY "public read" ON profile_stars +FOR SELECT USING (true); + +-- Indexes +-- The primary key already creates a unique index on (creator_id, star_id), so no need to recreate it. + +DROP INDEX IF EXISTS profile_stars_target_id_idx; +CREATE INDEX profile_stars_target_id_idx ON public.profile_stars USING btree (target_id); diff --git a/common/src/supabase/schema.ts b/common/src/supabase/schema.ts index af717714..0517866d 100644 --- a/common/src/supabase/schema.ts +++ b/common/src/supabase/schema.ts @@ -211,7 +211,7 @@ export type Database = { } Relationships: [] } - love_stars: { + profile_stars: { Row: { created_time: string creator_id: string diff --git a/web/lib/supabase/stars.ts b/web/lib/supabase/stars.ts index 7b56f12b..ef645cd7 100644 --- a/web/lib/supabase/stars.ts +++ b/web/lib/supabase/stars.ts @@ -5,7 +5,7 @@ import {DisplayUser} from "common/api/user-types"; export const getStars = async (creatorId: string) => { const { data } = await run( db - .from('love_stars') + .from('profile_stars') .select('*') .filter('creator_id', 'eq', creatorId) .order('created_time', { ascending: false })