feat(audit): dual-write журнала в auth-portal ingest
Docker / build (push) Failing after 23s

Добавлены event_id/actorUserId и async push source_app=vps без блокировки CRUD.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-07-21 13:24:30 +07:00
co-authored by Cursor
parent 8cee00e6e3
commit a02daba69b
9 changed files with 344 additions and 11 deletions
+4 -1
View File
@@ -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()
},
+2
View File
@@ -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`,
+1
View File
@@ -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')
+1
View File
@@ -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,