-- Fix: migration 003 was tracked but ALTER TABLE statements did not persist.
-- Re-apply the schema changes to download_clients.

-- Add missing columns
ALTER TABLE download_clients ADD COLUMN IF NOT EXISTS url TEXT;
ALTER TABLE download_clients ADD COLUMN IF NOT EXISTS api_key TEXT;
ALTER TABLE download_clients ADD COLUMN IF NOT EXISTS category TEXT NOT NULL DEFAULT 'umm';
ALTER TABLE download_clients ADD COLUMN IF NOT EXISTS priority INTEGER NOT NULL DEFAULT 0;
ALTER TABLE download_clients ADD COLUMN IF NOT EXISTS protocol TEXT NOT NULL DEFAULT 'nzb';

-- Migrate existing rows: combine host+port into url
UPDATE download_clients SET url = 'http://' || host || ':' || port::text WHERE url IS NULL;

-- Now url should be populated — make it NOT NULL
ALTER TABLE download_clients ALTER COLUMN url SET NOT NULL;

-- Drop old columns
ALTER TABLE download_clients DROP COLUMN IF EXISTS host;
ALTER TABLE download_clients DROP COLUMN IF EXISTS port;
ALTER TABLE download_clients DROP COLUMN IF EXISTS username;
ALTER TABLE download_clients DROP COLUMN IF EXISTS password;
