Skip to content

Commit 8fd0740

Browse files
committed
fix: consistent spacing in sql migrations
1 parent 4cfd54c commit 8fd0740

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

coderd/database/migrations/000306_update_protect_deleting_organization_function.down.sql

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ DROP TRIGGER IF EXISTS protect_deleting_organizations ON organizations;
33

44
-- Revert the function to its original implementation
55
CREATE OR REPLACE FUNCTION protect_deleting_organizations()
6-
RETURNS TRIGGER AS
6+
RETURNS TRIGGER AS
77
$$
88
DECLARE
99
workspace_count int;
10-
template_count int;
11-
group_count int;
12-
member_count int;
13-
provisioner_keys_count int;
10+
template_count int;
11+
group_count int;
12+
member_count int;
13+
provisioner_keys_count int;
1414
BEGIN
1515
workspace_count := (
1616
SELECT count(*) as count FROM workspaces
@@ -19,50 +19,50 @@ BEGIN
1919
AND workspaces.deleted = false
2020
);
2121

22-
template_count := (
22+
template_count := (
2323
SELECT count(*) as count FROM templates
2424
WHERE
2525
templates.organization_id = OLD.id
2626
AND templates.deleted = false
2727
);
2828

29-
group_count := (
29+
group_count := (
3030
SELECT count(*) as count FROM groups
3131
WHERE
3232
groups.organization_id = OLD.id
3333
);
3434

35-
member_count := (
35+
member_count := (
3636
SELECT count(*) as count FROM organization_members
3737
WHERE
3838
organization_members.organization_id = OLD.id
3939
);
4040

41-
provisioner_keys_count := (
42-
Select count(*) as count FROM provisioner_keys
43-
WHERE
44-
provisioner_keys.organization_id = OLD.id
45-
);
41+
provisioner_keys_count := (
42+
Select count(*) as count FROM provisioner_keys
43+
WHERE
44+
provisioner_keys.organization_id = OLD.id
45+
);
4646

4747
-- Fail the deletion if one of the following:
4848
-- * the organization has 1 or more workspaces
49-
-- * the organization has 1 or more templates
50-
-- * the organization has 1 or more groups other than "Everyone" group
51-
-- * the organization has 1 or more members other than the organization owner
52-
-- * the organization has 1 or more provisioner keys
49+
-- * the organization has 1 or more templates
50+
-- * the organization has 1 or more groups other than "Everyone" group
51+
-- * the organization has 1 or more members other than the organization owner
52+
-- * the organization has 1 or more provisioner keys
5353

5454
IF (workspace_count + template_count + provisioner_keys_count) > 0 THEN
5555
RAISE EXCEPTION 'cannot delete organization: organization has % workspaces, % templates, and % provisioner keys that must be deleted first', workspace_count, template_count, provisioner_keys_count;
5656
END IF;
5757

58-
IF (group_count) > 1 THEN
58+
IF (group_count) > 1 THEN
5959
RAISE EXCEPTION 'cannot delete organization: organization has % groups that must be deleted first', group_count - 1;
6060
END IF;
6161

6262
-- Allow 1 member to exist, because you cannot remove yourself. You can
6363
-- remove everyone else. Ideally, we only omit the member that matches
6464
-- the user_id of the caller, however in a trigger, the caller is unknown.
65-
IF (member_count) > 1 THEN
65+
IF (member_count) > 1 THEN
6666
RAISE EXCEPTION 'cannot delete organization: organization has % members that must be deleted first', member_count - 1;
6767
END IF;
6868

coderd/database/migrations/000306_update_protect_deleting_organization_function.up.sql

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ DROP TRIGGER IF EXISTS protect_deleting_organizations ON organizations;
22

33
-- Replace the function with the new implementation
44
CREATE OR REPLACE FUNCTION protect_deleting_organizations()
5-
RETURNS TRIGGER AS
5+
RETURNS TRIGGER AS
66
$$
77
DECLARE
88
workspace_count int;
9-
template_count int;
10-
group_count int;
11-
member_count int;
12-
provisioner_keys_count int;
9+
template_count int;
10+
group_count int;
11+
member_count int;
12+
provisioner_keys_count int;
1313
BEGIN
1414
workspace_count := (
1515
SELECT count(*) as count FROM workspaces
@@ -18,37 +18,37 @@ BEGIN
1818
AND workspaces.deleted = false
1919
);
2020

21-
template_count := (
21+
template_count := (
2222
SELECT count(*) as count FROM templates
2323
WHERE
2424
templates.organization_id = OLD.id
2525
AND templates.deleted = false
2626
);
2727

28-
group_count := (
28+
group_count := (
2929
SELECT count(*) as count FROM groups
3030
WHERE
3131
groups.organization_id = OLD.id
3232
);
3333

34-
member_count := (
34+
member_count := (
3535
SELECT count(*) as count FROM organization_members
3636
WHERE
3737
organization_members.organization_id = OLD.id
3838
);
3939

40-
provisioner_keys_count := (
41-
Select count(*) as count FROM provisioner_keys
42-
WHERE
43-
provisioner_keys.organization_id = OLD.id
44-
);
40+
provisioner_keys_count := (
41+
Select count(*) as count FROM provisioner_keys
42+
WHERE
43+
provisioner_keys.organization_id = OLD.id
44+
);
4545

4646
-- Fail the deletion if one of the following:
4747
-- * the organization has 1 or more workspaces
48-
-- * the organization has 1 or more templates
49-
-- * the organization has 1 or more groups other than "Everyone" group
50-
-- * the organization has 1 or more members other than the organization owner
51-
-- * the organization has 1 or more provisioner keys
48+
-- * the organization has 1 or more templates
49+
-- * the organization has 1 or more groups other than "Everyone" group
50+
-- * the organization has 1 or more members other than the organization owner
51+
-- * the organization has 1 or more provisioner keys
5252

5353
-- Only create error message for resources that actually exist
5454
IF (workspace_count + template_count + provisioner_keys_count) > 0 THEN
@@ -73,14 +73,14 @@ BEGIN
7373
END;
7474
END IF;
7575

76-
IF (group_count) > 1 THEN
76+
IF (group_count) > 1 THEN
7777
RAISE EXCEPTION 'cannot delete organization: organization has % groups that must be deleted first', group_count - 1;
7878
END IF;
7979

8080
-- Allow 1 member to exist, because you cannot remove yourself. You can
8181
-- remove everyone else. Ideally, we only omit the member that matches
8282
-- the user_id of the caller, however in a trigger, the caller is unknown.
83-
IF (member_count) > 1 THEN
83+
IF (member_count) > 1 THEN
8484
RAISE EXCEPTION 'cannot delete organization: organization has % members that must be deleted first', member_count - 1;
8585
END IF;
8686

@@ -92,5 +92,5 @@ $$ LANGUAGE plpgsql;
9292
CREATE TRIGGER protect_deleting_organizations
9393
BEFORE UPDATE ON organizations
9494
FOR EACH ROW
95-
WHEN (NEW.deleted = true AND OLD.deleted = false)
95+
WHEN (NEW.deleted = true AND OLD.deleted = false)
9696
EXECUTE FUNCTION protect_deleting_organizations();

0 commit comments

Comments
 (0)