-- This file is autogenerated from regen-schema.ts
CREATE TABLE IF NOT EXISTS love_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 love_answers ENABLE ROW LEVEL SECURITY;

-- Policies
DROP POLICY IF EXISTS "public read" ON love_answers;
CREATE POLICY "public read" ON love_answers FOR SELECT USING (true);

DROP POLICY IF EXISTS "self delete" ON love_answers;
CREATE POLICY "self delete" ON love_answers FOR DELETE USING (creator_id = firebase_uid());

DROP POLICY IF EXISTS "self insert" ON love_answers;
CREATE POLICY "self insert" ON love_answers FOR INSERT WITH CHECK (creator_id = firebase_uid());

DROP POLICY IF EXISTS "self update" ON love_answers;
CREATE POLICY "self update" ON love_answers FOR UPDATE USING (creator_id = firebase_uid());

-- Indexes
DROP INDEX IF EXISTS love_answers_creator_id_created_time_idx;
CREATE INDEX IF NOT EXISTS love_answers_creator_id_created_time_idx
    ON public.love_answers USING btree (creator_id, created_time DESC);

DROP INDEX IF EXISTS love_answers_question_creator_unique;
CREATE UNIQUE INDEX IF NOT EXISTS love_answers_question_creator_unique
    ON public.love_answers USING btree (question_id, creator_id);

DROP INDEX IF EXISTS love_answers_question_id_idx;
CREATE INDEX IF NOT EXISTS love_answers_question_id_idx
    ON public.love_answers USING btree (question_id);
