Skip to content

Commit

Permalink
disabling triggers when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni committed May 6, 2021
1 parent 5c761b3 commit ad16dfd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func (m *Model) CleanDB() error {
_tbl text;
_sch text;
BEGIN
FOR _sch, _tbl IN
SELECT schemaname, tablename
FROM pg_tables
WHERE tablename <> '%s' AND schemaname NOT IN ('pg_catalog', 'information_schema') AND tableowner = current_user
LOOP
--RAISE ERROR '%%',
EXECUTE -- dangerous, test before you execute!
format('DELETE FROM %%I.%%I CASCADE', _sch, _tbl);
END LOOP;
FOR _sch, _tbl IN
SELECT schemaname, tablename
FROM pg_tables
WHERE tablename <> '%s' AND schemaname NOT IN ('pg_catalog', 'information_schema') AND tableowner = current_user
LOOP
EXECUTE format('ALTER TABLE %%I.%%I DISABLE TRIGGER ALL;', _sch, _tbl);
EXECUTE format('DELETE FROM %%I.%%I CASCADE', _sch, _tbl);
EXECUTE format('ALTER TABLE %%I.%%I ENABLE TRIGGER ALL;', _sch, _tbl);
END LOOP;
END
$func$;`

Expand Down

0 comments on commit ad16dfd

Please sign in to comment.