unit(D8): audit_log table + migration + audit-row builder (rule 12)

This commit is contained in:
Tiel Coder
2026-11-18 18:25:30 +00:00
parent 6982a8040d
commit b664de65f5
4 changed files with 150 additions and 0 deletions
+25
View File
@@ -295,6 +295,30 @@ export const assignments = pgTable(
],
);
/* ----------------------------------------------------------- audit log (D8) */
/**
* Append-only audit trail (ARCHITECTURE §638, BUILD-SPEC §7 rule 12).
* Every admin mutation writes one row here; the app never updates or deletes
* a row. `before_json` / `after_json` capture the before/after of the change
* (empty string when there is none); `created_at` is a UTC instant.
*/
export const auditLog = pgTable("audit_log", {
id: text("id").primaryKey(),
actorId: text("actor_id").notNull(),
actorIpHash: text("actor_ip_hash"),
action: text("action").notNull(),
entityType: text("entity_type").notNull(),
entityId: text("entity_id"),
beforeJson: text("before_json").notNull().default(""),
afterJson: text("after_json").notNull().default(""),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => [index("audit_log_created_idx").on(table.createdAt)],
);
/* ------------------------------------------------- unavailability (D4) */
/**
@@ -736,6 +760,7 @@ export const schema = {
serviceInstances,
slots,
assignments,
auditLog,
unavailability,
skillCategories,
vendors,