From 27bf4eadf99e94c290608a1c728da345953a70c7 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Mon, 20 Oct 2025 16:10:41 +0200 Subject: [PATCH] Rename compatibility_answers_free --- .../supabase/compatibility_answers_free.sql | 38 +++++++++++++++++++ backend/supabase/functions_others.sql | 16 ++++---- backend/supabase/migration.sql | 2 +- backend/supabase/prompts_answers.sql | 38 ------------------- common/src/supabase/schema.ts | 2 +- .../answers/free-response-display.tsx | 2 +- .../answers/opinion-scale-display.tsx | 4 +- web/components/questions-form.tsx | 8 ++-- web/hooks/use-questions.ts | 2 +- web/lib/supabase/answers.ts | 4 +- web/lib/supabase/questions.ts | 4 +- 11 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 backend/supabase/compatibility_answers_free.sql delete mode 100644 backend/supabase/prompts_answers.sql diff --git a/backend/supabase/compatibility_answers_free.sql b/backend/supabase/compatibility_answers_free.sql new file mode 100644 index 00000000..abe08e46 --- /dev/null +++ b/backend/supabase/compatibility_answers_free.sql @@ -0,0 +1,38 @@ +CREATE TABLE IF NOT EXISTS compatibility_answers_free ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + created_time TIMESTAMPTZ DEFAULT now() NOT NULL, + creator_id TEXT NOT NULL, + free_response TEXT, + integer INTEGER, + multiple_choice INTEGER, + question_id BIGINT NOT NULL + ); + +-- Row Level Security +ALTER TABLE compatibility_answers_free ENABLE ROW LEVEL SECURITY; + +-- Policies +DROP POLICY IF EXISTS "public read" ON compatibility_answers_free; +CREATE POLICY "public read" ON compatibility_answers_free FOR SELECT USING (true); + +DROP POLICY IF EXISTS "self delete" ON compatibility_answers_free; +CREATE POLICY "self delete" ON compatibility_answers_free FOR DELETE USING (creator_id = firebase_uid()); + +DROP POLICY IF EXISTS "self insert" ON compatibility_answers_free; +CREATE POLICY "self insert" ON compatibility_answers_free FOR INSERT WITH CHECK (creator_id = firebase_uid()); + +DROP POLICY IF EXISTS "self update" ON compatibility_answers_free; +CREATE POLICY "self update" ON compatibility_answers_free FOR UPDATE USING (creator_id = firebase_uid()); + +-- Indexes +DROP INDEX IF EXISTS compatibility_answers_free_creator_id_created_time_idx; +CREATE INDEX IF NOT EXISTS compatibility_answers_free_creator_id_created_time_idx + ON public.compatibility_answers_free USING btree (creator_id, created_time DESC); + +DROP INDEX IF EXISTS compatibility_answers_free_question_creator_unique; +CREATE UNIQUE INDEX IF NOT EXISTS compatibility_answers_free_question_creator_unique + ON public.compatibility_answers_free USING btree (question_id, creator_id); + +DROP INDEX IF EXISTS compatibility_answers_free_question_id_idx; +CREATE INDEX IF NOT EXISTS compatibility_answers_free_question_id_idx + ON public.compatibility_answers_free USING btree (question_id); diff --git a/backend/supabase/functions_others.sql b/backend/supabase/functions_others.sql index 12095d48..5a40509c 100644 --- a/backend/supabase/functions_others.sql +++ b/backend/supabase/functions_others.sql @@ -24,11 +24,11 @@ or replace function public.get_compatibility_answers_and_profiles (p_question_id BEGIN RETURN QUERY SELECT - prompt_answers.question_id, - prompt_answers.created_time, - prompt_answers.free_response, - prompt_answers.multiple_choice, - prompt_answers.integer, + compatibility_answers_free.question_id, + compatibility_answers_free.created_time, + compatibility_answers_free.free_response, + compatibility_answers_free.multiple_choice, + compatibility_answers_free.integer, profiles.age, profiles.gender, profiles.city, @@ -36,11 +36,11 @@ SELECT FROM profiles JOIN - prompt_answers ON profiles.user_id = prompt_answers.creator_id + compatibility_answers_free ON profiles.user_id = compatibility_answers_free.creator_id join users on profiles.user_id = users.id WHERE - prompt_answers.question_id = p_question_id -order by prompt_answers.created_time desc; + compatibility_answers_free.question_id = p_question_id +order by compatibility_answers_free.created_time desc; END; $function$; \ No newline at end of file diff --git a/backend/supabase/migration.sql b/backend/supabase/migration.sql index 1f259f59..fa874870 100644 --- a/backend/supabase/migration.sql +++ b/backend/supabase/migration.sql @@ -8,7 +8,7 @@ BEGIN; \i backend/supabase/private_users.sql \i backend/supabase/private_user_messages.sql \i backend/supabase/private_user_seen_message_channels.sql -\i backend/supabase/prompt_answers.sql +\i backend/supabase/compatibility_answers_free.sql \i backend/supabase/profile_comments.sql \i backend/supabase/compatibility_answers.sql \i backend/supabase/profile_likes.sql diff --git a/backend/supabase/prompts_answers.sql b/backend/supabase/prompts_answers.sql deleted file mode 100644 index 30f4ab01..00000000 --- a/backend/supabase/prompts_answers.sql +++ /dev/null @@ -1,38 +0,0 @@ -CREATE TABLE IF NOT EXISTS prompt_answers ( - id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - created_time TIMESTAMPTZ DEFAULT now() NOT NULL, - creator_id TEXT NOT NULL, - free_response TEXT, - integer INTEGER, - multiple_choice INTEGER, - question_id BIGINT NOT NULL - ); - --- Row Level Security -ALTER TABLE prompt_answers ENABLE ROW LEVEL SECURITY; - --- Policies -DROP POLICY IF EXISTS "public read" ON prompt_answers; -CREATE POLICY "public read" ON prompt_answers FOR SELECT USING (true); - -DROP POLICY IF EXISTS "self delete" ON prompt_answers; -CREATE POLICY "self delete" ON prompt_answers FOR DELETE USING (creator_id = firebase_uid()); - -DROP POLICY IF EXISTS "self insert" ON prompt_answers; -CREATE POLICY "self insert" ON prompt_answers FOR INSERT WITH CHECK (creator_id = firebase_uid()); - -DROP POLICY IF EXISTS "self update" ON prompt_answers; -CREATE POLICY "self update" ON prompt_answers FOR UPDATE USING (creator_id = firebase_uid()); - --- Indexes -DROP INDEX IF EXISTS prompt_answers_creator_id_created_time_idx; -CREATE INDEX IF NOT EXISTS prompt_answers_creator_id_created_time_idx - ON public.prompt_answers USING btree (creator_id, created_time DESC); - -DROP INDEX IF EXISTS prompt_answers_question_creator_unique; -CREATE UNIQUE INDEX IF NOT EXISTS prompt_answers_question_creator_unique - ON public.prompt_answers USING btree (question_id, creator_id); - -DROP INDEX IF EXISTS prompt_answers_question_id_idx; -CREATE INDEX IF NOT EXISTS prompt_answers_question_id_idx - ON public.prompt_answers USING btree (question_id); diff --git a/common/src/supabase/schema.ts b/common/src/supabase/schema.ts index 69f6c2ed..db700917 100644 --- a/common/src/supabase/schema.ts +++ b/common/src/supabase/schema.ts @@ -73,7 +73,7 @@ export type Database = { } ] } - prompt_answers: { + compatibility_answers_free: { Row: { created_time: string creator_id: string diff --git a/web/components/answers/free-response-display.tsx b/web/components/answers/free-response-display.tsx index db354886..c6973eb8 100644 --- a/web/components/answers/free-response-display.tsx +++ b/web/components/answers/free-response-display.tsx @@ -92,7 +92,7 @@ export function FreeResponseDisplay(props: { } function AnswerBlock(props: { - answer: rowFor<'prompt_answers'> + answer: rowFor<'compatibility_answers_free'> questions: QuestionWithCountType[] isCurrentUser: boolean user: User diff --git a/web/components/answers/opinion-scale-display.tsx b/web/components/answers/opinion-scale-display.tsx index d13230e8..c7f5bef9 100644 --- a/web/components/answers/opinion-scale-display.tsx +++ b/web/components/answers/opinion-scale-display.tsx @@ -12,7 +12,7 @@ import { Subtitle } from '../widgets/profile-subtitle' import { BiTachometer } from 'react-icons/bi' export function OpinionScale(props: { - multiChoiceAnswers: rowFor<'prompt_answers'>[] + multiChoiceAnswers: rowFor<'compatibility_answers_free'>[] questions: rowFor<'compatibility_prompts'>[] isCurrentUser: boolean }) { @@ -74,7 +74,7 @@ export function OpinionScale(props: { } function OpinionScaleBlock(props: { - answer: rowFor<'prompt_answers'> + answer: rowFor<'compatibility_answers_free'> questions: rowFor<'compatibility_prompts'>[] }) { const { answer, questions } = props diff --git a/web/components/questions-form.tsx b/web/components/questions-form.tsx index 0f7f922b..dbce69a2 100644 --- a/web/components/questions-form.tsx +++ b/web/components/questions-form.tsx @@ -59,13 +59,13 @@ export const QuestionsForm = (props: { questionType: QuestionType }) => { ) } -type loveAnswer = rowFor<'prompt_answers'> +type loveAnswer = rowFor<'compatibility_answers_free'> export type loveAnswerState = Omit const fetchPrevious = async (id: number, userId: string) => { const res = await run( db - .from('prompt_answers') + .from('compatibility_answers_free') .select('*') .eq('question_id', id) .eq('creator_id', userId) @@ -103,7 +103,7 @@ const submitAnswer = async (newForm: loveAnswerState) => { } as loveAnswerState await run( db - .from('prompt_answers') + .from('compatibility_answers_free') .upsert(input, { onConflict: 'question_id,creator_id' }) ) } @@ -167,7 +167,7 @@ const QuestionRow = (props: { row: rowFor<'compatibility_prompts'>; user: User } export const IndividualQuestionRow = (props: { row: rowFor<'compatibility_prompts'> - initialAnswer?: rowFor<'prompt_answers'> + initialAnswer?: rowFor<'compatibility_answers_free'> user: User onCancel: () => void onSubmit?: () => void diff --git a/web/hooks/use-questions.ts b/web/hooks/use-questions.ts index 093a9c53..1773b419 100644 --- a/web/hooks/use-questions.ts +++ b/web/hooks/use-questions.ts @@ -29,7 +29,7 @@ export const useFreeResponseQuestions = () => { export const useUserAnswers = (userId: string | undefined) => { const [answers, setAnswers] = usePersistentInMemoryState< - Row<'prompt_answers'>[] + Row<'compatibility_answers_free'>[] >([], `answers-${userId}`) useEffect(() => { diff --git a/web/lib/supabase/answers.ts b/web/lib/supabase/answers.ts index 66cf6ed2..f0888b8d 100644 --- a/web/lib/supabase/answers.ts +++ b/web/lib/supabase/answers.ts @@ -2,13 +2,13 @@ import { Row as rowFor, run } from 'common/supabase/utils' import { db } from 'web/lib/supabase/db' export const deleteAnswer = async ( - answer: rowFor<'prompt_answers'>, + answer: rowFor<'compatibility_answers_free'>, userId?: string ) => { if (!userId || answer.creator_id !== userId) return await run( db - .from('prompt_answers') + .from('compatibility_answers_free') .delete() .match({ id: answer.id, creator_id: userId }) ) diff --git a/web/lib/supabase/questions.ts b/web/lib/supabase/questions.ts index 9e94ea37..c212a191 100644 --- a/web/lib/supabase/questions.ts +++ b/web/lib/supabase/questions.ts @@ -1,7 +1,7 @@ import { Row, run } from 'common/supabase/utils' import { db } from 'web/lib/supabase/db' export type Question = Row<'compatibility_prompts'> -export type Answer = Row<'prompt_answers'> +export type Answer = Row<'compatibility_answers_free'> export const getAllQuestions = async () => { const res = await run( db.from('compatibility_prompts').select('*').order('created_time') @@ -22,7 +22,7 @@ export const getFreeResponseQuestions = async () => { export const getUserAnswers = async (userId: string) => { const { data } = await run( - db.from('prompt_answers').select('*').eq('creator_id', userId) + db.from('compatibility_answers_free').select('*').eq('creator_id', userId) ) return data }