Skip to content

feat: add 'display_name' column to 'workspace_agent_scripts' #14747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
692 changes: 351 additions & 341 deletions agent/proto/agent.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions agent/proto/agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ message WorkspaceAgentScript {
bool run_on_stop = 6;
bool start_blocks_login = 7;
google.protobuf.Duration timeout = 8;
string display_name = 9;
}

message WorkspaceAgentMetadata {
Expand Down
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE workspace_agent_scripts DROP COLUMN display_name;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE workspace_agent_scripts ADD COLUMN display_name text;

UPDATE workspace_agent_scripts
SET display_name = workspace_agent_log_sources.display_name
FROM workspace_agent_log_sources
WHERE workspace_agent_scripts.log_source_id = workspace_agent_log_sources.id;

ALTER TABLE workspace_agent_scripts ALTER COLUMN display_name SET NOT NULL;
1 change: 1 addition & 0 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions coderd/database/queries/workspacescripts.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- name: InsertWorkspaceAgentScripts :many
INSERT INTO
workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds)
workspace_agent_scripts (workspace_agent_id, created_at, log_source_id, log_path, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name)
SELECT
@workspace_agent_id :: uuid AS workspace_agent_id,
@created_at :: timestamptz AS created_at,
Expand All @@ -11,7 +11,8 @@ SELECT
unnest(@start_blocks_login :: boolean [ ]) AS start_blocks_login,
unnest(@run_on_start :: boolean [ ]) AS run_on_start,
unnest(@run_on_stop :: boolean [ ]) AS run_on_stop,
unnest(@timeout_seconds :: integer [ ]) AS timeout_seconds
unnest(@timeout_seconds :: integer [ ]) AS timeout_seconds,
unnest(@display_name :: text [ ]) AS display_name
RETURNING workspace_agent_scripts.*;

-- name: GetWorkspaceAgentScriptsByAgentIDs :many
Expand Down
3 changes: 3 additions & 0 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
logSourceIDs := make([]uuid.UUID, 0, len(prAgent.Scripts))
logSourceDisplayNames := make([]string, 0, len(prAgent.Scripts))
logSourceIcons := make([]string, 0, len(prAgent.Scripts))
scriptDisplayName := make([]string, 0, len(prAgent.Scripts))
scriptLogPaths := make([]string, 0, len(prAgent.Scripts))
scriptSources := make([]string, 0, len(prAgent.Scripts))
scriptCron := make([]string, 0, len(prAgent.Scripts))
Expand All @@ -1830,6 +1831,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
logSourceIDs = append(logSourceIDs, uuid.New())
logSourceDisplayNames = append(logSourceDisplayNames, script.DisplayName)
logSourceIcons = append(logSourceIcons, script.Icon)
scriptDisplayName = append(scriptDisplayName, script.DisplayName)
scriptLogPaths = append(scriptLogPaths, script.LogPath)
scriptSources = append(scriptSources, script.Script)
scriptCron = append(scriptCron, script.Cron)
Expand Down Expand Up @@ -1861,6 +1863,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
StartBlocksLogin: scriptStartBlocksLogin,
RunOnStart: scriptRunOnStart,
RunOnStop: scriptRunOnStop,
DisplayName: scriptDisplayName,
})
if err != nil {
return xerrors.Errorf("insert agent scripts: %w", err)
Expand Down
1 change: 1 addition & 0 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ func convertScripts(dbScripts []database.WorkspaceAgentScript) []codersdk.Worksp
RunOnStop: dbScript.RunOnStop,
StartBlocksLogin: dbScript.StartBlocksLogin,
Timeout: time.Duration(dbScript.TimeoutSeconds) * time.Second,
DisplayName: dbScript.DisplayName,
})
}
return scripts
Expand Down
2 changes: 2 additions & 0 deletions codersdk/agentsdk/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func AgentScriptFromProto(protoScript *proto.WorkspaceAgentScript) (codersdk.Wor
RunOnStop: protoScript.RunOnStop,
StartBlocksLogin: protoScript.StartBlocksLogin,
Timeout: protoScript.Timeout.AsDuration(),
DisplayName: protoScript.DisplayName,
}, nil
}

Expand All @@ -185,6 +186,7 @@ func ProtoFromScript(s codersdk.WorkspaceAgentScript) *proto.WorkspaceAgentScrip
RunOnStop: s.RunOnStop,
StartBlocksLogin: s.StartBlocksLogin,
Timeout: durationpb.New(s.Timeout),
DisplayName: s.DisplayName,
}
}

Expand Down
2 changes: 2 additions & 0 deletions codersdk/agentsdk/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestManifest(t *testing.T) {
RunOnStop: true,
StartBlocksLogin: true,
Timeout: time.Second,
DisplayName: "foo",
},
{
LogSourceID: uuid.New(),
Expand All @@ -124,6 +125,7 @@ func TestManifest(t *testing.T) {
RunOnStop: true,
StartBlocksLogin: true,
Timeout: time.Second * 4,
DisplayName: "bar",
},
},
}
Expand Down
1 change: 1 addition & 0 deletions codersdk/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type WorkspaceAgentScript struct {
RunOnStop bool `json:"run_on_stop"`
StartBlocksLogin bool `json:"start_blocks_login"`
Timeout time.Duration `json:"timeout"`
DisplayName string `json:"display_name"`
}

type WorkspaceAgentHealth struct {
Expand Down
1 change: 1 addition & 0 deletions docs/reference/api/agents.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions docs/reference/api/builds.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions docs/reference/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading