Skip to content

Commit 9466ff7

Browse files
committed
fix: trigger
1 parent 891cbae commit 9466ff7

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

coderd/database/migrations/000296_organization_soft_delete.up.sql

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,22 @@ BEGIN
4949
Select count(*) as count FROM provisioner_keys
5050
WHERE
5151
provisioner_keys.organization_id = OLD.id
52-
)
52+
);
5353

5454
-- Fail the deletion if one of the following:
5555
-- * the organization has 1 or more workspaces
5656
-- * the organization has 1 or more templates
5757
-- * the organization has 1 or more groups other than "Everyone" group
5858
-- * the organization has 1 or more members other than the organization owner
5959

60-
IF (workspace_count + template_count) > 0 THEN
61-
RAISE EXCEPTION 'cannot delete organization: organization has % workspaces and % templates that must be deleted first', workspace_count, template_count;
60+
IF (workspace_count + template_count + provisioner_keys_count) > 0 THEN
61+
RAISE EXCEPTION 'cannot delete organization: organization has % workspaces, % templates, and % provisioner keys that must be deleted first', workspace_count, template_count, provisioner_keys_count;
6262
END IF;
6363

6464
IF (group_count) > 1 THEN
6565
RAISE EXCEPTION 'cannot delete organization: organization has % groups that must be deleted first', group_count - 1;
6666
END IF;
6767

68-
IF (provisioner_keys_count) > 0 THEN
69-
RAISE EXCEPTION 'cannot delete organization: organization has % provisioner keys that must be deleted first', provisioner_keys_count;
70-
END IF;
71-
72-
-- If member count > 1
7368
-- Allow 1 member to exist, because you cannot remove yourself. You can
7469
-- remove everyone else. Ideally, we only omit the member that matches
7570
-- the user_id of the caller, however in a trigger, the caller is unknown.

0 commit comments

Comments
 (0)