Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb568aa7

Browse files
stirbybrettkolodnyDanielleMaywoodEmyrk
authored
chore: cherry pick migrations for release 2.22 (#17873)
Co-authored-by: brettkolodny <brettkolodny@gmail.com>Co-authored-by: Danielle Maywood <danielle@themaywoods.com>Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
1 parent4a70bdc commitb568aa7

File tree

40 files changed

+720
-42
lines changed

40 files changed

+720
-42
lines changed

‎coderd/apidoc/docs.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func WorkspaceAgentPortShare(t testing.TB, db database.Store, orig database.Work
157157
funcWorkspaceAgent(t testing.TB,db database.Store,orig database.WorkspaceAgent) database.WorkspaceAgent {
158158
agt,err:=db.InsertWorkspaceAgent(genCtx, database.InsertWorkspaceAgentParams{
159159
ID:takeFirst(orig.ID,uuid.New()),
160+
ParentID:takeFirst(orig.ParentID, uuid.NullUUID{}),
160161
CreatedAt:takeFirst(orig.CreatedAt,dbtime.Now()),
161162
UpdatedAt:takeFirst(orig.UpdatedAt,dbtime.Now()),
162163
Name:takeFirst(orig.Name,testutil.GetRandomName(t)),

‎coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9477,6 +9477,7 @@ func (q *FakeQuerier) InsertWorkspaceAgent(_ context.Context, arg database.Inser
94779477

94789478
agent:= database.WorkspaceAgent{
94799479
ID:arg.ID,
9480+
ParentID:arg.ParentID,
94809481
CreatedAt:arg.CreatedAt,
94819482
UpdatedAt:arg.UpdatedAt,
94829483
ResourceID:arg.ResourceID,

‎coderd/database/dump.sql

Lines changed: 58 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/foreign_key_constraint.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
DROPTRIGGER IF EXISTS protect_deleting_organizationsON organizations;
2+
3+
-- Replace the function with the new implementation
4+
CREATE OR REPLACEFUNCTIONprotect_deleting_organizations()
5+
RETURNS TRIGGERAS
6+
$$
7+
DECLARE
8+
workspace_countint;
9+
template_countint;
10+
group_countint;
11+
member_countint;
12+
provisioner_keys_countint;
13+
BEGIN
14+
workspace_count := (
15+
SELECTcount(*)as countFROM workspaces
16+
WHERE
17+
workspaces.organization_id=OLD.id
18+
ANDworkspaces.deleted= false
19+
);
20+
21+
template_count := (
22+
SELECTcount(*)as countFROM templates
23+
WHERE
24+
templates.organization_id=OLD.id
25+
ANDtemplates.deleted= false
26+
);
27+
28+
group_count := (
29+
SELECTcount(*)as countFROM groups
30+
WHERE
31+
groups.organization_id=OLD.id
32+
);
33+
34+
member_count := (
35+
SELECTcount(*)as countFROM organization_members
36+
WHERE
37+
organization_members.organization_id=OLD.id
38+
);
39+
40+
provisioner_keys_count := (
41+
Selectcount(*)as countFROM provisioner_keys
42+
WHERE
43+
provisioner_keys.organization_id=OLD.id
44+
);
45+
46+
-- Fail the deletion if one of the following:
47+
-- * 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
52+
53+
-- Only create error message for resources that actually exist
54+
IF (workspace_count+ template_count+ provisioner_keys_count)>0 THEN
55+
DECLARE
56+
error_messagetext :='cannot delete organization: organization has';
57+
error_partstext[] :='{}';
58+
BEGIN
59+
IF workspace_count>0 THEN
60+
error_parts := array_append(error_parts, workspace_count||' workspaces');
61+
END IF;
62+
63+
IF template_count>0 THEN
64+
error_parts := array_append(error_parts, template_count||' templates');
65+
END IF;
66+
67+
IF provisioner_keys_count>0 THEN
68+
error_parts := array_append(error_parts, provisioner_keys_count||' provisioner keys');
69+
END IF;
70+
71+
error_message := error_message|| array_to_string(error_parts,',')||' that must be deleted first';
72+
RAISE EXCEPTION'%', error_message;
73+
END;
74+
END IF;
75+
76+
IF (group_count)>1 THEN
77+
RAISE EXCEPTION'cannot delete organization: organization has % groups that must be deleted first', group_count-1;
78+
END IF;
79+
80+
-- Allow 1 member to exist, because you cannot remove yourself. You can
81+
-- remove everyone else. Ideally, we only omit the member that matches
82+
-- the user_id of the caller, however in a trigger, the caller is unknown.
83+
IF (member_count)>1 THEN
84+
RAISE EXCEPTION'cannot delete organization: organization has % members that must be deleted first', member_count-1;
85+
END IF;
86+
87+
RETURN NEW;
88+
END;
89+
$$ LANGUAGE plpgsql;
90+
91+
-- Trigger to protect organizations from being soft deleted with existing resources
92+
CREATETRIGGERprotect_deleting_organizations
93+
BEFOREUPDATEON organizations
94+
FOR EACH ROW
95+
WHEN (NEW.deleted= trueANDOLD.deleted= false)
96+
EXECUTE FUNCTION protect_deleting_organizations();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp