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

enterprise-portal: init database schema and handler store#63139

Merged
unknwon merged 7 commits intomainfrom
jc/00-ep-database
Jun 6, 2024
Merged

enterprise-portal: init database schema and handler store#63139
unknwon merged 7 commits intomainfrom
jc/00-ep-database

Conversation

@unknwon
Copy link
Contributor

@unknwon unknwon commented Jun 6, 2024

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.

  • It uses GORM's ONLY for auto migration, just to kick things off, we may migrate to file-based migration like we are planning for SAMS.
  • It then uses the *pgxpool.Pool as the DB interface for executing business logic queries.

Additionally, refactored subscriptionsservice/v1.go to use a Store that 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:

CleanShot 2024-06-06 at 17 02 42@2x

@cla-bot cla-bot bot added the cla-signed label Jun 6, 2024
@unknwon unknwon force-pushed the jc/00-ep-database branch 2 times, most recently from d1f30f5 to da9dae2 Compare June 6, 2024 21:12
Copy link
Contributor Author

@unknwon unknwon Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"customdsn" would never work, this PR is the first user of PGDSN(?) 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a regression from recent PR to use pool, I've definitely used PGDSN for msp-testbed before

@unknwon unknwon force-pushed the jc/00-ep-database branch from da9dae2 to ee31f85 Compare June 6, 2024 21:23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +3 to +10
// 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"`
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@unknwon unknwon marked this pull request as ready for review June 6, 2024 21:35
@unknwon unknwon requested a review from a team June 6, 2024 21:35
Comment on lines +28 to +38
// 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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks 😁

@unknwon unknwon requested a review from bobheadxi June 6, 2024 22:09
Comment on lines +89 to +105
// 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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scary given the naming conventions are outside our control 😆 but hopefully is okay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha we will see!

Copy link
Member

@bobheadxi bobheadxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 💪

@unknwon unknwon merged commit ce025a0 into main Jun 6, 2024
@unknwon unknwon deleted the jc/00-ep-database branch June 6, 2024 22:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants