-- ============================================================================
-- ServerManager Soft Deletes
-- Adds status column for soft deletes instead of physical row removal
-- Exceptions: monitoring_history, rate_limits, sessions (physical purge OK)
-- Exceptions: audit_logs (immutable, never deleted)
-- ============================================================================

ALTER TABLE `users`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `updated_at`,
    ADD INDEX `idx_users_status` (`status`);

ALTER TABLE `servers`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `updated_at`,
    ADD INDEX `idx_servers_status` (`status`);

ALTER TABLE `teams`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `updated_at`,
    ADD INDEX `idx_teams_status` (`status`);

ALTER TABLE `command_history`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `executed_at`,
    ADD INDEX `idx_command_history_status` (`status`);

ALTER TABLE `server_user`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `role`,
    ADD INDEX `idx_server_user_status` (`status`);

ALTER TABLE `team_user`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `created_at`,
    ADD INDEX `idx_team_user_status` (`status`);

ALTER TABLE `team_server`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `role`,
    ADD INDEX `idx_team_server_status` (`status`);

ALTER TABLE `api_tokens`
    ADD COLUMN `status` ENUM('active', 'disabled', 'deleted') NOT NULL DEFAULT 'active' AFTER `expires_at`,
    ADD INDEX `idx_api_tokens_status` (`status`);

-- ============================================================================
-- FK constraints remain unchanged:
-- ON DELETE CASCADE only fires on physical DELETE, which we no longer do.
-- monitoring_history, rate_limits, sessions keep physical purge.
-- ============================================================================
