feat : copy buzzy audit logs
This commit is contained in:
+18
-27
@@ -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),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user