ALTER TABLE operation_logs ADD COLUMN administrator_id BIGINT UNSIGNED NULL; ALTER TABLE operation_logs ADD COLUMN impersonated_user_id BIGINT UNSIGNED NULL; ALTER TABLE operation_logs ADD COLUMN admin_action BOOLEAN NOT NULL DEFAULT FALSE; UPDATE operation_logs l JOIN users u ON u.id=l.user_id SET l.admin_action=TRUE,l.administrator_id=u.id WHERE u.role='admin'; UPDATE operation_logs SET admin_action=TRUE WHERE resource_type IN ('plan','tenant','domain_approval','system_settings','project_network','host_subscription','panel_site','node','node_task','runtime_component','runtime_environment','runtime_maintenance','impersonation'); CREATE TABLE impersonation_sessions ( token_hash BINARY(32) PRIMARY KEY, parent_session_hash BINARY(32) NOT NULL, administrator_id BIGINT UNSIGNED NOT NULL, target_user_id BIGINT UNSIGNED NOT NULL, expires_at DATETIME NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX idx_impersonation_target (target_user_id), CONSTRAINT fk_impersonation_parent FOREIGN KEY (parent_session_hash) REFERENCES sessions(token_hash) ON DELETE CASCADE, CONSTRAINT fk_impersonation_administrator FOREIGN KEY (administrator_id) REFERENCES users(id) ON DELETE CASCADE, CONSTRAINT fk_impersonation_target FOREIGN KEY (target_user_id) REFERENCES users(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;