enterprise-portal: init database schema and handler store#63139
enterprise-portal: init database schema and handler store#63139
Conversation
d1f30f5 to
da9dae2
Compare
There was a problem hiding this comment.
"customdsn" would never work, this PR is the first user of PGDSN(?) 😂
There was a problem hiding this comment.
I think this is a regression from recent PR to use pool, I've definitely used PGDSN for msp-testbed before
da9dae2 to
ee31f85
Compare
There was a problem hiding this comment.
There was a problem hiding this comment.
Copied from https://github.com/sourcegraph/sourcegraph-accounts/blob/main/backend/internal/redislock/mutex_test.go and adjusted test setup accordingly.
| // Subscription is a product subscription record. | ||
| type Subscription struct { | ||
| // ID is the prefixed UUID-format identifier for the subscription. | ||
| ID string `gorm:"primaryKey"` | ||
| // InstanceDomain is the instance domain associated with the subscription, e.g. | ||
| // "acme.sourcegraphcloud.com". | ||
| InstanceDomain string `gorm:"index"` | ||
| } |
There was a problem hiding this comment.
EP is still not the source of truth for subscriptions yet, so I think start small makes sense for things we actually need. Later PR(s) we will combine data in the handler layer, until EP becomes the source of truth.
We will add full-blown columns during when we move source-of-truth from dotcom to EP.
| // NewStoreV1 returns a new StoreV1 using the given client and database handles. | ||
| func NewStoreV1(opts NewStoreV1Options) StoreV1 { | ||
| return &storeV1{ | ||
| db: opts.DB, | ||
| dotcomDB: opts.DotcomDB, | ||
| } | ||
| } | ||
|
|
||
| func (s *storeV1) ListEnterpriseSubscriptionLicenses(ctx context.Context, filters []*subscriptionsv1.ListEnterpriseSubscriptionLicensesFilter, limit int) ([]*dotcomdb.LicenseAttributes, error) { | ||
| return s.dotcomDB.ListEnterpriseSubscriptionLicenses(ctx, filters, limit) | ||
| } |
| // shouldSkipMigration returns true if the migration should be skipped. | ||
| func shouldSkipMigration(previousVersion, currentVersion string) bool { | ||
| // Skip for PR-builds. | ||
| if strings.HasPrefix(currentVersion, "_candidate") { | ||
| return true | ||
| } | ||
|
|
||
| const releaseBuildVersionExample = "277307_2024-06-06_5.4-9185da3c3e42" | ||
| // We always run the full auto-migration if the version is not release-build like. | ||
| if len(currentVersion) < len(releaseBuildVersionExample) || | ||
| len(previousVersion) < len(releaseBuildVersionExample) { | ||
| return false | ||
| } | ||
|
|
||
| // The release build version is sorted lexicographically, so we can compare it as a string. | ||
| return previousVersion >= currentVersion | ||
| } |
There was a problem hiding this comment.
scary given the naming conventions are outside our control 😆 but hopefully is okay
Part of CORE-99
This PR scaffolds the database schema and code structure based on CORE-99 comment with some modifications. See inline comments for more elaborations.
*pgxpool.Poolas the DB interface for executing business logic queries.Additionally, refactored
subscriptionsservice/v1.goto use aStorethat provide single interface for accessing data(base), as we have been doing in SAMS and SSC.Test plan
Enterprise Portal starts locally, and database is initialized: