Skip to content

Commit b523d15

Browse files
committed
fix
1 parent 1c32689 commit b523d15

37 files changed

+549
-560
lines changed

components/common-go/db/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the GNU Affero General Public License (AGPL).
33
// See License-AGPL.txt in the project root for license information.
44

5-
package common_db
5+
package db
66

77
import (
88
"fmt"

components/common-go/db/cost_center.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the GNU Affero General Public License (AGPL).
33
// See License-AGPL.txt in the project root for license information.
44

5-
package common_db
5+
package db
66

77
import (
88
"context"

components/common-go/db/cost_center_test.go

Lines changed: 121 additions & 121 deletions
Large diffs are not rendered by default.

components/common-go/db/dbtest/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"sync"
99
"testing"
1010

11-
common_db "github.com/gitpod-io/gitpod/common-go/db"
11+
"github.com/gitpod-io/gitpod/common-go/db"
1212
"github.com/stretchr/testify/require"
1313
"gorm.io/gorm"
1414
)
@@ -31,13 +31,13 @@ func ConnectForTests(t *testing.T) *gorm.DB {
3131
// These are static connection details for tests, started by `leeway components/usage:init-testdb`.
3232
// We use the same static credentials for CI & local instance of MySQL Server.
3333
var err error
34-
conn, err = common_db.Connect(common_db.ConnectionParams{
34+
conn, err = db.Connect(db.ConnectionParams{
3535
User: "root",
3636
Password: "test",
3737
Host: "localhost:23306",
3838
Database: "gitpod",
3939
})
40-
require.NoError(t, err, "Failed to establish connection to DB. In a workspace, run `leeway build components/common-go:init-testdb` once to bootstrap the common_db.")
40+
require.NoError(t, err, "Failed to establish connection to DB. In a workspace, run `leeway build components/common-go:init-testdb` once to bootstrap the db.")
4141

4242
return conn
4343
}

components/common-go/db/dbtest/cost_center.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ import (
88
"testing"
99
"time"
1010

11-
common_db "github.com/gitpod-io/gitpod/common-go/db"
11+
"github.com/gitpod-io/gitpod/common-go/db"
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/require"
1414
"gorm.io/gorm"
1515
)
1616

17-
func NewCostCenter(t *testing.T, record common_db.CostCenter) common_db.CostCenter {
17+
func NewCostCenter(t *testing.T, record db.CostCenter) db.CostCenter {
1818
t.Helper()
1919

20-
result := common_db.CostCenter{
21-
ID: common_db.NewUserAttributionID(uuid.New().String()),
22-
CreationTime: common_db.NewVarCharTime(time.Now()),
20+
result := db.CostCenter{
21+
ID: db.NewUserAttributionID(uuid.New().String()),
22+
CreationTime: db.NewVarCharTime(time.Now()),
2323
SpendingLimit: 100,
24-
BillingStrategy: common_db.CostCenter_Stripe,
25-
BillingCycleStart: common_db.NewVarCharTime(time.Now()),
26-
NextBillingTime: common_db.NewVarCharTime(time.Now().Add(10 * time.Hour)),
24+
BillingStrategy: db.CostCenter_Stripe,
25+
BillingCycleStart: db.NewVarCharTime(time.Now()),
26+
NextBillingTime: db.NewVarCharTime(time.Now().Add(10 * time.Hour)),
2727
}
2828

2929
if record.ID != "" {
@@ -45,10 +45,10 @@ func NewCostCenter(t *testing.T, record common_db.CostCenter) common_db.CostCent
4545
return result
4646
}
4747

48-
func CreateCostCenters(t *testing.T, conn *gorm.DB, entries ...common_db.CostCenter) []common_db.CostCenter {
48+
func CreateCostCenters(t *testing.T, conn *gorm.DB, entries ...db.CostCenter) []db.CostCenter {
4949
t.Helper()
5050

51-
var records []common_db.CostCenter
51+
var records []db.CostCenter
5252
var ids []string
5353
for _, entry := range entries {
5454
record := NewCostCenter(t, entry)
@@ -60,7 +60,7 @@ func CreateCostCenters(t *testing.T, conn *gorm.DB, entries ...common_db.CostCen
6060
require.NoError(t, tx.Error)
6161
t.Cleanup(func() {
6262
if len(ids) > 0 {
63-
require.NoError(t, conn.Where(ids).Delete(&common_db.CostCenter{}).Error)
63+
require.NoError(t, conn.Where(ids).Delete(&db.CostCenter{}).Error)
6464
}
6565
})
6666

components/common-go/db/dbtest/stripe_customer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import (
99
"testing"
1010
"time"
1111

12-
common_db "github.com/gitpod-io/gitpod/common-go/db"
12+
"github.com/gitpod-io/gitpod/common-go/db"
1313
"github.com/google/uuid"
1414
"github.com/stretchr/testify/require"
1515
"gorm.io/gorm"
1616
)
1717

18-
func NewStripeCustomer(t *testing.T, customer common_db.StripeCustomer) common_db.StripeCustomer {
18+
func NewStripeCustomer(t *testing.T, customer db.StripeCustomer) db.StripeCustomer {
1919
t.Helper()
2020

21-
result := common_db.StripeCustomer{
21+
result := db.StripeCustomer{
2222
StripeCustomerID: fmt.Sprintf("cus_%s", uuid.New().String()),
23-
AttributionID: common_db.NewUserAttributionID(uuid.New().String()),
24-
CreationTime: common_db.NewVarCharTime(time.Now()),
23+
AttributionID: db.NewUserAttributionID(uuid.New().String()),
24+
CreationTime: db.NewVarCharTime(time.Now()),
2525
}
2626

2727
if customer.StripeCustomerID != "" {
@@ -38,10 +38,10 @@ func NewStripeCustomer(t *testing.T, customer common_db.StripeCustomer) common_d
3838
return result
3939
}
4040

41-
func CreateStripeCustomers(t *testing.T, conn *gorm.DB, customers ...common_db.StripeCustomer) []common_db.StripeCustomer {
41+
func CreateStripeCustomers(t *testing.T, conn *gorm.DB, customers ...db.StripeCustomer) []db.StripeCustomer {
4242
t.Helper()
4343

44-
var records []common_db.StripeCustomer
44+
var records []db.StripeCustomer
4545
var ids []string
4646
for _, c := range customers {
4747
record := NewStripeCustomer(t, c)
@@ -52,7 +52,7 @@ func CreateStripeCustomers(t *testing.T, conn *gorm.DB, customers ...common_db.S
5252
require.NoError(t, conn.CreateInBatches(&records, 1000).Error)
5353

5454
t.Cleanup(func() {
55-
require.NoError(t, conn.Where(ids).Delete(&common_db.StripeCustomer{}).Error)
55+
require.NoError(t, conn.Where(ids).Delete(&db.StripeCustomer{}).Error)
5656
})
5757

5858
return records

components/common-go/db/dbtest/usage.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import (
88
"context"
99
"testing"
1010

11-
common_db "github.com/gitpod-io/gitpod/common-go/db"
11+
"github.com/gitpod-io/gitpod/common-go/db"
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/require"
1414
"gorm.io/gorm"
1515
)
1616

17-
func NewUsage(t *testing.T, record common_db.Usage) common_db.Usage {
17+
func NewUsage(t *testing.T, record db.Usage) db.Usage {
1818
t.Helper()
1919

2020
workspaceInstanceId := uuid.New()
2121

22-
result := common_db.Usage{
22+
result := db.Usage{
2323
ID: uuid.New(),
24-
AttributionID: common_db.NewUserAttributionID(uuid.New().String()),
24+
AttributionID: db.NewUserAttributionID(uuid.New().String()),
2525
Description: "some description",
2626
CreditCents: 42,
27-
EffectiveTime: common_db.VarcharTime{},
28-
Kind: common_db.WorkspaceInstanceUsageKind,
27+
EffectiveTime: db.VarcharTime{},
28+
Kind: db.WorkspaceInstanceUsageKind,
2929
WorkspaceInstanceID: &workspaceInstanceId,
3030
}
3131

@@ -59,21 +59,21 @@ func NewUsage(t *testing.T, record common_db.Usage) common_db.Usage {
5959
return result
6060
}
6161

62-
func CreateUsageRecords(t *testing.T, conn *gorm.DB, entries ...common_db.Usage) []common_db.Usage {
62+
func CreateUsageRecords(t *testing.T, conn *gorm.DB, entries ...db.Usage) []db.Usage {
6363
t.Helper()
6464

65-
var records []common_db.Usage
65+
var records []db.Usage
6666
var ids []string
6767
for _, usageEntry := range entries {
6868
record := NewUsage(t, usageEntry)
6969
records = append(records, record)
7070
ids = append(ids, record.ID.String())
7171
}
7272

73-
require.NoError(t, common_db.InsertUsage(context.Background(), conn, entries...))
73+
require.NoError(t, db.InsertUsage(context.Background(), conn, entries...))
7474
t.Cleanup(func() {
7575
if len(ids) > 0 {
76-
require.NoError(t, conn.Where(ids).Delete(&common_db.Usage{}).Error)
76+
require.NoError(t, conn.Where(ids).Delete(&db.Usage{}).Error)
7777
}
7878
})
7979

components/common-go/db/dbtest/user.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import (
88
"testing"
99
"time"
1010

11-
common_db "github.com/gitpod-io/gitpod/common-go/db"
11+
"github.com/gitpod-io/gitpod/common-go/db"
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/require"
1414
"gorm.io/gorm"
1515
)
1616

1717
type User struct {
18-
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;"`
19-
AvatarURL string `gorm:"column:avatarUrl;type:char;size:255;"`
20-
Name string `gorm:"column:name;type:char;size:255;"`
21-
FullName string `gorm:"column:fullName;type:char;size:255;"`
22-
CreationDate common_db.VarcharTime `gorm:"column:creationDate;type:varchar;size:255;"`
18+
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;"`
19+
AvatarURL string `gorm:"column:avatarUrl;type:char;size:255;"`
20+
Name string `gorm:"column:name;type:char;size:255;"`
21+
FullName string `gorm:"column:fullName;type:char;size:255;"`
22+
CreationDate db.VarcharTime `gorm:"column:creationDate;type:varchar;size:255;"`
2323

2424
// user has more field but we don't care here as they are just used in tests.
2525
}
@@ -36,7 +36,7 @@ func NewUser(t *testing.T, user User) User {
3636
AvatarURL: "https://avatars.githubusercontent.com/u/9071",
3737
Name: "HomerJSimpson",
3838
FullName: "Homer Simpson",
39-
CreationDate: common_db.NewVarCharTime(time.Now()),
39+
CreationDate: db.NewVarCharTime(time.Now()),
4040
}
4141

4242
if user.ID != uuid.Nil {

components/common-go/db/dbtest/workspace.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"database/sql"
99
"testing"
1010

11-
common_db "github.com/gitpod-io/gitpod/common-go/db"
11+
"github.com/gitpod-io/gitpod/common-go/db"
1212
"github.com/gitpod-io/gitpod/common-go/namegen"
1313
"github.com/google/uuid"
1414
"github.com/stretchr/testify/require"
@@ -21,9 +21,9 @@ const (
2121
)
2222

2323
// NewWorkspace creates a new stub workspace with default values, unless these are set on the workspace argument
24-
// Records are not stored, use `common_db.Create(dbtest.NewWorkspace(t, common_db.Workspace{})) to store it.
24+
// Records are not stored, use `db.Create(dbtest.NewWorkspace(t, db.Workspace{})) to store it.
2525
// Only used for tests. Additional default properties may be added in the future.
26-
func NewWorkspace(t *testing.T, workspace common_db.Workspace) common_db.Workspace {
26+
func NewWorkspace(t *testing.T, workspace db.Workspace) db.Workspace {
2727
t.Helper()
2828

2929
id := GenerateWorkspaceID()
@@ -44,7 +44,7 @@ func NewWorkspace(t *testing.T, workspace common_db.Workspace) common_db.Workspa
4444
projectID = workspace.ProjectID
4545
}
4646

47-
workspaceType := common_db.WorkspaceType_Regular
47+
workspaceType := db.WorkspaceType_Regular
4848
if workspace.Type != "" {
4949
workspaceType = workspace.Type
5050
}
@@ -64,7 +64,7 @@ func NewWorkspace(t *testing.T, workspace common_db.Workspace) common_db.Workspa
6464
config = workspace.Config
6565
}
6666

67-
return common_db.Workspace{
67+
return db.Workspace{
6868
ID: id,
6969
OwnerID: ownerID,
7070
Type: workspaceType,
@@ -80,10 +80,10 @@ func GenerateWorkspaceID() string {
8080
return id
8181
}
8282

83-
func CreateWorkspaces(t *testing.T, conn *gorm.DB, workspaces ...common_db.Workspace) []common_db.Workspace {
83+
func CreateWorkspaces(t *testing.T, conn *gorm.DB, workspaces ...db.Workspace) []db.Workspace {
8484
t.Helper()
8585

86-
var records []common_db.Workspace
86+
var records []db.Workspace
8787
var ids []string
8888
for _, w := range workspaces {
8989
record := NewWorkspace(t, w)
@@ -94,7 +94,7 @@ func CreateWorkspaces(t *testing.T, conn *gorm.DB, workspaces ...common_db.Works
9494
require.NoError(t, conn.CreateInBatches(&records, 1000).Error)
9595

9696
t.Cleanup(func() {
97-
require.NoError(t, conn.Where(ids).Delete(&common_db.Workspace{}).Error)
97+
require.NoError(t, conn.Where(ids).Delete(&db.Workspace{}).Error)
9898
})
9999

100100
return records

0 commit comments

Comments
 (0)