Skip to content

Commit

Permalink
Merge branch 'main' into feat/canvas-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Jan 2, 2025
2 parents a9958ad + c17f387 commit c256aa5
Show file tree
Hide file tree
Showing 33 changed files with 4,317 additions and 3,893 deletions.
4 changes: 4 additions & 0 deletions admin/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (s *Service) InitOrganizationBilling(ctx context.Context, org *database.Org
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: org.QuotaProjects,
QuotaDeployments: org.QuotaDeployments,
Expand Down Expand Up @@ -124,6 +125,7 @@ func (s *Service) RepairOrganizationBilling(ctx context.Context, org *database.O
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: org.QuotaProjects,
QuotaDeployments: org.QuotaDeployments,
Expand Down Expand Up @@ -181,6 +183,7 @@ func (s *Service) RepairOrganizationBilling(ctx context.Context, org *database.O
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: biggerOfInt(sub.Plan.Quotas.NumProjects, org.QuotaProjects),
QuotaDeployments: biggerOfInt(sub.Plan.Quotas.NumDeployments, org.QuotaDeployments),
Expand Down Expand Up @@ -247,6 +250,7 @@ func (s *Service) StartTrial(ctx context.Context, org *database.Organization) (*
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: biggerOfInt(plan.Quotas.NumProjects, org.QuotaProjects),
QuotaDeployments: biggerOfInt(plan.Quotas.NumDeployments, org.QuotaDeployments),
Expand Down
9 changes: 8 additions & 1 deletion admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ type DB interface {

FindAsset(ctx context.Context, id string) (*Asset, error)
FindUnusedAssets(ctx context.Context, limit int) ([]*Asset, error)
InsertAsset(ctx context.Context, organizationID, path, ownerID string) (*Asset, error)
InsertAsset(ctx context.Context, id string, organizationID, path, ownerID string, cacheable bool) (*Asset, error)
DeleteAssets(ctx context.Context, ids []string) error

FindOrganizationIDsWithBilling(ctx context.Context) ([]string, error)
Expand Down Expand Up @@ -316,6 +316,7 @@ type Organization struct {
Name string
DisplayName string `db:"display_name"`
Description string
LogoAssetID *string `db:"logo_asset_id"`
CustomDomain string `db:"custom_domain"`
AllUsergroupID *string `db:"all_usergroup_id"`
CreatedOn time.Time `db:"created_on"`
Expand All @@ -337,6 +338,7 @@ type InsertOrganizationOptions struct {
Name string `validate:"slug"`
DisplayName string
Description string
LogoAssetID *string
CustomDomain string `validate:"omitempty,fqdn"`
QuotaProjects int
QuotaDeployments int
Expand All @@ -355,6 +357,7 @@ type UpdateOrganizationOptions struct {
Name string `validate:"slug"`
DisplayName string
Description string
LogoAssetID *string
CustomDomain string `validate:"omitempty,fqdn"`
QuotaProjects int
QuotaDeployments int
Expand Down Expand Up @@ -992,14 +995,18 @@ type InsertVirtualFileOptions struct {
Data []byte `validate:"max=8192"` // 8kb
}

// Asset represents a user-uploaded file asset.
// For example, this can be an upload deploy of a project or a custom logo for an org.
type Asset struct {
ID string
OrganizationID *string `db:"org_id"`
Path string `db:"path"`
OwnerID string `db:"owner_id"`
Cacheable bool `db:"cacheable"`
CreatedOn time.Time `db:"created_on"`
}

// ProjectVariable represents a key-value variable for a project, possible for a specific environment (e.g. production or development).
type ProjectVariable struct {
ID string `db:"id"`
ProjectID string `db:"project_id"`
Expand Down
3 changes: 3 additions & 0 deletions admin/database/postgres/migrations/0056.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE orgs ADD COLUMN logo_asset_id UUID REFERENCES assets(id) ON DELETE SET NULL;

ALTER TABLE assets ADD COLUMN cacheable BOOLEAN NOT NULL DEFAULT FALSE;
22 changes: 12 additions & 10 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func (c *connection) InsertOrganization(ctx context.Context, opts *database.Inse
}

res := &database.Organization{}
err := c.getDB(ctx).QueryRowxContext(ctx, `INSERT INTO orgs(name, display_name, description, custom_domain, quota_projects, quota_deployments, quota_slots_total, quota_slots_per_deployment, quota_outstanding_invites, quota_storage_limit_bytes_per_deployment, billing_customer_id, payment_customer_id, billing_email, created_by_user_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *`,
opts.Name, opts.DisplayName, opts.Description, opts.CustomDomain, opts.QuotaProjects, opts.QuotaDeployments, opts.QuotaSlotsTotal, opts.QuotaSlotsPerDeployment, opts.QuotaOutstandingInvites, opts.QuotaStorageLimitBytesPerDeployment, opts.BillingCustomerID, opts.PaymentCustomerID, opts.BillingEmail, opts.CreatedByUserID).StructScan(res)
err := c.getDB(ctx).QueryRowxContext(ctx, `INSERT INTO orgs(name, display_name, description, logo_asset_id, custom_domain, quota_projects, quota_deployments, quota_slots_total, quota_slots_per_deployment, quota_outstanding_invites, quota_storage_limit_bytes_per_deployment, billing_customer_id, payment_customer_id, billing_email, created_by_user_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *`,
opts.Name, opts.DisplayName, opts.Description, opts.LogoAssetID, opts.CustomDomain, opts.QuotaProjects, opts.QuotaDeployments, opts.QuotaSlotsTotal, opts.QuotaSlotsPerDeployment, opts.QuotaOutstandingInvites, opts.QuotaStorageLimitBytesPerDeployment, opts.BillingCustomerID, opts.PaymentCustomerID, opts.BillingEmail, opts.CreatedByUserID).StructScan(res)
if err != nil {
return nil, parseErr("org", err)
}
Expand All @@ -158,7 +158,9 @@ func (c *connection) UpdateOrganization(ctx context.Context, id string, opts *da
}

res := &database.Organization{}
err := c.getDB(ctx).QueryRowxContext(ctx, "UPDATE orgs SET name=$1, display_name=$2, description=$3, custom_domain=$4, quota_projects=$5, quota_deployments=$6, quota_slots_total=$7, quota_slots_per_deployment=$8, quota_outstanding_invites=$9, quota_storage_limit_bytes_per_deployment=$10, billing_customer_id=$11, payment_customer_id=$12, billing_email=$13, created_by_user_id=$14, updated_on=now() WHERE id=$15 RETURNING *", opts.Name, opts.DisplayName, opts.Description, opts.CustomDomain, opts.QuotaProjects, opts.QuotaDeployments, opts.QuotaSlotsTotal, opts.QuotaSlotsPerDeployment, opts.QuotaOutstandingInvites, opts.QuotaStorageLimitBytesPerDeployment, opts.BillingCustomerID, opts.PaymentCustomerID, opts.BillingEmail, opts.CreatedByUserID, id).StructScan(res)
err := c.getDB(ctx).QueryRowxContext(ctx,
`UPDATE orgs SET name=$1, display_name=$2, description=$3, logo_asset_id=$4, custom_domain=$5, quota_projects=$6, quota_deployments=$7, quota_slots_total=$8, quota_slots_per_deployment=$9, quota_outstanding_invites=$10, quota_storage_limit_bytes_per_deployment=$11, billing_customer_id=$12, payment_customer_id=$13, billing_email=$14, created_by_user_id=$15, updated_on=now() WHERE id=$16 RETURNING *`,
opts.Name, opts.DisplayName, opts.Description, opts.LogoAssetID, opts.CustomDomain, opts.QuotaProjects, opts.QuotaDeployments, opts.QuotaSlotsTotal, opts.QuotaSlotsPerDeployment, opts.QuotaOutstandingInvites, opts.QuotaStorageLimitBytesPerDeployment, opts.BillingCustomerID, opts.PaymentCustomerID, opts.BillingEmail, opts.CreatedByUserID, id).StructScan(res)
if err != nil {
return nil, parseErr("org", err)
}
Expand Down Expand Up @@ -1931,12 +1933,12 @@ func (c *connection) FindAsset(ctx context.Context, id string) (*database.Asset,
return res, nil
}

func (c *connection) InsertAsset(ctx context.Context, organizationID, path, ownerID string) (*database.Asset, error) {
func (c *connection) InsertAsset(ctx context.Context, id, organizationID, path, ownerID string, cacheable bool) (*database.Asset, error) {
res := &database.Asset{}
err := c.getDB(ctx).QueryRowxContext(ctx, `
INSERT INTO assets (org_id, path, owner_id)
VALUES ($1, $2, $3) RETURNING *`,
organizationID, path, ownerID,
INSERT INTO assets (id, org_id, path, owner_id, cacheable)
VALUES ($1, $2, $3, $4, $5) RETURNING *`,
id, organizationID, path, ownerID, cacheable,
).StructScan(res)
if err != nil {
return nil, parseErr("asset", err)
Expand All @@ -1951,8 +1953,8 @@ func (c *connection) FindUnusedAssets(ctx context.Context, limit int) ([]*databa
err := c.getDB(ctx).SelectContext(ctx, &res, `
SELECT a.* FROM assets a
WHERE a.created_on < now() - INTERVAL '6 hours'
AND NOT EXISTS
(SELECT 1 FROM projects p WHERE p.archive_asset_id = a.id)
AND NOT EXISTS (SELECT 1 FROM projects p WHERE p.archive_asset_id = a.id)
AND NOT EXISTS (SELECT 1 FROM orgs o WHERE o.logo_asset_id = a.id)
ORDER BY a.created_on DESC LIMIT $1
`, limit)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions admin/jobs/river/subscription_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (w *SubscriptionCancellationCheckWorker) subscriptionCancellationCheck(ctx
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: 0,
QuotaDeployments: 0,
Expand Down
1 change: 1 addition & 0 deletions admin/jobs/river/trial_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (w *TrialGracePeriodCheckWorker) trialGracePeriodCheck(ctx context.Context)
Name: org.Name,
DisplayName: org.DisplayName,
Description: org.Description,
LogoAssetID: org.LogoAssetID,
CustomDomain: org.CustomDomain,
QuotaProjects: 0,
QuotaDeployments: 0,
Expand Down
Loading

0 comments on commit c256aa5

Please sign in to comment.