Skip to content

Commit 4715a2f

Browse files
committed
[usage] Add usageAttributionID to WorksapceInstance model (in go)
1 parent f28ba51 commit 4715a2f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

components/usage/pkg/db/workspace_instance.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/google/uuid"
1212
"gorm.io/datatypes"
1313
"gorm.io/gorm"
14+
"strings"
1415
"time"
1516
)
1617

@@ -23,6 +24,7 @@ type WorkspaceInstance struct {
2324
IdeURL string `gorm:"column:ideUrl;type:varchar;size:255;" json:"ideUrl"`
2425
WorkspaceBaseImage string `gorm:"column:workspaceBaseImage;type:varchar;size:255;" json:"workspaceBaseImage"`
2526
WorkspaceImage string `gorm:"column:workspaceImage;type:varchar;size:255;" json:"workspaceImage"`
27+
UsageAttributionID string `gorm:"column:usageAttributionId;type:varchar;size:60;" json:"usageAttributionId"`
2628

2729
CreationTime VarcharTime `gorm:"column:creationTime;type:varchar;size:255;" json:"creationTime"`
2830
StartedTime VarcharTime `gorm:"column:startedTime;type:varchar;size:255;" json:"startedTime"`
@@ -87,3 +89,16 @@ func ListWorkspaceInstancesInRange(ctx context.Context, conn *gorm.DB, from, to
8789

8890
return instances, nil
8991
}
92+
93+
// AttributionID consists of an entity, and an identifier in the form:
94+
// <entity>:<identifier>, e.g. team:a7dcf253-f05e-4dcf-9a47-cf8fccc74717
95+
type AttributionID string
96+
97+
func (a AttributionID) Values() (entity string, identifier string) {
98+
tokens := strings.Split(string(a), ":")
99+
if len(tokens) != 2 {
100+
return "", ""
101+
}
102+
103+
return tokens[0], tokens[1]
104+
}

0 commit comments

Comments
 (0)