ai-chatbot/lib/db/migrations/0073_add_system_setting_history.sql
Your Name 8c8d2c07f5
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
fix: protect workflow settings from overwrites
2026-04-16 19:02:53 +08:00

22 lines
682 B
SQL

CREATE TABLE IF NOT EXISTS "SystemSettingHistory" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"key" varchar(128) NOT NULL,
"previousValue" jsonb,
"nextValue" jsonb,
"reason" varchar(128),
"changedAt" timestamp DEFAULT now() NOT NULL,
"changedBy" uuid
);
DO $$ BEGIN
ALTER TABLE "SystemSettingHistory"
ADD CONSTRAINT "SystemSettingHistory_changedBy_User_id_fk"
FOREIGN KEY ("changedBy") REFERENCES "public"."User"("id")
ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
CREATE INDEX IF NOT EXISTS "SystemSettingHistory_key_changedAt_idx"
ON "SystemSettingHistory" ("key", "changedAt" DESC);