Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
26 lines
1.2 KiB
SQL
26 lines
1.2 KiB
SQL
-- Co-Lite change add-admin-audit-log: the admin audit trail.
|
|
-- Target: `service-log`.`audit_event`. Additive only. Run once, after the release package.
|
|
-- DDL: run with a user that may create tables, not the services' user.
|
|
-- Written by services-log from the audit-event-topic Pub/Sub messages that mobile-api publishes.
|
|
USE `service-log`;
|
|
|
|
CREATE TABLE IF NOT EXISTS `audit_event` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`company_id` bigint NULL,
|
|
`occurred_at` datetime(6) NOT NULL,
|
|
`actor` varchar(191) NOT NULL,
|
|
`module` varchar(64) NULL,
|
|
`action` varchar(128) NOT NULL,
|
|
`http_method` varchar(16) NULL,
|
|
`path_template` varchar(255) NULL,
|
|
`target_id` varchar(128) NULL,
|
|
`outcome` varchar(16) NOT NULL COMMENT 'SUCCESS | FAILURE',
|
|
`http_status` int NULL,
|
|
`client_ip` varchar(64) NULL,
|
|
`changes` text NULL COMMENT 'JSON: allow-listed before/after, or changed field names',
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_audit_event_occurred_at` (`occurred_at`),
|
|
KEY `idx_audit_event_actor` (`actor`, `occurred_at`),
|
|
KEY `idx_audit_event_module_action` (`module`, `action`, `occurred_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|