ALTER TABLE sources
	ADD COLUMN IF NOT EXISTS source_owner VARCHAR(255),
	ADD COLUMN IF NOT EXISTS source_owner_email VARCHAR(255),
	ADD COLUMN IF NOT EXISTS source_owner_department VARCHAR(255),
	ADD COLUMN IF NOT EXISTS added_from_ip VARCHAR(64),
	ADD COLUMN IF NOT EXISTS notes TEXT,
	ADD COLUMN IF NOT EXISTS last_modified_by UUID REFERENCES users(id),
	ADD COLUMN IF NOT EXISTS last_modified_at TIMESTAMPTZ,
	ADD COLUMN IF NOT EXISTS file_size_limit_mb INT DEFAULT 100,
	ADD COLUMN IF NOT EXISTS ocr_enabled BOOLEAN DEFAULT TRUE,
	ADD COLUMN IF NOT EXISTS metadata_extraction BOOLEAN DEFAULT TRUE,
	ADD COLUMN IF NOT EXISTS pii_detection BOOLEAN DEFAULT TRUE;

UPDATE sources
SET
	last_modified_at = COALESCE(last_modified_at, updated_at, created_at),
	file_size_limit_mb = COALESCE(file_size_limit_mb, 100),
	ocr_enabled = COALESCE(ocr_enabled, TRUE),
	metadata_extraction = COALESCE(metadata_extraction, TRUE),
	pii_detection = COALESCE(pii_detection, TRUE);

