-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 25 additions & 8 deletions
33
components/usage/pkg/db/team_membership.go
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package db | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"time" | ||
) | ||
|
||
type TeamMembership struct { | ||
ID string `gorm:"primary_key;column:id;type:char;size:36;" json:"id"` | ||
TeamID string `gorm:"column:teamId;type:char;size:36;" json:"team_id"` | ||
UserID string `gorm:"column:userId;type:char;size:36;" json:"user_id"` | ||
Role string `gorm:"column:role;type:varchar;size:255;" json:"role"` | ||
CreationTime string `gorm:"column:creationTime;type:varchar;size:255;" json:"creation_time"` | ||
Deleted bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"` | ||
LastModified time.Time `gorm:"column:_lastModified;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"_last_modified"` | ||
SubscriptionID string `gorm:"column:subscriptionId;type:char;size:36;" json:"subscription_id"` | ||
ID uuid.UUID `gorm:"primary_key;column:id;type:char;size:36;" json:"id"` | ||
|
||
TeamID uuid.UUID `gorm:"column:teamId;type:char;size:36;" json:"teamId"` | ||
UserID uuid.UUID `gorm:"column:userId;type:char;size:36;" json:"userId"` | ||
Role TeamMembershipRole `gorm:"column:role;type:varchar;size:255;" json:"role"` | ||
SubscriptionID uuid.UUID `gorm:"column:subscriptionId;type:char;size:36;" json:"subscriptionId"` | ||
|
||
CreationTime VarcharTime `gorm:"column:creationTime;type:varchar;size:255;" json:"creationTime"` | ||
// Read-only (-> property). | ||
LastModified time.Time `gorm:"->:column:_lastModified;type:timestamp;default:CURRENT_TIMESTAMP(6);" json:"_lastModified"` | ||
|
||
// deleted column is reserved for use by db-sync | ||
_ bool `gorm:"column:deleted;type:tinyint;default:0;" json:"deleted"` | ||
} | ||
|
||
// TableName sets the insert table name for this struct type | ||
func (d *TeamMembership) TableName() string { | ||
return "d_b_team_membership" | ||
} | ||
|
||
type TeamMembershipRole string | ||
|
||
const ( | ||
TeamMembershipRole_Owner = TeamMembershipRole("owner") | ||
TeamMembershipRole_Member = TeamMembershipRole("member") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package db_test | ||
|
||
import ( | ||
"github.com/gitpod-io/gitpod/usage/pkg/db" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestTeamMembership_WriteRead(t *testing.T) { | ||
conn := db.ConnectForTests(t) | ||
|
||
membership := &db.TeamMembership{ | ||
ID: uuid.New(), | ||
TeamID: uuid.New(), | ||
UserID: uuid.New(), | ||
Role: db.TeamMembershipRole_Member, | ||
SubscriptionID: uuid.New(), | ||
} | ||
|
||
tx := conn.Create(membership) | ||
require.NoError(t, tx.Error) | ||
|
||
read := &db.TeamMembership{ID: membership.ID} | ||
tx = conn.First(read) | ||
require.NoError(t, tx.Error) | ||
require.Equal(t, membership, read) | ||
} |