Rename compatibility_prompts

This commit is contained in:
MartinBraquet
2025-10-20 15:59:44 +02:00
parent cd3c8d89d0
commit d1a421ca15
14 changed files with 43 additions and 43 deletions

View File

@@ -13,7 +13,7 @@ export const createCompatibilityQuestion: APIHandler<
const pg = createSupabaseDirectClient()
const { data, error } = await tryCatch(
insert(pg, 'love_questions', {
insert(pg, 'compatibility_prompts', {
creator_id: creator.id,
question,
answer_type: 'compatibility_multiple_choice',

View File

@@ -17,22 +17,22 @@ export const getCompatibilityQuestions: APIHandler<
const pg = createSupabaseDirectClient()
const questions = await pg.manyOrNone<
Row<'love_questions'> & { answer_count: number; score: number }
Row<'compatibility_prompts'> & { answer_count: number; score: number }
>(
`SELECT
love_questions.*,
compatibility_prompts.*,
COUNT(compatibility_answers.question_id) as answer_count,
AVG(POWER(compatibility_answers.importance + 1 + CASE WHEN compatibility_answers.explanation IS NULL THEN 1 ELSE 0 END, 2)) as score
FROM
love_questions
compatibility_prompts
LEFT JOIN
compatibility_answers ON love_questions.id = compatibility_answers.question_id
compatibility_answers ON compatibility_prompts.id = compatibility_answers.question_id
WHERE
love_questions.answer_type = 'compatibility_multiple_choice'
compatibility_prompts.answer_type = 'compatibility_multiple_choice'
GROUP BY
love_questions.id
compatibility_prompts.id
ORDER BY
love_questions.importance_score
compatibility_prompts.importance_score
`,
[]
)

View File

@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS love_questions (
CREATE TABLE IF NOT EXISTS compatibility_prompts (
answer_type TEXT DEFAULT 'free_response' NOT NULL,
created_time TIMESTAMPTZ DEFAULT now() NOT NULL,
creator_id TEXT NOT NULL,
@@ -9,11 +9,11 @@ CREATE TABLE IF NOT EXISTS love_questions (
);
-- Row Level Security
ALTER TABLE love_questions ENABLE ROW LEVEL SECURITY;
ALTER TABLE compatibility_prompts ENABLE ROW LEVEL SECURITY;
-- Policies
DROP POLICY IF EXISTS "public read" ON love_questions;
CREATE POLICY "public read" ON love_questions
DROP POLICY IF EXISTS "public read" ON compatibility_prompts;
CREATE POLICY "public read" ON compatibility_prompts
FOR ALL USING (true);
-- Indexes

View File

@@ -1,26 +1,26 @@
create
or replace function public.get_compatibility_questions_with_answer_count () returns setof record language plpgsql as $function$
or replace function public.get_compatibility_prompts_with_answer_count () returns setof record language plpgsql as $function$
BEGIN
RETURN QUERY
SELECT
love_questions.*,
compatibility_prompts.*,
COUNT(compatibility_answers.question_id) as answer_count
FROM
love_questions
compatibility_prompts
LEFT JOIN
compatibility_answers ON love_questions.id = compatibility_answers.question_id
WHERE love_questions.answer_type='compatibility_multiple_choice'
compatibility_answers ON compatibility_prompts.id = compatibility_answers.question_id
WHERE compatibility_prompts.answer_type='compatibility_multiple_choice'
GROUP BY
love_questions.id
compatibility_prompts.id
ORDER BY
answer_count DESC;
END;
$function$;
create
or replace function public.get_love_question_answers_and_profiles (p_question_id bigint) returns setof record language plpgsql as $function$
or replace function public.get_compatibility_answers_and_profiles (p_question_id bigint) returns setof record language plpgsql as $function$
BEGIN
RETURN QUERY
SELECT

View File

@@ -12,7 +12,7 @@ BEGIN;
\i backend/supabase/profile_comments.sql
\i backend/supabase/compatibility_answers.sql
\i backend/supabase/profile_likes.sql
\i backend/supabase/love_questions.sql
\i backend/supabase/compatibility_prompts.sql
\i backend/supabase/love_ships.sql
\i backend/supabase/love_stars.sql
\i backend/supabase/love_waitlist.sql

View File

@@ -265,7 +265,7 @@ export const API = (_apiTypeCheck = {
props: z.object({}),
returns: {} as {
status: 'success'
questions: (Row<'love_questions'> & {
questions: (Row<'compatibility_prompts'> & {
answer_count: number
score: number
})[]

View File

@@ -157,7 +157,7 @@ export type Database = {
}
Relationships: []
}
love_questions: {
compatibility_prompts: {
Row: {
answer_type: string
created_time: string
@@ -827,15 +827,15 @@ export type Database = {
Args: { user_id: string }
Returns: number
}
get_compatibility_questions_with_answer_count: {
get_compatibility_prompts_with_answer_count: {
Args: Record<PropertyKey, never>
Returns: Record<string, unknown>[]
}
get_love_question_answers_and_lovers: {
get_compatibility_answers_and_lovers: {
Args: { p_question_id: number }
Returns: Record<string, unknown>[]
}
get_love_question_answers_and_profiles: {
get_compatibility_answers_and_profiles: {
Args: { p_question_id: number }
Returns: Record<string, unknown>[]
}

View File

@@ -53,10 +53,10 @@ function AddCompatibilityQuestionModal(props: {
onClose?: () => void
}) {
const { open, setOpen, user, onClose } = props
const [dbQuestion, setDbQuestion] = useState<rowFor<'love_questions'> | null>(
const [dbQuestion, setDbQuestion] = useState<rowFor<'compatibility_prompts'> | null>(
null
)
const afterAddQuestion = (newQuestion: rowFor<'love_questions'>) => {
const afterAddQuestion = (newQuestion: rowFor<'compatibility_prompts'>) => {
setDbQuestion(newQuestion)
console.debug('setDbQuestion', newQuestion)
}
@@ -90,7 +90,7 @@ function AddCompatibilityQuestionModal(props: {
}
function CreateCompatibilityModalContent(props: {
afterAddQuestion: (question: rowFor<'love_questions'>) => void
afterAddQuestion: (question: rowFor<'compatibility_prompts'>) => void
setOpen: (open: boolean) => void
}) {
const { afterAddQuestion, setOpen } = props
@@ -140,7 +140,7 @@ function CreateCompatibilityModalContent(props: {
console.debug('create-compatibility-question', newQuestion, data)
const q = newQuestion?.question
if (q) {
afterAddQuestion(q as rowFor<'love_questions'>)
afterAddQuestion(q as rowFor<'compatibility_prompts'>)
}
track('create love compatibility question')
} catch (e) {

View File

@@ -13,7 +13,7 @@ import { BiTachometer } from 'react-icons/bi'
export function OpinionScale(props: {
multiChoiceAnswers: rowFor<'prompt_answers'>[]
questions: rowFor<'love_questions'>[]
questions: rowFor<'compatibility_prompts'>[]
isCurrentUser: boolean
}) {
const { multiChoiceAnswers, questions, isCurrentUser } = props
@@ -75,7 +75,7 @@ export function OpinionScale(props: {
function OpinionScaleBlock(props: {
answer: rowFor<'prompt_answers'>
questions: rowFor<'love_questions'>[]
questions: rowFor<'compatibility_prompts'>[]
}) {
const { answer, questions } = props
const question = questions.find((q) => q.id === answer.question_id)

View File

@@ -108,7 +108,7 @@ const submitAnswer = async (newForm: loveAnswerState) => {
)
}
const QuestionRow = (props: { row: rowFor<'love_questions'>; user: User }) => {
const QuestionRow = (props: { row: rowFor<'compatibility_prompts'>; user: User }) => {
const { row, user } = props
const { question, id, answer_type, multiple_choice_options } = row
const options = multiple_choice_options as Record<string, number>
@@ -166,7 +166,7 @@ const QuestionRow = (props: { row: rowFor<'love_questions'>; user: User }) => {
}
export const IndividualQuestionRow = (props: {
row: rowFor<'love_questions'>
row: rowFor<'compatibility_prompts'>
initialAnswer?: rowFor<'prompt_answers'>
user: User
onCancel: () => void

View File

@@ -12,7 +12,7 @@ import { usePersistentInMemoryState } from 'web/hooks/use-persistent-in-memory-s
import { api } from 'web/lib/api'
export const useQuestions = () => {
const [questions, setQuestions] = useState<Row<'love_questions'>[]>([])
const [questions, setQuestions] = useState<Row<'compatibility_prompts'>[]>([])
useEffect(() => {
getAllQuestions().then(setQuestions)
}, [])
@@ -20,7 +20,7 @@ export const useQuestions = () => {
}
export const useFreeResponseQuestions = () => {
const [questions, setQuestions] = useState<Row<'love_questions'>[]>([])
const [questions, setQuestions] = useState<Row<'compatibility_prompts'>[]>([])
useEffect(() => {
getFreeResponseQuestions().then(setQuestions)
}, [])
@@ -74,7 +74,7 @@ export const useUserCompatibilityAnswers = (userId: string | undefined) => {
return { refreshCompatibilityAnswers, compatibilityAnswers }
}
export type QuestionWithCountType = Row<'love_questions'> & {
export type QuestionWithCountType = Row<'compatibility_prompts'> & {
answer_count: number
score: number
}

View File

@@ -15,7 +15,7 @@ export const deleteAnswer = async (
}
export const getOtherAnswers = async (question_id: number) => {
const { data } = await db.rpc('get_love_question_answers_and_profiles' as any, {
const { data } = await db.rpc('get_compatibility_answers_and_profiles' as any, {
p_question_id: question_id,
})
return data

View File

@@ -1,10 +1,10 @@
import { Row, run } from 'common/supabase/utils'
import { db } from 'web/lib/supabase/db'
export type Question = Row<'love_questions'>
export type Question = Row<'compatibility_prompts'>
export type Answer = Row<'prompt_answers'>
export const getAllQuestions = async () => {
const res = await run(
db.from('love_questions').select('*').order('created_time')
db.from('compatibility_prompts').select('*').order('created_time')
)
return res.data
}
@@ -12,7 +12,7 @@ export const getAllQuestions = async () => {
export const getFreeResponseQuestions = async () => {
const res = await run(
db
.from('love_questions')
.from('compatibility_prompts')
.select('*')
.order('created_time')
.eq('answer_type', 'free_response')
@@ -45,7 +45,7 @@ export const getFRQuestionsWithAnswerCount = async () => {
export const getCompatibilityQuestionsWithAnswerCount = async () => {
const { data } = await db.rpc(
'get_compatibility_questions_with_answer_count' as any
'get_compatibility_prompts_with_answer_count' as any
)
return data
}

View File

@@ -18,7 +18,7 @@ export default function Stats() {
'private_user_message_channels',
'private_user_messages',
'profile_comments',
'love_questions',
'compatibility_prompts',
'compatibility_answers',
'votes',
'vote_results',
@@ -58,7 +58,7 @@ export default function Stats() {
{!!data.active_members && <StatBox value={data.active_members} label={'Active Members (last month)'} />}
{!!data.private_user_message_channels && <StatBox value={data.private_user_message_channels} label={'Discussions'} />}
{!!data.private_user_messages && <StatBox value={data.private_user_messages} label={'Messages'} />}
{!!data.love_questions && <StatBox value={data.love_questions} label={'Compatibility Prompts'} />}
{!!data.compatibility_prompts && <StatBox value={data.compatibility_prompts} label={'Compatibility Prompts'} />}
{!!data.compatibility_answers && <StatBox value={data.compatibility_answers} label={'Prompts Answered'} />}
{!!data.votes && <StatBox value={data.votes} label={'Proposals'} />}
{!!data.vote_results && <StatBox value={data.vote_results} label={'Votes'} />}