guys, what is a safe way to drop all tables quickl...
# sql
w
guys, what is a safe way to drop all tables quickly? Can I just run this script as I would do in a normal Postgres DB, or will it mess up some Supabase-specific stuff?
Copy code
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
(Background: I'm coding a tool that migrates an Airtable base to Postgres / Supabase and need to "reset" the target Supabase tables frequently. So it is a dev/test project at the moment, but once I get the migration right, I want to continue to develop the live app on top of it, so I'm a bit paranoid it will mess up something in long run)
s
This was asked before [0] but we don't have a straightforward way to do this. If you want to drop all tables in
public
, though, that's simpler: [1] [0] https://github.com/supabase/supabase/discussions/1829 [1] https://stackoverflow.com/questions/59720477/how-to-delete-every-table-in-a-specific-schema-in-postgres?noredirect=1&lq=1
w
I only want to drop the tables I've created myself by running SQL statements using
pg
(via connection string
postgres://postgres:blabla@db.blabla.supabase.co:5432/postgres
), so I assume yes, I need to delete all tables in
public
. So when I run this, it shouldn't mess up anything Supabase has configured when the project was created or when a table is added via GUI?
Copy code
DO $$
DECLARE
  row record;
BEGIN
    FOR row IN SELECT * FROM pg_tables WHERE schemaname = 'public' 
    LOOP
      EXECUTE 'DROP TABLE public.' || quote_ident(row.tablename) || ' CASCADE';
    END LOOP;
END;
$$;
?
s
Yeah there shouldn't be a Supabase-managed table in
public