USE mehrgozar;

ALTER TABLE subscription_nodes
    ADD COLUMN IF NOT EXISTS total_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER client_uuid,
    ADD COLUMN IF NOT EXISTS expiry_time_ms BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER total_bytes,
    ADD COLUMN IF NOT EXISTS limit_ip INT UNSIGNED NOT NULL DEFAULT 0 AFTER expiry_time_ms,
    ADD COLUMN IF NOT EXISTS last_up BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER limit_ip,
    ADD COLUMN IF NOT EXISTS last_down BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER last_up,
    ADD COLUMN IF NOT EXISTS last_online_ms BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER last_down,
    ADD COLUMN IF NOT EXISTS synced_at DATETIME NULL AFTER last_online_ms;

CREATE INDEX IF NOT EXISTS idx_nodes_email ON subscription_nodes (client_email);
CREATE INDEX IF NOT EXISTS idx_nodes_subid ON subscription_nodes (client_sub_id);
