Open jljabben opened 3 years ago
SQL script to delete orphan groups with all it's bills and splits from database
DELETE FROM "split" WHERE "bill_id" IN
(SELECT "id" FROM "bill" WHERE "group_id" IN
(SELECT "id" FROM "group" WHERE "id" NOT IN
(SELECT "group_id" FROM "groups_users")
)
);
DELETE FROM "bill" WHERE "group_id" IN
(SELECT "id" FROM "group" WHERE "id" NOT IN
(SELECT "group_id" FROM "groups_users")
);
DELETE FROM "group" WHERE "id" NOT IN
(SELECT "group_id" FROM "groups_users");
In case the last user of a group leaves the group too, there should be a job to delete the group with all it's bills and splits. Currently the groups will remain in database. A SQL script is needed to remove orphan groups for the first time.
Alternative: a cron job that checks the groups and deletes those that don't have any members anymore.