From 8b17a175c3e7e27b789812eba4e3cd760beadb10 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Tue, 6 Jan 2026 04:08:11 +0000
Subject: Initial Control system

---
 .../20250110000004_create_api_key_events_table.sql   | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 makima/migrations/20250110000004_create_api_key_events_table.sql

(limited to 'makima/migrations/20250110000004_create_api_key_events_table.sql')

diff --git a/makima/migrations/20250110000004_create_api_key_events_table.sql b/makima/migrations/20250110000004_create_api_key_events_table.sql
new file mode 100644
index 0000000..cb07bb3
--- /dev/null
+++ b/makima/migrations/20250110000004_create_api_key_events_table.sql
@@ -0,0 +1,20 @@
+-- Audit log for API key operations
+CREATE TABLE IF NOT EXISTS api_key_events (
+    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+    api_key_id UUID NOT NULL REFERENCES api_keys(id) ON DELETE CASCADE,
+    event_type VARCHAR(32) NOT NULL,
+    -- Request metadata
+    ip_address INET,
+    user_agent TEXT,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+
+    CONSTRAINT valid_event_type CHECK (
+        event_type IN ('created', 'used', 'revoked', 'refreshed')
+    )
+);
+
+CREATE INDEX idx_api_key_events_api_key_id ON api_key_events(api_key_id);
+CREATE INDEX idx_api_key_events_created_at ON api_key_events(created_at DESC);
+CREATE INDEX idx_api_key_events_event_type ON api_key_events(event_type);
+
+COMMENT ON TABLE api_key_events IS 'Audit log for API key lifecycle events';
-- 
cgit v1.2.3

