feat : copy buzzy audit logs
CI / Verify (push) Successful in 2m2s
CI / Build immutable images and deploy (push) Successful in 2m47s

This commit is contained in:
2026-09-27 17:00:25 +07:00 Unverified
parent 8ddb5896b6
commit 188cec9bda
10 changed files with 152 additions and 353 deletions
+18 -27
View File
@@ -23,6 +23,14 @@ import type {
} from "@/lib/catalog/lunaris";
import type { ExtraSheet } from "@/lib/guides/extra-sheet";
export type AuditLogValue =
| string
| number
| boolean
| null
| AuditLogValue[]
| { [key: string]: AuditLogValue };
const authSchema = pgSchema("auth");
const catalogSchema = pgSchema("catalog");
const guidesSchema = pgSchema("guides");
@@ -177,42 +185,25 @@ export const outboxEvents = pgTable(
],
);
export const auditLogs = pgTable(
export const auditLog = pgTable(
"audit_log",
{
id: bigint("id", { mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity(),
actorId: text("actor_id").notNull(),
actorLabel: text("actor_label").notNull(),
action: varchar("action", { length: 64 }).notNull(),
targetType: varchar("target_type", { length: 32 }).notNull(),
targetId: text("target_id").notNull(),
scope: varchar("scope", { length: 64 }),
resultingVersion: integer("resulting_version"),
metadata: jsonb("metadata")
.$type<Record<string, string | number | boolean | null>>()
.default({})
.notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
authorId: text("author_id"),
author: text("author"),
text: text("text").notNull(),
details: jsonb("details")
.$type<Record<string, AuditLogValue>>()
.default({}),
time: timestamp("time", { withTimezone: true })
.defaultNow()
.notNull(),
},
(table) => [
index("audit_log_created_idx").on(table.createdAt, table.id),
index("audit_log_actor_created_idx").on(
table.actorId,
table.createdAt,
),
index("audit_log_target_created_idx").on(
table.targetType,
table.targetId,
table.createdAt,
),
index("audit_log_action_created_idx").on(
table.action,
table.createdAt,
),
index("audit_log_time_idx").on(table.time, table.id),
index("audit_log_author_time_idx").on(table.authorId, table.time),
],
);