Добавлены event_id/actorUserId и async push source_app=vps без блокировки CRUD. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -4,11 +4,13 @@ import { getDb, schema } from '../index.js'
|
||||
import { getCurrentSpaceId } from '../space-context.js'
|
||||
|
||||
export interface AuditEntryInput {
|
||||
eventId: string
|
||||
entity: string
|
||||
entityId: string
|
||||
action: 'create' | 'update' | 'delete'
|
||||
diff?: Record<string, unknown>
|
||||
actorUserId?: string | null
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
function parseDiff(row: { diff: string | null }) {
|
||||
@@ -26,13 +28,14 @@ export const auditLogRepository = {
|
||||
.insert(schema.auditLog)
|
||||
.values({
|
||||
id: `audit-${randomUUID()}`,
|
||||
eventId: input.eventId,
|
||||
spaceId: getCurrentSpaceId(),
|
||||
entity: input.entity,
|
||||
entityId: input.entityId,
|
||||
action: input.action,
|
||||
diff: input.diff ? JSON.stringify(input.diff) : null,
|
||||
actorUserId: input.actorUserId ?? null,
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: input.createdAt ?? new Date().toISOString(),
|
||||
})
|
||||
.run()
|
||||
},
|
||||
|
||||
@@ -220,6 +220,7 @@ const CORE_TABLE_MIGRATIONS: string[] = [
|
||||
)`,
|
||||
`CREATE TABLE IF NOT EXISTS audit_log (
|
||||
id TEXT PRIMARY KEY,
|
||||
eventId TEXT,
|
||||
spaceId TEXT NOT NULL DEFAULT 'space-main',
|
||||
entity TEXT NOT NULL,
|
||||
entityId TEXT NOT NULL,
|
||||
@@ -325,6 +326,7 @@ const COLUMN_MIGRATIONS: string[] = [
|
||||
`ALTER TABLE vps_health_checks ADD COLUMN spaceId TEXT`,
|
||||
`ALTER TABLE audit_log ADD COLUMN spaceId TEXT`,
|
||||
`ALTER TABLE audit_log ADD COLUMN actorUserId TEXT`,
|
||||
`ALTER TABLE audit_log ADD COLUMN eventId TEXT`,
|
||||
`ALTER TABLE spaces ADD COLUMN deletedAt TEXT`,
|
||||
`ALTER TABLE sync_log ADD COLUMN spaceId TEXT`,
|
||||
`ALTER TABLE sync_log ADD COLUMN summary TEXT`,
|
||||
|
||||
@@ -275,6 +275,7 @@ export const vpsHealthChecks = sqliteTable('vps_health_checks', {
|
||||
|
||||
export const auditLog = sqliteTable('audit_log', {
|
||||
id: text('id').primaryKey(),
|
||||
eventId: text('eventId'),
|
||||
spaceId: text('spaceId')
|
||||
.notNull()
|
||||
.default('space-main')
|
||||
|
||||
@@ -264,6 +264,7 @@ CREATE TABLE IF NOT EXISTS server_projects (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_log (
|
||||
id TEXT PRIMARY KEY,
|
||||
eventId TEXT,
|
||||
spaceId TEXT NOT NULL DEFAULT 'space-main',
|
||||
entity TEXT NOT NULL,
|
||||
entityId TEXT NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user