SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS integration_http_logs (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    workspace_id BIGINT UNSIGNED NULL,
    integration_id BIGINT UNSIGNED NULL,
    adapter VARCHAR(120) NOT NULL,
    method VARCHAR(12) NOT NULL,
    url VARCHAR(500) NOT NULL,
    http_status INT NULL,
    request_meta JSON NULL,
    response_meta JSON NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_ihttp_workspace_time(workspace_id,created_at),
    INDEX idx_ihttp_integration_time(integration_id,created_at),
    CONSTRAINT fk_ihttp_workspace FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE SET NULL,
    CONSTRAINT fk_ihttp_integration FOREIGN KEY(integration_id) REFERENCES integrations(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS maintenance_runs (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    workspace_id BIGINT UNSIGNED NULL,
    user_id BIGINT UNSIGNED NULL,
    action VARCHAR(120) NOT NULL,
    result_json JSON NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_maintenance_ws_time(workspace_id,created_at),
    CONSTRAINT fk_mr_workspace FOREIGN KEY(workspace_id) REFERENCES workspaces(id) ON DELETE SET NULL,
    CONSTRAINT fk_mr_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
