Skip to content

Commit

Permalink
fix: disable FK constraints when wiping rows (#1768)
Browse files Browse the repository at this point in the history
Fixes #1766
  • Loading branch information
alecthomas authored Jun 13, 2024
1 parent 9f49895 commit d6ad5ae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions go-runtime/ftl/ftltest/ftltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ func WithDatabase(dbHandle ftl.Database) Option {
}
_, err = sqlDB.ExecContext(ctx, `DO $$
DECLARE
table_name text;
table_name text;
BEGIN
FOR table_name IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
LOOP
EXECUTE 'DELETE FROM ' || table_name;
END LOOP;
FOR table_name IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
LOOP
EXECUTE 'ALTER TABLE ' || quote_ident(table_name) || ' DISABLE TRIGGER ALL;';
EXECUTE 'DELETE FROM ' || quote_ident(table_name) || ';';
EXECUTE 'ALTER TABLE ' || quote_ident(table_name) || ' ENABLE TRIGGER ALL;';
END LOOP;
END $$;`)
if err != nil {
return fmt.Errorf("could not clear tables in database %q: %w", dbHandle.Name, err)
Expand Down

0 comments on commit d6ad5ae

Please sign in to comment.