Skip to content

Commit ce2d00d

Browse files
easyCZroboquat
authored andcommitted
[usage] Extend go model with extra fields for WorkspaceInstanceUsage
1 parent d5987af commit ce2d00d

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

components/usage/pkg/apiv1/usage_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func TestUsageService_ListBilledUsage(t *testing.T) {
4747
StartedAt: startedAt.AsTime(),
4848
StoppedAt: sql.NullTime{},
4949
CreditsUsed: 0,
50-
GenerationId: 0,
51-
Deleted: false,
50+
GenerationID: 0,
5251
},
5352
}
5453
dbtest.CreateWorkspaceInstanceUsageRecords(t, dbconn, instanceUsages...)

components/usage/pkg/controller/reconciler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ func usageReportToUsageRecords(report UsageReport, pricer *WorkspacePricer, now
250250
StartedAt: instance.CreationTime.Time(),
251251
StoppedAt: stoppedAt,
252252
CreditsUsed: pricer.CreditsUsedByInstance(&instance, now),
253-
GenerationId: 0,
254-
Deleted: false,
253+
GenerationID: 0,
255254
})
256255
}
257256
}

components/usage/pkg/controller/reconciler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func TestUsageReportConversionToDBUsageRecords(t *testing.T) {
180180
StartedAt: creationTime.Time(),
181181
StoppedAt: sql.NullTime{Time: stoppedTime.Time(), Valid: true},
182182
CreditsUsed: 470,
183-
GenerationId: 0,
184183
}},
185184
},
186185
{
@@ -202,7 +201,6 @@ func TestUsageReportConversionToDBUsageRecords(t *testing.T) {
202201
StartedAt: creationTime.Time(),
203202
StoppedAt: sql.NullTime{},
204203
CreditsUsed: 470,
205-
GenerationId: 0,
206204
}},
207205
},
208206
}

components/usage/pkg/db/workspace_instance_usage.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ import (
1818
type WorkspaceInstanceUsage struct {
1919
InstanceID uuid.UUID `gorm:"primary_key;column:instanceId;type:char;size:36;" json:"instanceId"`
2020
AttributionID AttributionID `gorm:"column:attributionId;type:varchar;size:255;" json:"attributionId"`
21-
StartedAt time.Time `gorm:"column:startedAt;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"startedAt"`
22-
StoppedAt sql.NullTime `gorm:"column:stoppedAt;type:timestamp;" json:"stoppedAt"`
23-
CreditsUsed float64 `gorm:"column:creditsUsed;type:double;" json:"creditsUsed"`
24-
GenerationId int `gorm:"column:generationId;type:int;" json:"generationId"`
25-
Deleted bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
21+
22+
UserID string `gorm:"column:userId;type:varchar;size:255;" json:"userId"`
23+
WorkspaceID string `gorm:"column:workspaceId;type:varchar;size:255;" json:"workspaceId"`
24+
ProjectID string `gorm:"column:projectId;type:varchar;size:255;" json:"projectId"`
25+
WorkspaceType WorkspaceType `gorm:"column:workspaceType;type:varchar;size:255;" json:"workspaceType"`
26+
WorkspaceClass string `gorm:"column:workspaceClass;type:varchar;size:255;" json:"workspaceClass"`
27+
28+
CreditsUsed float64 `gorm:"column:creditsUsed;type:double;" json:"creditsUsed"`
29+
30+
StartedAt time.Time `gorm:"column:startedAt;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"startedAt"`
31+
StoppedAt sql.NullTime `gorm:"column:stoppedAt;type:timestamp;" json:"stoppedAt"`
32+
33+
GenerationID int `gorm:"column:generationId;type:int;" json:"generationId"`
34+
35+
// deleted is used by db-sync
36+
Deleted bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"`
2637
}
2738

2839
// TableName sets the insert table name for this struct type

components/usage/pkg/db/workspace_instance_usage_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func TestCanCreateUsageRecords(t *testing.T) {
3434
StartedAt: time.Now(),
3535
StoppedAt: sql.NullTime{},
3636
CreditsUsed: 0,
37-
GenerationId: 0,
38-
Deleted: false,
37+
GenerationID: 0,
3938
}},
4039
},
4140
}
@@ -72,17 +71,15 @@ func TestNoErrorOnCreatingDuplicateRecords(t *testing.T) {
7271
StartedAt: instanceStartTime,
7372
StoppedAt: sql.NullTime{},
7473
CreditsUsed: 0,
75-
GenerationId: 0,
76-
Deleted: false,
74+
GenerationID: 0,
7775
},
7876
{
7977
InstanceID: instanceID,
8078
AttributionID: teamAttributionID,
8179
StartedAt: instanceStartTime,
8280
StoppedAt: sql.NullTime{},
8381
CreditsUsed: 0,
84-
GenerationId: 0,
85-
Deleted: false,
82+
GenerationID: 0,
8683
},
8784
},
8885
},

0 commit comments

Comments
 (0)