-- Create audit log table for tracking all user actions CREATE TABLE IF NOT EXISTS audit_log ( audit_id BIGINT AUTO_INCREMENT PRIMARY KEY, user_id INT, action_type VARCHAR(50) NOT NULL, entity_type VARCHAR(50) NOT NULL, entity_id VARCHAR(50), details JSON, ip_address VARCHAR(45), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE SET NULL, INDEX idx_user_id (user_id), INDEX idx_created_at (created_at), INDEX idx_entity (entity_type, entity_id), INDEX idx_action_type (action_type) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;