diff --git a/platform/backend/src/database/schemas/audit-log.ts b/platform/backend/src/database/schemas/audit-log.ts new file mode 100644 index 00000000000..2f80cef63ef --- /dev/null +++ b/platform/backend/src/database/schemas/audit-log.ts @@ -0,0 +1,28 @@ +import { pgTable, text, timestamp, uuid, jsonb } from "drizzle-orm/pg-core"; + +export const auditLogs = pgTable("audit_logs", { + id: uuid("id").primaryKey().defaultRandom(), + userId: text("user_id").notNull(), + action: text("action").notNull(), + resource: text("resource").notNull(), + resourceId: text("resource_id"), + changes: jsonb("changes"), + ipAddress: text("ip_address"), + createdAt: timestamp("created_at").defaultNow().notNull(), +}); + +// Middleware Logic (Pseudocode for Fastify) +/* +export const auditLogMiddleware = async (request, reply) => { + if (request.method !== 'GET') { + request.addHook('onResponse', async (request, reply) => { + await db.insert(auditLogs).values({ + userId: request.user.id, + action: request.method, + resource: request.url, + changes: request.body + }); + }); + } +}; +*/