Files
ctms/database/migrations/20250122_add_faq_best_reply.sql
T
2025-12-26 14:07:28 +08:00

16 lines
521 B
SQL

ALTER TABLE public.faq_items
ADD COLUMN IF NOT EXISTS best_reply_id uuid;
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint WHERE conname = 'faq_items_best_reply_id_fkey'
) THEN
ALTER TABLE ONLY public.faq_items
ADD CONSTRAINT faq_items_best_reply_id_fkey
FOREIGN KEY (best_reply_id) REFERENCES public.faq_replies(id) ON DELETE SET NULL;
END IF;
END $$;
CREATE INDEX IF NOT EXISTS ix_faq_items_best_reply_id ON public.faq_items USING btree (best_reply_id);