addSql(<<<'SQL' DO $$ DECLARE r RECORD; BEGIN -- Special-case legacy table name from Prisma. IF EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'ModelType' ) THEN EXECUTE 'ALTER TABLE public."ModelType" RENAME TO model_types'; END IF; -- Rename columns containing uppercase letters. FOR r IN SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = 'public' AND column_name ~ '[A-Z]' LOOP EXECUTE format( 'ALTER TABLE public.%I RENAME COLUMN %I TO %I', r.table_name, r.column_name, lower(r.column_name) ); END LOOP; -- Rename tables containing uppercase letters. FOR r IN SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name ~ '[A-Z]' LOOP EXECUTE format( 'ALTER TABLE public.%I RENAME TO %I', r.table_name, lower(r.table_name) ); END LOOP; END $$; SQL); } public function down(Schema $schema): void { // Irreversible: cannot restore original casing reliably. } }