审计日志并入系统管理、规范项目成员获取逻辑

This commit is contained in:
Cheng Zhou
2025-12-26 14:57:57 +08:00
parent 7c9befc3c9
commit 71db309e12
17 changed files with 94 additions and 116 deletions
@@ -1,33 +0,0 @@
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE TABLE public.faq_replies (
id uuid NOT NULL,
faq_id uuid NOT NULL,
study_id uuid,
content text NOT NULL,
created_by uuid NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
quote_reply_id uuid
);
ALTER TABLE public.faq_replies OWNER TO ctms_user;
ALTER TABLE ONLY public.faq_replies
ADD CONSTRAINT faq_replies_pkey PRIMARY KEY (id);
CREATE INDEX ix_faq_replies_faq_id ON public.faq_replies USING btree (faq_id);
CREATE INDEX ix_faq_replies_study_id ON public.faq_replies USING btree (study_id);
ALTER TABLE ONLY public.faq_replies
ADD CONSTRAINT faq_replies_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);
ALTER TABLE ONLY public.faq_replies
ADD CONSTRAINT faq_replies_faq_id_fkey FOREIGN KEY (faq_id) REFERENCES public.faq_items(id);
ALTER TABLE ONLY public.faq_replies
ADD CONSTRAINT faq_replies_quote_reply_id_fkey FOREIGN KEY (quote_reply_id) REFERENCES public.faq_replies(id);
ALTER TABLE ONLY public.faq_replies
ADD CONSTRAINT faq_replies_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);
INSERT INTO public.faq_replies (id, faq_id, study_id, content, created_by, created_at)
SELECT gen_random_uuid(), id, study_id, answer, created_by, updated_at
FROM public.faq_items
WHERE answer IS NOT NULL AND btrim(answer) <> '';
@@ -1,2 +0,0 @@
ALTER TABLE public.faq_replies
ADD COLUMN IF NOT EXISTS is_deleted boolean DEFAULT false NOT NULL;
@@ -1,15 +0,0 @@
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);
@@ -1,4 +0,0 @@
ALTER TABLE public.faq_items
ADD COLUMN IF NOT EXISTS status character varying(20) DEFAULT 'PENDING' NOT NULL;
UPDATE public.faq_items SET status = 'PENDING' WHERE status IS NULL;
@@ -1,14 +0,0 @@
ALTER TABLE public.faq_items
ADD COLUMN IF NOT EXISTS resolved_by_confirm boolean DEFAULT false NOT NULL;
UPDATE public.faq_items
SET status = CASE
WHEN best_reply_id IS NOT NULL THEN 'RESOLVED'
WHEN EXISTS (
SELECT 1 FROM public.faq_replies r
WHERE r.faq_id = faq_items.id AND r.is_deleted = false
) THEN 'PROCESSING'
ELSE 'PENDING'
END,
resolved_by_confirm = false
WHERE status = 'RESOLVED' AND best_reply_id IS NULL;