DO $$ BEGIN IF EXISTS ( SELECT 1 FROM source_connections WHERE source_type = 'manual' ) THEN RAISE EXCEPTION 'cannot downgrade while manual source connections exist'; END IF; END $$; ALTER TABLE source_connections DROP CONSTRAINT IF EXISTS source_connections_source_type_check; ALTER TABLE source_connections ADD CONSTRAINT source_connections_source_type_check CHECK (source_type IN ('pp', 'alist', 'dingtalk'));