import subprocess, os
DB = ['/home/allaun/.nix-profile/bin/psql', '-h', 'localhost', '-U', 'postgres', '-d', 'appflowy']
ENV = {'PGPASSWORD': 'postgres', 'PATH': '/home/allaun/.nix-profile/bin:/usr/bin:/bin'}

r = subprocess.run(DB + ['-t', '-A', '-c', "SELECT tablename FROM pg_tables WHERE schemaname = 'public'"],
                   capture_output=True, timeout=10, env=ENV)
for tbl in r.stdout.decode().strip().split('\n'):
    if tbl.strip():
        subprocess.run(DB + ['-c', f'DROP TABLE IF EXISTS public.{tbl.strip()} CASCADE'],
                       capture_output=True, timeout=30, env=ENV)
        print(f'Dropped public.{tbl.strip()}')
print('Done')
