chore(coderd/database): enforce agent name unique within workspace build (#18052)

Adds a database trigger that runs on insert and update of the
`workspace_agents` table. The trigger ensures that the agent name is
unique within the context of the workspace build it is being inserted
into.
This commit is contained in:
Danielle Maywood
2025-05-28 14:21:17 +01:00
committed by GitHub
parent 110102a60a
commit 6e255c72c6
5 changed files with 328 additions and 4 deletions

View File

@ -609,8 +609,8 @@ func TestTemplateInsights_Golden(t *testing.T) {
Name: "example",
Type: "aws_instance",
Agents: []*proto.Agent{{
Id: uuid.NewString(), // Doesn't matter, not used in DB.
Name: "dev",
Id: uuid.NewString(), // Doesn't matter, not used in DB.
Name: fmt.Sprintf("dev-%d", len(resources)), // Ensure unique name per agent
Auth: &proto.Agent_Token{
Token: authToken.String(),
},
@ -1525,8 +1525,8 @@ func TestUserActivityInsights_Golden(t *testing.T) {
Name: "example",
Type: "aws_instance",
Agents: []*proto.Agent{{
Id: uuid.NewString(), // Doesn't matter, not used in DB.
Name: "dev",
Id: uuid.NewString(), // Doesn't matter, not used in DB.
Name: fmt.Sprintf("dev-%d", len(resources)), // Ensure unique name per agent
Auth: &proto.Agent_Token{
Token: authToken.String(),
},