feat: audit_event table, Audit log module and audit Pub/Sub topic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-30 15:40:26 +08:00
1 parent 01603e9ece
commit b9912478e0
6 files changed
+67 -1

No files matched your search

@@ -0,0 +1,25 @@
-- 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;
@@ -0,0 +1,7 @@
-- Co-Lite change add-admin-audit-log: the Audit log back-office module (area BO).
-- Target: `service-system`.`module`. Additive only. Run once, after the release package.
-- No role grant: super admins see every module; they grant BO_AUDIT_LOG to other roles under Roles.
USE `service-system`;
INSERT INTO `module` (`id`, `name`, `desc`, `area`, `type`, `parent`, `url`, `icon_name`) VALUES
(41100000, 'BO_AUDIT_LOG', 'Audit log', 'BO', 'M', 40000000, '/audit-log', 'ScrollText');
@@ -0,0 +1,7 @@
-- Co-Lite change add-admin-audit-log: rollback of 01-02. Destroys the audit trail.
USE `service-system`;
DELETE FROM `modules_roles` WHERE `module_id` = 41100000;
DELETE FROM `module` WHERE `id` = 41100000;
USE `service-log`;
DROP TABLE IF EXISTS `audit_event`;