When iterating on initial Postgres migrations, it's often useful to wipe all tables and replay them from scratch. Dropping and recreating the schema works, but it nukes everything else in there too — extensions, functions, sequences, types. Sometimes you just want the tables gone.
The full post has a small DO $$ block that loops over pg_tables for the current schema and issues DROP TABLE ... CASCADE for each one. Schema, extensions, and the rest stay put. Drop it into psql or a migration tool and you're back to a clean slate in one shot.
Originally published at andreasbergstrom.dev — read the full post there.
Top comments (0)