feat(audit): 增加审计事件基础模块

This commit is contained in:
2026-07-08 16:17:36 +08:00
parent 64f49c512f
commit 73e8dfa8c8
9 changed files with 297 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
CREATE TABLE "audit_events" (
"id" TEXT NOT NULL,
"actor_id" TEXT,
"actor_name" TEXT NOT NULL DEFAULT '',
"action" TEXT NOT NULL,
"entity_type" TEXT NOT NULL,
"entity_id" TEXT NOT NULL,
"product_id" TEXT,
"project_id" TEXT,
"version_id" TEXT,
"scope" JSONB NOT NULL DEFAULT '{}',
"before" JSONB,
"after" JSONB,
"metadata" JSONB NOT NULL DEFAULT '{}',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "audit_events_pkey" PRIMARY KEY ("id", "created_at")
) PARTITION BY RANGE ("created_at");
CREATE TABLE "audit_events_default" PARTITION OF "audit_events" DEFAULT;
CREATE INDEX "audit_events_actor_created_at_idx" ON "audit_events"("actor_id", "created_at" DESC);
CREATE INDEX "audit_events_entity_created_at_idx" ON "audit_events"("entity_type", "entity_id", "created_at" DESC);
CREATE INDEX "audit_events_product_created_at_idx" ON "audit_events"("product_id", "created_at" DESC);
CREATE INDEX "audit_events_project_created_at_idx" ON "audit_events"("project_id", "created_at" DESC);
CREATE INDEX "audit_events_version_created_at_idx" ON "audit_events"("version_id", "created_at" DESC);