mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: add 'display_name' column to 'workspace_agent_scripts' (#14747)
* feat: add 'display_name' column to 'workspace_agent_scripts' * fix: backfill from workspace_agent_log_sources * fix: run 'make gen'
This commit is contained in:
3
coderd/apidoc/docs.go
generated
3
coderd/apidoc/docs.go
generated
@ -14260,6 +14260,9 @@ const docTemplate = `{
|
||||
"cron": {
|
||||
"type": "string"
|
||||
},
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"log_path": {
|
||||
"type": "string"
|
||||
},
|
||||
|
3
coderd/apidoc/swagger.json
generated
3
coderd/apidoc/swagger.json
generated
@ -12986,6 +12986,9 @@
|
||||
"cron": {
|
||||
"type": "string"
|
||||
},
|
||||
"display_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"log_path": {
|
||||
"type": "string"
|
||||
},
|
||||
|
3
coderd/database/dump.sql
generated
3
coderd/database/dump.sql
generated
@ -1365,7 +1365,8 @@ CREATE TABLE workspace_agent_scripts (
|
||||
start_blocks_login boolean NOT NULL,
|
||||
run_on_start boolean NOT NULL,
|
||||
run_on_stop boolean NOT NULL,
|
||||
timeout_seconds integer NOT NULL
|
||||
timeout_seconds integer NOT NULL,
|
||||
display_name text NOT NULL
|
||||
);
|
||||
|
||||
CREATE SEQUENCE workspace_agent_startup_logs_id_seq
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE workspace_agent_scripts DROP COLUMN display_name;
|
@ -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;
|
@ -2880,6 +2880,7 @@ type WorkspaceAgentScript struct {
|
||||
RunOnStart bool `db:"run_on_start" json:"run_on_start"`
|
||||
RunOnStop bool `db:"run_on_stop" json:"run_on_stop"`
|
||||
TimeoutSeconds int32 `db:"timeout_seconds" json:"timeout_seconds"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
}
|
||||
|
||||
type WorkspaceAgentStat struct {
|
||||
|
@ -15492,7 +15492,7 @@ func (q *sqlQuerier) UpdateWorkspacesDormantDeletingAtByTemplateID(ctx context.C
|
||||
}
|
||||
|
||||
const getWorkspaceAgentScriptsByAgentIDs = `-- name: GetWorkspaceAgentScriptsByAgentIDs :many
|
||||
SELECT workspace_agent_id, log_source_id, log_path, created_at, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds FROM workspace_agent_scripts WHERE workspace_agent_id = ANY($1 :: uuid [ ])
|
||||
SELECT workspace_agent_id, log_source_id, log_path, created_at, script, cron, start_blocks_login, run_on_start, run_on_stop, timeout_seconds, display_name FROM workspace_agent_scripts WHERE workspace_agent_id = ANY($1 :: uuid [ ])
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetWorkspaceAgentScriptsByAgentIDs(ctx context.Context, ids []uuid.UUID) ([]WorkspaceAgentScript, error) {
|
||||
@ -15515,6 +15515,7 @@ func (q *sqlQuerier) GetWorkspaceAgentScriptsByAgentIDs(ctx context.Context, ids
|
||||
&i.RunOnStart,
|
||||
&i.RunOnStop,
|
||||
&i.TimeoutSeconds,
|
||||
&i.DisplayName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -15531,7 +15532,7 @@ func (q *sqlQuerier) GetWorkspaceAgentScriptsByAgentIDs(ctx context.Context, ids
|
||||
|
||||
const insertWorkspaceAgentScripts = `-- 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
|
||||
$1 :: uuid AS workspace_agent_id,
|
||||
$2 :: timestamptz AS created_at,
|
||||
@ -15542,8 +15543,9 @@ SELECT
|
||||
unnest($7 :: boolean [ ]) AS start_blocks_login,
|
||||
unnest($8 :: boolean [ ]) AS run_on_start,
|
||||
unnest($9 :: boolean [ ]) AS run_on_stop,
|
||||
unnest($10 :: integer [ ]) AS timeout_seconds
|
||||
RETURNING workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds
|
||||
unnest($10 :: integer [ ]) AS timeout_seconds,
|
||||
unnest($11 :: text [ ]) AS display_name
|
||||
RETURNING workspace_agent_scripts.workspace_agent_id, workspace_agent_scripts.log_source_id, workspace_agent_scripts.log_path, workspace_agent_scripts.created_at, workspace_agent_scripts.script, workspace_agent_scripts.cron, workspace_agent_scripts.start_blocks_login, workspace_agent_scripts.run_on_start, workspace_agent_scripts.run_on_stop, workspace_agent_scripts.timeout_seconds, workspace_agent_scripts.display_name
|
||||
`
|
||||
|
||||
type InsertWorkspaceAgentScriptsParams struct {
|
||||
@ -15557,6 +15559,7 @@ type InsertWorkspaceAgentScriptsParams struct {
|
||||
RunOnStart []bool `db:"run_on_start" json:"run_on_start"`
|
||||
RunOnStop []bool `db:"run_on_stop" json:"run_on_stop"`
|
||||
TimeoutSeconds []int32 `db:"timeout_seconds" json:"timeout_seconds"`
|
||||
DisplayName []string `db:"display_name" json:"display_name"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg InsertWorkspaceAgentScriptsParams) ([]WorkspaceAgentScript, error) {
|
||||
@ -15571,6 +15574,7 @@ func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg Insert
|
||||
pq.Array(arg.RunOnStart),
|
||||
pq.Array(arg.RunOnStop),
|
||||
pq.Array(arg.TimeoutSeconds),
|
||||
pq.Array(arg.DisplayName),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -15590,6 +15594,7 @@ func (q *sqlQuerier) InsertWorkspaceAgentScripts(ctx context.Context, arg Insert
|
||||
&i.RunOnStart,
|
||||
&i.RunOnStop,
|
||||
&i.TimeoutSeconds,
|
||||
&i.DisplayName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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
|
||||
|
@ -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))
|
||||
@ -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)
|
||||
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user