feat(db): add audit integrity/requestId columns, user_preferences table, audit indexes

This commit is contained in:
SnapOtter
2026-06-13 16:17:17 +08:00
parent b8b6b0a44a
commit cafd2d8b65
4 changed files with 1027 additions and 14 deletions
+14
View File
@@ -0,0 +1,14 @@
CREATE TABLE "user_preferences" (
"user_id" text NOT NULL,
"key" text NOT NULL,
"value" jsonb NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "user_preferences_user_id_key_pk" PRIMARY KEY("user_id","key")
);
--> statement-breakpoint
ALTER TABLE "audit_log" ADD COLUMN "integrity" text;--> statement-breakpoint
ALTER TABLE "audit_log" ADD COLUMN "request_id" text;--> statement-breakpoint
ALTER TABLE "user_preferences" ADD CONSTRAINT "user_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "audit_log_created_at_idx" ON "audit_log" USING btree ("created_at");--> statement-breakpoint
CREATE INDEX "audit_log_action_idx" ON "audit_log" USING btree ("action");--> statement-breakpoint
CREATE INDEX "audit_log_actor_id_idx" ON "audit_log" USING btree ("actor_id");