Skip to content

Commit 5e8b150

Browse files
mtojekmafredri
authored andcommitted
Implement database model
1 parent 5455c58 commit 5e8b150

19 files changed

+77
-11
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dbfake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,6 +2856,7 @@ func (q *fakeQuerier) InsertWorkspaceAgent(_ context.Context, arg database.Inser
28562856
TroubleshootingURL: arg.TroubleshootingURL,
28572857
MOTDFile: arg.MOTDFile,
28582858
LifecycleState: database.WorkspaceAgentLifecycleStateCreated,
2859+
ShutdownScript: arg.ShutdownScript,
28592860
}
28602861

28612862
q.workspaceAgents = append(q.workspaceAgents, agent)

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE workspace_agents DROP COLUMN shutdown_script;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE workspace_agents ADD COLUMN shutdown_script varchar(65534);
2+
3+
COMMENT ON COLUMN workspace_agents.shutdown_script IS 'Script that is executed before the agent is stopped.';

coderd/database/models.go

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

coderd/database/queries.sql.go

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceagents.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ INSERT INTO
5858
troubleshooting_url,
5959
motd_file,
6060
login_before_ready,
61-
startup_script_timeout_seconds
61+
startup_script_timeout_seconds,
62+
shutdown_script
6263
)
6364
VALUES
64-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) RETURNING *;
65+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) RETURNING *;
6566

6667
-- name: UpdateWorkspaceAgentConnectionByID :exec
6768
UPDATE

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
11441144
MOTDFile: prAgent.GetMotdFile(),
11451145
LoginBeforeReady: prAgent.GetLoginBeforeReady(),
11461146
StartupScriptTimeoutSeconds: prAgent.GetStartupScriptTimeoutSeconds(),
1147+
ShutdownScript: sql.NullString{
1148+
String: prAgent.ShutdownScript,
1149+
Valid: prAgent.ShutdownScript != "",
1150+
},
11471151
})
11481152
if err != nil {
11491153
return xerrors.Errorf("insert agent: %w", err)

coderd/workspaceagents.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
153153
VSCodePortProxyURI: vscodeProxyURI,
154154
MOTDFile: workspaceAgent.MOTDFile,
155155
StartupScriptTimeout: time.Duration(apiAgent.StartupScriptTimeoutSeconds) * time.Second,
156+
ShutdownScript: apiAgent.ShutdownScript,
156157
})
157158
}
158159

codersdk/agentsdk/agentsdk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Metadata struct {
7878
StartupScriptTimeout time.Duration `json:"startup_script_timeout"`
7979
Directory string `json:"directory"`
8080
MOTDFile string `json:"motd_file"`
81+
ShutdownScript string `json:"shutdown_script"`
8182
}
8283

8384
// Metadata fetches metadata for the currently authenticated workspace agent.

codersdk/workspaceagents.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ type WorkspaceAgent struct {
7878
// LoginBeforeReady if true, the agent will delay logins until it is ready (e.g. executing startup script has ended).
7979
LoginBeforeReady bool `db:"login_before_ready" json:"login_before_ready"`
8080
// StartupScriptTimeoutSeconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout.
81-
StartupScriptTimeoutSeconds int32 `db:"startup_script_timeout_seconds" json:"startup_script_timeout_seconds"`
81+
StartupScriptTimeoutSeconds int32 `db:"startup_script_timeout_seconds" json:"startup_script_timeout_seconds"`
82+
ShutdownScript string `json:"shutdown_script,omitempty"`
8283
}
8384

8485
type DERPRegion struct {

docs/api/agents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/me/metadata \
369369
},
370370
"git_auth_configs": 0,
371371
"motd_file": "string",
372+
"shutdown_script": "string",
372373
"startup_script": "string",
373374
"startup_script_timeout": 0,
374375
"vscode_port_proxy_uri": "string"
@@ -515,6 +516,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent} \
515516
"name": "string",
516517
"operating_system": "string",
517518
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
519+
"shutdown_script": "string",
518520
"startup_script": "string",
519521
"startup_script_timeout_seconds": 0,
520522
"status": "connecting",

0 commit comments

Comments
 (0)