ai-chatbot/lib/db/migrations/0085_add_system_setting_snapshots.sql
2026-05-29 16:52:40 +08:00

24 lines
693 B
SQL

CREATE TABLE IF NOT EXISTS "SystemSettingSnapshot" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"scope" varchar(64) NOT NULL,
"label" varchar(128),
"summary" jsonb,
"data" jsonb NOT NULL,
"createdAt" timestamp DEFAULT now() NOT NULL,
"createdBy" uuid
);
DO $$
BEGIN
ALTER TABLE "SystemSettingSnapshot"
ADD CONSTRAINT "SystemSettingSnapshot_createdBy_User_id_fk"
FOREIGN KEY ("createdBy") REFERENCES "public"."User"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION;
EXCEPTION
WHEN duplicate_object THEN NULL;
END $$;
CREATE INDEX IF NOT EXISTS "SystemSettingSnapshot_scope_createdAt_idx"
ON "SystemSettingSnapshot" ("scope", "createdAt" DESC);