mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-05-18 13:47:08 -04:00
Rename compatibility_answers_free
This commit is contained in:
38
backend/supabase/compatibility_answers_free.sql
Normal file
38
backend/supabase/compatibility_answers_free.sql
Normal file
@@ -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);
|
||||
@@ -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$;
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
@@ -73,7 +73,7 @@ export type Database = {
|
||||
}
|
||||
]
|
||||
}
|
||||
prompt_answers: {
|
||||
compatibility_answers_free: {
|
||||
Row: {
|
||||
created_time: string
|
||||
creator_id: string
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -59,13 +59,13 @@ export const QuestionsForm = (props: { questionType: QuestionType }) => {
|
||||
</Col>
|
||||
)
|
||||
}
|
||||
type loveAnswer = rowFor<'prompt_answers'>
|
||||
type loveAnswer = rowFor<'compatibility_answers_free'>
|
||||
export type loveAnswerState = Omit<loveAnswer, 'id' | 'created_time'>
|
||||
|
||||
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
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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 })
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user