-- Migration 052: Add offsite status columns to backup_jobs
-- Adds missing columns for SFTP offsite upload tracking

ALTER TABLE backup_jobs
ADD COLUMN IF NOT EXISTS offsite_status VARCHAR(20) DEFAULT 'pending' CHECK (offsite_status IN ('pending', 'uploading', 'uploaded', 'failed')),
ADD COLUMN IF NOT EXISTS offsite_location VARCHAR(500),
ADD COLUMN IF NOT EXISTS offsite_attempts INTEGER DEFAULT 0,
ADD COLUMN IF NOT EXISTS offsite_last_error TEXT;

-- Create index for offsite status filtering
CREATE INDEX IF NOT EXISTS idx_backup_jobs_offsite_status ON backup_jobs(offsite_status);

-- Comment
COMMENT ON COLUMN backup_jobs.offsite_status IS 'Status of SFTP offsite upload: pending, uploading, uploaded, or failed';
COMMENT ON COLUMN backup_jobs.offsite_location IS 'Remote path on SFTP server where backup was uploaded';
COMMENT ON COLUMN backup_jobs.offsite_attempts IS 'Number of offsite upload attempts';
COMMENT ON COLUMN backup_jobs.offsite_last_error IS 'Last error message from failed offsite upload';
