-- Atomic even when executed as a standalone statement. Preserve retired source -- IDs, source keys, caps and all referencing history; never repurpose a row. DO $migration$ BEGIN LOCK TABLE sources IN ACCESS EXCLUSIVE MODE; ALTER TABLE sources DROP CONSTRAINT sources_type_check; ALTER TABLE sources ADD CONSTRAINT sources_type_check CHECK (type IN ('bloomberg','stocktwits','reuters','watcherguru','cnbc_business')); ALTER TABLE sources DROP CONSTRAINT sources_source_key_check; ALTER TABLE sources ADD CONSTRAINT sources_source_key_check CHECK (source_key IN ('yahoo_finance','bloomberg','watcher_guru','cnbc_business')); UPDATE sources SET enabled=false WHERE source_key='watcher_guru'; INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES(gen_random_uuid(),'CNBC Business','cnbc_business',true,20,'cnbc_business'); END $migration$;