Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit e9a31ea

Browse files
authored
feat/enterpriseportal: use UUID type for subscription ID (#63452)
We were aligned on using non-prefixed UUIDs internally, only prefixing them for external consumption. This lets us use the native UUID type. Part of https://linear.app/sourcegraph/issue/CORE-155 ## Test plan CI, `sg run enterprise-portal` `select * from enterprise_portal_subscriptions;` on dev shows we are using the non-prefixed UUDs only. Manual migration, since it doesn't seem like GORM can do this for you: ``` ALTER TABLE enterprise_portal_subscriptions ALTER COLUMN id TYPE uuid USING id::uuid; ``` Checked that data is intact.
1 parent 6c861d1 commit e9a31ea

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

cmd/enterprise-portal/internal/database/subscriptions/subscriptions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
// Subscription is an Enterprise subscription record.
1515
type Subscription struct {
16-
// ID is the prefixed UUID-format identifier for the subscription.
17-
ID string `gorm:"primaryKey"`
16+
// ID is the internal (unprefixed) UUID-format identifier for the subscription.
17+
ID string `gorm:"type:uuid;primaryKey"`
1818
// InstanceDomain is the instance domain associated with the subscription, e.g.
1919
// "acme.sourcegraphcloud.com".
2020
InstanceDomain string `gorm:"unique"`

cmd/enterprise-portal/internal/database/subscriptions/subscriptions_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func SubscriptionsStoreList(t *testing.T, ctx context.Context, s *subscriptions.
6767
assert.Equal(t, s2.ID, ss[1].ID)
6868

6969
t.Run("no match", func(t *testing.T) {
70-
ss, err = s.List(ctx, subscriptions.ListEnterpriseSubscriptionsOptions{IDs: []string{"1234"}})
70+
ss, err = s.List(ctx, subscriptions.ListEnterpriseSubscriptionsOptions{
71+
IDs: []string{uuid.Must(uuid.NewV7()).String()},
72+
})
7173
require.NoError(t, err)
7274
require.Len(t, ss, 0)
7375
})
@@ -83,7 +85,9 @@ func SubscriptionsStoreList(t *testing.T, ctx context.Context, s *subscriptions.
8385
assert.Equal(t, s2.ID, ss[1].ID)
8486

8587
t.Run("no match", func(t *testing.T) {
86-
ss, err = s.List(ctx, subscriptions.ListEnterpriseSubscriptionsOptions{InstanceDomains: []string{"1234"}})
88+
ss, err = s.List(ctx, subscriptions.ListEnterpriseSubscriptionsOptions{
89+
InstanceDomains: []string{"1234"},
90+
})
8791
require.NoError(t, err)
8892
require.Len(t, ss, 0)
8993
})

0 commit comments

Comments
 (0)