BEGIN; ALTER TABLE public.report_customer_config ALTER COLUMN theme TYPE VARCHAR(40); ALTER TABLE public.report_customer_config DROP CONSTRAINT IF EXISTS report_customer_config_theme_check; DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conname = 'report_customer_config_theme_not_empty' AND conrelid = 'public.report_customer_config'::regclass ) THEN ALTER TABLE public.report_customer_config ADD CONSTRAINT report_customer_config_theme_not_empty CHECK (length(trim(theme)) > 0) NOT VALID; END IF; END; $$; ALTER TABLE public.report_customer_config VALIDATE CONSTRAINT report_customer_config_theme_not_empty; COMMIT;