kitgit

tirbofish/kitgit · commit

b1ad0c6422f8f180452f81645bd6f165f457d9b3

merge: feat/user-audit-log into integrate/all-features

Verified

Thribhu K <4tkbytes@pm.me> · 2026-07-28 23:38

view full diff

diff --git a/migrations/011_user_audit_log.sql b/migrations/011_user_audit_log.sql
new file mode 100644
index 0000000..13a5f1b
--- /dev/null
+++ b/migrations/011_user_audit_log.sql
@@ -0,0 +1,18 @@
+-- Per-user security / account audit trail (separate from activity_events social feed).
+CREATE TABLE IF NOT EXISTS audit_log (
+    id BIGSERIAL PRIMARY KEY,
+    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+    actor_id UUID REFERENCES users(id) ON DELETE SET NULL,
+    action TEXT NOT NULL,
+    ip TEXT,
+    user_agent TEXT,
+    metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
+);
+
+CREATE INDEX IF NOT EXISTS audit_log_user_id_created_at_idx
+    ON audit_log(user_id, created_at DESC);
+CREATE INDEX IF NOT EXISTS audit_log_created_at_idx
+    ON audit_log(created_at DESC);
+CREATE INDEX IF NOT EXISTS audit_log_action_idx
+    ON audit_log(action);
diff --git a/src/db/models.rs b/src/db/models.rs
index 236c066..441145f 100644
--- a/src/db/models.rs
+++ b/src/db/models.rs
@@ -171,6 +171,19 @@ pub struct ActivityEvent {
     pub created_at: DateTime<Utc>,
 }
 
+/// Per-user security / account audit entry (not the social activity feed).
+#[derive(Debug, Clone, FromRow)]
+pub struct AuditLog {
+    pub id: i64,
+    pub user_id: Uuid,
+    pub actor_id: Option<Uuid>,
+    pub action: String,
+    pub ip: Option<String>,
+    pub user_agent: Option<String>,
+    pub metadata: serde_json::Value,
+    pub created_at: DateTime<Utc>,
+}
+
 #[derive(Debug, Clone, FromRow)]
 pub struct Issue {
     pub id: Uuid,
diff --git a/src/db/queries.rs b/src/db/queries.rs
index 10890a5..7a47198 100644

Large diffs are not rendered by default. Showing the first 50 of 740 lines. Show full diff