diff --git a/cmd/satellite/billing.go b/cmd/satellite/billing.go index 6a5c1a0dc..1bb4c8bd2 100644 --- a/cmd/satellite/billing.go +++ b/cmd/satellite/billing.go @@ -71,7 +71,6 @@ func setupPayments(log *zap.Logger, db satellite.DB) (*stripecoinpayments.Servic db.Wallets(), db.Billing(), db.Console().Projects(), - db.Console().Users(), db.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/accounting/db.go b/satellite/accounting/db.go index f12dec71b..02b9e6885 100644 --- a/satellite/accounting/db.go +++ b/satellite/accounting/db.go @@ -236,6 +236,9 @@ type ProjectAccounting interface { GetProjectLimits(ctx context.Context, projectID uuid.UUID) (ProjectLimits, error) // GetProjectTotal returns project usage summary for specified period of time. GetProjectTotal(ctx context.Context, projectID uuid.UUID, since, before time.Time) (*ProjectUsage, error) + // GetProjectTotalByPartner retrieves project usage for a given period categorized by partner name. + // Unpartnered usage or usage for a partner not present in partnerNames is mapped to the empty string. + GetProjectTotalByPartner(ctx context.Context, projectID uuid.UUID, partnerNames []string, since, before time.Time) (usages map[string]ProjectUsage, err error) // GetProjectObjectsSegments returns project objects and segments for specified period of time. GetProjectObjectsSegments(ctx context.Context, projectID uuid.UUID) (*ProjectObjectsSegments, error) // GetBucketUsageRollups returns usage rollup per each bucket for specified period of time. diff --git a/satellite/admin.go b/satellite/admin.go index 125da4962..eb5b0b04b 100644 --- a/satellite/admin.go +++ b/satellite/admin.go @@ -168,7 +168,6 @@ func NewAdmin(log *zap.Logger, full *identity.FullIdentity, db DB, metabaseDB *m peer.DB.Wallets(), peer.DB.Billing(), peer.DB.Console().Projects(), - peer.DB.Console().Users(), peer.DB.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/api.go b/satellite/api.go index 4a76d5a17..8cf9613bc 100644 --- a/satellite/api.go +++ b/satellite/api.go @@ -548,7 +548,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, peer.DB.Wallets(), peer.DB.Billing(), peer.DB.Console().Projects(), - peer.DB.Console().Users(), peer.DB.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/console/consoleweb/consoleql/mutation_test.go b/satellite/console/consoleweb/consoleql/mutation_test.go index 6f9af77f9..a3577fc10 100644 --- a/satellite/console/consoleweb/consoleql/mutation_test.go +++ b/satellite/console/consoleweb/consoleql/mutation_test.go @@ -92,7 +92,6 @@ func TestGraphqlMutation(t *testing.T) { db.Wallets(), db.Billing(), db.Console().Projects(), - db.Console().Users(), db.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/console/consoleweb/consoleql/query_test.go b/satellite/console/consoleweb/consoleql/query_test.go index 3bc3d1d42..66d89e4cb 100644 --- a/satellite/console/consoleweb/consoleql/query_test.go +++ b/satellite/console/consoleweb/consoleql/query_test.go @@ -76,7 +76,6 @@ func TestGraphqlQuery(t *testing.T) { db.Wallets(), db.Billing(), db.Console().Projects(), - db.Console().Users(), db.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/console/service.go b/satellite/console/service.go index 2e7aa4811..7382bf807 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -3044,7 +3044,7 @@ func (payment Payments) GetProjectUsagePriceModel(ctx context.Context) (_ *payme return nil, Error.Wrap(err) } - model := payment.service.accounts.GetProjectUsagePriceModel(user.UserAgent) + model := payment.service.accounts.GetProjectUsagePriceModel(string(user.UserAgent)) return &model, nil } diff --git a/satellite/core.go b/satellite/core.go index 21f6e5418..41d0f12b2 100644 --- a/satellite/core.go +++ b/satellite/core.go @@ -542,7 +542,6 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, peer.DB.Wallets(), peer.DB.Billing(), peer.DB.Console().Projects(), - peer.DB.Console().Users(), peer.DB.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/payments/account.go b/satellite/payments/account.go index 7157ca593..418048560 100644 --- a/satellite/payments/account.go +++ b/satellite/payments/account.go @@ -29,10 +29,8 @@ type Accounts interface { // ProjectCharges returns how much money current user will be charged for each project. ProjectCharges(ctx context.Context, userID uuid.UUID, since, before time.Time) ([]ProjectCharge, error) - // GetProjectUsagePriceModel returns the project usage price model for a user agent. - // If the user agent is malformed or does not contain a valid partner ID, the default - // price model is returned. - GetProjectUsagePriceModel(userAgent []byte) ProjectUsagePriceModel + // GetProjectUsagePriceModel returns the project usage price model for a partner name. + GetProjectUsagePriceModel(partner string) ProjectUsagePriceModel // CheckProjectInvoicingStatus returns error if for the given project there are outstanding project records and/or usage // which have not been applied/invoiced yet (meaning sent over to stripe). diff --git a/satellite/payments/stripecoinpayments/accounts.go b/satellite/payments/stripecoinpayments/accounts.go index 28a6639a0..35eeaa624 100644 --- a/satellite/payments/stripecoinpayments/accounts.go +++ b/satellite/payments/stripecoinpayments/accounts.go @@ -10,8 +10,8 @@ import ( "github.com/stripe/stripe-go/v72" "github.com/zeebo/errs" - "storj.io/common/useragent" "storj.io/common/uuid" + "storj.io/storj/satellite/accounting" "storj.io/storj/satellite/payments" ) @@ -120,48 +120,47 @@ func (accounts *accounts) ProjectCharges(ctx context.Context, userID uuid.UUID, return nil, Error.Wrap(err) } - user, err := accounts.service.usersDB.Get(ctx, userID) - if err != nil { - return nil, Error.Wrap(err) - } - for _, project := range projects { - usage, err := accounts.service.usageDB.GetProjectTotal(ctx, project.ID, since, before) + totalUsage := accounting.ProjectUsage{Since: since, Before: before} + + usages, err := accounts.service.usageDB.GetProjectTotalByPartner(ctx, project.ID, accounts.service.partnerNames, since, before) if err != nil { - return charges, Error.Wrap(err) + return nil, Error.Wrap(err) } - pricing := accounts.GetProjectUsagePriceModel(user.UserAgent) - projectPrice := accounts.service.calculateProjectUsagePrice(usage.Egress, usage.Storage, usage.SegmentCount, pricing) + var totalPrice projectUsagePrice + + for partner, usage := range usages { + priceModel := accounts.GetProjectUsagePriceModel(partner) + price := accounts.service.calculateProjectUsagePrice(usage.Egress, usage.Storage, usage.SegmentCount, priceModel) + + totalPrice.Egress = totalPrice.Egress.Add(price.Egress) + totalPrice.Segments = totalPrice.Segments.Add(price.Segments) + totalPrice.Storage = totalPrice.Storage.Add(price.Storage) + + totalUsage.Egress += usage.Egress + totalUsage.ObjectCount += usage.ObjectCount + totalUsage.SegmentCount += usage.SegmentCount + totalUsage.Storage += usage.Storage + } charges = append(charges, payments.ProjectCharge{ - ProjectUsage: *usage, + ProjectUsage: totalUsage, ProjectID: project.ID, - Egress: projectPrice.Egress.IntPart(), - SegmentCount: projectPrice.Segments.IntPart(), - StorageGbHrs: projectPrice.Storage.IntPart(), + Egress: totalPrice.Egress.IntPart(), + SegmentCount: totalPrice.Segments.IntPart(), + StorageGbHrs: totalPrice.Storage.IntPart(), }) } return charges, nil } -// GetProjectUsagePriceModel returns the project usage price model for a user agent. -// If the user agent is malformed or does not contain a valid partner ID, the default -// price model is returned. -func (accounts *accounts) GetProjectUsagePriceModel(userAgent []byte) payments.ProjectUsagePriceModel { - if userAgent == nil { - return accounts.service.usagePrices - } - entries, err := useragent.ParseEntries(userAgent) - if err != nil { - return accounts.service.usagePrices - } - for _, entry := range entries { - if override, ok := accounts.service.usagePriceOverrides[entry.Product]; ok { - return override - } +// GetProjectUsagePriceModel returns the project usage price model for a partner name. +func (accounts *accounts) GetProjectUsagePriceModel(partner string) payments.ProjectUsagePriceModel { + if override, ok := accounts.service.usagePriceOverrides[partner]; ok { + return override } return accounts.service.usagePrices } diff --git a/satellite/payments/stripecoinpayments/accounts_test.go b/satellite/payments/stripecoinpayments/accounts_test.go index b83b72342..9c754dcc6 100644 --- a/satellite/payments/stripecoinpayments/accounts_test.go +++ b/satellite/payments/stripecoinpayments/accounts_test.go @@ -70,7 +70,6 @@ func TestSignupCouponCodes(t *testing.T) { db.Wallets(), db.Billing(), db.Console().Projects(), - db.Console().Users(), db.ProjectAccounting(), prices, priceOverrides, diff --git a/satellite/payments/stripecoinpayments/service.go b/satellite/payments/stripecoinpayments/service.go index 1d44771af..1ed11f3e1 100644 --- a/satellite/payments/stripecoinpayments/service.go +++ b/satellite/payments/stripecoinpayments/service.go @@ -8,6 +8,7 @@ import ( "encoding/json" "errors" "fmt" + "sort" "strconv" "strings" "time" @@ -61,12 +62,12 @@ type Service struct { billingDB billing.TransactionsDB projectsDB console.Projects - usersDB console.Users usageDB accounting.ProjectAccounting stripeClient StripeClient usagePrices payments.ProjectUsagePriceModel usagePriceOverrides map[string]payments.ProjectUsagePriceModel + partnerNames []string // BonusRate amount of percents BonusRate int64 // Coupon Values @@ -81,18 +82,23 @@ type Service struct { } // NewService creates a Service instance. -func NewService(log *zap.Logger, stripeClient StripeClient, config Config, db DB, walletsDB storjscan.WalletsDB, billingDB billing.TransactionsDB, projectsDB console.Projects, usersDB console.Users, usageDB accounting.ProjectAccounting, usagePrices payments.ProjectUsagePriceModel, usagePriceOverrides map[string]payments.ProjectUsagePriceModel, bonusRate int64) (*Service, error) { +func NewService(log *zap.Logger, stripeClient StripeClient, config Config, db DB, walletsDB storjscan.WalletsDB, billingDB billing.TransactionsDB, projectsDB console.Projects, usageDB accounting.ProjectAccounting, usagePrices payments.ProjectUsagePriceModel, usagePriceOverrides map[string]payments.ProjectUsagePriceModel, bonusRate int64) (*Service, error) { + var partners []string + for partner := range usagePriceOverrides { + partners = append(partners, partner) + } + return &Service{ log: log, db: db, walletsDB: walletsDB, billingDB: billingDB, projectsDB: projectsDB, - usersDB: usersDB, usageDB: usageDB, stripeClient: stripeClient, usagePrices: usagePrices, usagePriceOverrides: usagePriceOverrides, + partnerNames: partners, BonusRate: bonusRate, StripeFreeTierCouponID: config.StripeFreeTierCouponID, AutoAdvance: config.AutoAdvance, @@ -458,14 +464,7 @@ func (service *Service) applyProjectRecords(ctx context.Context, records []Proje return 0, errs.Wrap(err) } - owner, err := service.usersDB.Get(ctx, proj.OwnerID) - if err != nil { - service.log.Error("Owner does not exist for project.", zap.Stringer("Owner ID", proj.OwnerID), zap.Stringer("Project ID", record.ProjectID)) - return 0, errs.Wrap(err) - } - - pricing := service.Accounts().GetProjectUsagePriceModel(owner.UserAgent) - if skipped, err := service.createInvoiceItems(ctx, cusID, proj.Name, record, pricing); err != nil { + if skipped, err := service.createInvoiceItems(ctx, cusID, proj.Name, record); err != nil { return 0, errs.Wrap(err) } else if skipped { skipCount++ @@ -476,7 +475,7 @@ func (service *Service) applyProjectRecords(ctx context.Context, records []Proje } // createInvoiceItems creates invoice line items for stripe customer. -func (service *Service) createInvoiceItems(ctx context.Context, cusID, projName string, record ProjectRecord, priceModel payments.ProjectUsagePriceModel) (skipped bool, err error) { +func (service *Service) createInvoiceItems(ctx context.Context, cusID, projName string, record ProjectRecord) (skipped bool, err error) { defer mon.Task()(&ctx)(&err) if err = service.db.ProjectRecords().Consume(ctx, record.ID); err != nil { @@ -487,7 +486,12 @@ func (service *Service) createInvoiceItems(ctx context.Context, cusID, projName return true, nil } - items := service.InvoiceItemsFromProjectRecord(projName, record, priceModel) + usages, err := service.usageDB.GetProjectTotalByPartner(ctx, record.ProjectID, service.partnerNames, record.PeriodStart, record.PeriodEnd) + if err != nil { + return false, err + } + + items := service.InvoiceItemsFromProjectUsage(projName, usages) for _, item := range items { item.Currency = stripe.String(string(stripe.CurrencyUSD)) item.Customer = stripe.String(cusID) @@ -502,28 +506,50 @@ func (service *Service) createInvoiceItems(ctx context.Context, cusID, projName return false, nil } -// InvoiceItemsFromProjectRecord calculates Stripe invoice item from project record. -func (service *Service) InvoiceItemsFromProjectRecord(projName string, record ProjectRecord, priceModel payments.ProjectUsagePriceModel) (result []*stripe.InvoiceItemParams) { - projectItem := &stripe.InvoiceItemParams{} - projectItem.Description = stripe.String(fmt.Sprintf("Project %s - Segment Storage (MB-Month)", projName)) - projectItem.Quantity = stripe.Int64(storageMBMonthDecimal(record.Storage).IntPart()) - storagePrice, _ := priceModel.StorageMBMonthCents.Float64() - projectItem.UnitAmountDecimal = stripe.Float64(storagePrice) - result = append(result, projectItem) +// InvoiceItemsFromProjectUsage calculates Stripe invoice item from project usage. +func (service *Service) InvoiceItemsFromProjectUsage(projName string, partnerUsages map[string]accounting.ProjectUsage) (result []*stripe.InvoiceItemParams) { + var partners []string + if len(partnerUsages) == 0 { + partners = []string{""} + partnerUsages = map[string]accounting.ProjectUsage{"": {}} + } else { + for partner := range partnerUsages { + partners = append(partners, partner) + } + sort.Strings(partners) + } - projectItem = &stripe.InvoiceItemParams{} - projectItem.Description = stripe.String(fmt.Sprintf("Project %s - Egress Bandwidth (MB)", projName)) - projectItem.Quantity = stripe.Int64(egressMBDecimal(record.Egress).IntPart()) - egressPrice, _ := priceModel.EgressMBCents.Float64() - projectItem.UnitAmountDecimal = stripe.Float64(egressPrice) - result = append(result, projectItem) + for _, partner := range partners { + usage := partnerUsages[partner] + priceModel := service.Accounts().GetProjectUsagePriceModel(partner) + + prefix := "Project " + projName + if partner != "" { + prefix += " (" + partner + ")" + } + + projectItem := &stripe.InvoiceItemParams{} + projectItem.Description = stripe.String(prefix + " - Segment Storage (MB-Month)") + projectItem.Quantity = stripe.Int64(storageMBMonthDecimal(usage.Storage).IntPart()) + storagePrice, _ := priceModel.StorageMBMonthCents.Float64() + projectItem.UnitAmountDecimal = stripe.Float64(storagePrice) + result = append(result, projectItem) + + projectItem = &stripe.InvoiceItemParams{} + projectItem.Description = stripe.String(prefix + " - Egress Bandwidth (MB)") + projectItem.Quantity = stripe.Int64(egressMBDecimal(usage.Egress).IntPart()) + egressPrice, _ := priceModel.EgressMBCents.Float64() + projectItem.UnitAmountDecimal = stripe.Float64(egressPrice) + result = append(result, projectItem) + + projectItem = &stripe.InvoiceItemParams{} + projectItem.Description = stripe.String(prefix + " - Segment Fee (Segment-Month)") + projectItem.Quantity = stripe.Int64(segmentMonthDecimal(usage.SegmentCount).IntPart()) + segmentPrice, _ := priceModel.SegmentMonthCents.Float64() + projectItem.UnitAmountDecimal = stripe.Float64(segmentPrice) + result = append(result, projectItem) + } - projectItem = &stripe.InvoiceItemParams{} - projectItem.Description = stripe.String(fmt.Sprintf("Project %s - Segment Fee (Segment-Month)", projName)) - projectItem.Quantity = stripe.Int64(segmentMonthDecimal(record.Segments).IntPart()) - segmentPrice, _ := priceModel.SegmentMonthCents.Float64() - projectItem.UnitAmountDecimal = stripe.Float64(segmentPrice) - result = append(result, projectItem) service.log.Info("invoice items", zap.Any("result", result)) return result diff --git a/satellite/payments/stripecoinpayments/service_test.go b/satellite/payments/stripecoinpayments/service_test.go index 3e2f4fd92..43c68fb26 100644 --- a/satellite/payments/stripecoinpayments/service_test.go +++ b/satellite/payments/stripecoinpayments/service_test.go @@ -6,6 +6,7 @@ package stripecoinpayments_test import ( "context" "fmt" + "math" "strconv" "testing" "time" @@ -17,6 +18,7 @@ import ( "storj.io/common/currency" "storj.io/common/memory" "storj.io/common/pb" + "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/common/uuid" @@ -225,68 +227,106 @@ func TestService_ProjectsWithMembers(t *testing.T) { }) } -func TestService_InvoiceItemsFromProjectRecord(t *testing.T) { +func TestService_InvoiceItemsFromProjectUsage(t *testing.T) { + const ( + projectName = "my-project" + partnerName = "partner" + noOverridePartnerName = "no-override" + + hoursPerMonth = 24 * 30 + bytesPerMegabyte = int64(memory.MB / memory.B) + byteHoursPerMBMonth = hoursPerMonth * bytesPerMegabyte + ) + + var ( + defaultPrice = paymentsconfig.ProjectUsagePrice{ + StorageTB: "1", + EgressTB: "2", + Segment: "3", + } + partnerPrice = paymentsconfig.ProjectUsagePrice{ + StorageTB: "4", + EgressTB: "5", + Segment: "6", + } + ) + defaultModel, err := defaultPrice.ToModel() + require.NoError(t, err) + partnerModel, err := partnerPrice.ToModel() + require.NoError(t, err) + testplanet.Run(t, testplanet.Config{ SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0, + Reconfigure: testplanet.Reconfigure{ + Satellite: func(log *zap.Logger, index int, config *satellite.Config) { + config.Payments.UsagePrice = defaultPrice + config.Payments.UsagePriceOverrides.SetMap(map[string]paymentsconfig.ProjectUsagePrice{ + partnerName: partnerPrice, + }) + }, + }, }, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { - satellite := planet.Satellites[0] - - // these numbers are fraction of cents, not of dollars. - expectedStoragePrice := 0.001 - expectedEgressPrice := 0.0045 - expectedSegmentPrice := 0.00022 - - type TestCase struct { - Storage float64 - Egress int64 - Segments float64 - - StorageQuantity int64 - EgressQuantity int64 - SegmentsQuantity int64 - } - - testCases := []TestCase{ - {}, // all zeros - { - Storage: 10000000000, // Byte-Hours - // storage quantity is calculated to Megabyte-Months - // (10000000000 / 1000000) Byte-Hours to Megabytes-Hours - // round(10000 / 720) Megabytes-Hours to Megabyte-Months, 720 - hours in month - StorageQuantity: 14, // Megabyte-Months + usage := map[string]accounting.ProjectUsage{ + "": { + Storage: 10000000000, // Byte-hours + Egress: 123 * memory.GB.Int64(), // Bytes + SegmentCount: 200000, // Segment-Hours }, - { - Egress: 134 * memory.GB.Int64(), // Bytes - // egress quantity is calculated to Megabytes - // (134000000000 / 1000000) Bytes to Megabytes - EgressQuantity: 134000, // Megabytes + partnerName: { + Storage: 20000000000, + Egress: 456 * memory.GB.Int64(), + SegmentCount: 400000, }, - { - Segments: 400000, // Segment-Hours - // object quantity is calculated to Segment-Months - // round(400000 / 720) Segment-Hours to Segment-Months, 720 - hours in month - SegmentsQuantity: 556, // Segment-Months + noOverridePartnerName: { + Storage: 30000000000, + Egress: 789 * memory.GB.Int64(), + SegmentCount: 600000, }, } - for _, tc := range testCases { - record := stripecoinpayments.ProjectRecord{ - Storage: tc.Storage, - Egress: tc.Egress, - Segments: tc.Segments, - } + items := planet.Satellites[0].API.Payments.StripeService.InvoiceItemsFromProjectUsage(projectName, usage) + require.Len(t, items, len(usage)*3) - pricing := satellite.API.Payments.Accounts.GetProjectUsagePriceModel(nil) - items := satellite.API.Payments.StripeService.InvoiceItemsFromProjectRecord("project name", record, pricing) + for i, tt := range []struct { + name string + partner string + priceModel payments.ProjectUsagePriceModel + }{ + {"default pricing - no partner", "", defaultModel}, + {"default pricing - no override for partner", noOverridePartnerName, defaultModel}, + {"partner pricing", partnerName, partnerModel}, + } { + t.Run(tt.name, func(t *testing.T) { + prefix := "Project " + projectName + if tt.partner != "" { + prefix += " (" + tt.partner + ")" + } - require.Equal(t, tc.StorageQuantity, *items[0].Quantity) - require.Equal(t, expectedStoragePrice, *items[0].UnitAmountDecimal) + usage := usage[tt.partner] + expectedStorageQuantity := int64(math.Round(usage.Storage / float64(byteHoursPerMBMonth))) + expectedEgressQuantity := int64(math.Round(float64(usage.Egress) / float64(bytesPerMegabyte))) + expectedSegmentQuantity := int64(math.Round(usage.SegmentCount / hoursPerMonth)) - require.Equal(t, tc.EgressQuantity, *items[1].Quantity) - require.Equal(t, expectedEgressPrice, *items[1].UnitAmountDecimal) + items := items[i*3 : (i*3)+3] + for _, item := range items { + require.NotNil(t, item) + } - require.Equal(t, tc.SegmentsQuantity, *items[2].Quantity) - require.Equal(t, expectedSegmentPrice, *items[2].UnitAmountDecimal) + require.Equal(t, prefix+" - Segment Storage (MB-Month)", *items[0].Description) + require.Equal(t, expectedStorageQuantity, *items[0].Quantity) + storage, _ := tt.priceModel.StorageMBMonthCents.Float64() + require.Equal(t, storage, *items[0].UnitAmountDecimal) + + require.Equal(t, prefix+" - Egress Bandwidth (MB)", *items[1].Description) + require.Equal(t, expectedEgressQuantity, *items[1].Quantity) + egress, _ := tt.priceModel.EgressMBCents.Float64() + require.Equal(t, egress, *items[1].UnitAmountDecimal) + + require.Equal(t, prefix+" - Segment Fee (Segment-Month)", *items[2].Description) + require.Equal(t, expectedSegmentQuantity, *items[2].Quantity) + segment, _ := tt.priceModel.SegmentMonthCents.Float64() + require.Equal(t, segment, *items[2].UnitAmountDecimal) + }) } }) } @@ -539,9 +579,9 @@ func TestProjectUsagePrice(t *testing.T) { expectedPrice payments.ProjectUsagePriceModel }{ {"default pricing", nil, defaultModel}, - {"default pricing - user agent is not valid partner ID", []byte("invalid/v0.0"), defaultModel}, - {"partner pricing - user agent is partner ID", []byte(partnerName), partnerModel}, - {"partner pricing - user agent includes partner ID", []byte("invalid/v0.0 " + partnerName + " invalid/v0.0"), partnerModel}, + {"default pricing - user agent is not valid partner name", []byte("invalid/v0.0"), defaultModel}, + {"partner pricing - user agent is partner name", []byte(partnerName), partnerModel}, + {"partner pricing - user agent prefixed with partner name", []byte(partnerName + " invalid/v0.0"), partnerModel}, } { t.Run(tt.name, func(t *testing.T) { user, err := sat.AddUser(ctx, console.CreateUser{ @@ -554,7 +594,15 @@ func TestProjectUsagePrice(t *testing.T) { project, err := sat.AddProject(ctx, user.ID, "testproject") require.NoError(t, err) - err = sat.DB.Orders().UpdateBucketBandwidthSettle(ctx, project.ID, []byte("testbucket"), + bucket, err := sat.DB.Buckets().CreateBucket(ctx, storj.Bucket{ + ID: testrand.UUID(), + Name: testrand.BucketName(), + ProjectID: project.ID, + UserAgent: tt.userAgent, + }) + require.NoError(t, err) + + err = sat.DB.Orders().UpdateBucketBandwidthSettle(ctx, project.ID, []byte(bucket.Name), pb.PieceAction_GET, memory.TB.Int64(), 0, period) require.NoError(t, err) diff --git a/satellite/satellitedb/dbx/project_bucket.dbx b/satellite/satellitedb/dbx/project_bucket.dbx index ac1ea7e07..ef1eae4c4 100644 --- a/satellite/satellitedb/dbx/project_bucket.dbx +++ b/satellite/satellitedb/dbx/project_bucket.dbx @@ -98,6 +98,12 @@ read one ( where bucket_metainfo.name = ? ) +read one ( + select bucket_metainfo.user_agent + where bucket_metainfo.project_id = ? + where bucket_metainfo.name = ? +) + read has ( select bucket_metainfo where bucket_metainfo.project_id = ? diff --git a/satellite/satellitedb/dbx/satellitedb.dbx.go b/satellite/satellitedb/dbx/satellitedb.dbx.go index c9c1f1979..7659aa21d 100644 --- a/satellite/satellitedb/dbx/satellitedb.dbx.go +++ b/satellite/satellitedb/dbx/satellitedb.dbx.go @@ -11557,6 +11557,10 @@ type UsageLimit_Row struct { UsageLimit *int64 } +type UserAgent_Row struct { + UserAgent []byte +} + type UserId_Row struct { UserId []byte } @@ -12414,92 +12418,6 @@ func (obj *pgxImpl) CreateNoReturn_OauthToken(ctx context.Context, } -func (obj *pgxImpl) Create_BucketMetainfo(ctx context.Context, - bucket_metainfo_id BucketMetainfo_Id_Field, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field, - bucket_metainfo_path_cipher BucketMetainfo_PathCipher_Field, - bucket_metainfo_default_segment_size BucketMetainfo_DefaultSegmentSize_Field, - bucket_metainfo_default_encryption_cipher_suite BucketMetainfo_DefaultEncryptionCipherSuite_Field, - bucket_metainfo_default_encryption_block_size BucketMetainfo_DefaultEncryptionBlockSize_Field, - bucket_metainfo_default_redundancy_algorithm BucketMetainfo_DefaultRedundancyAlgorithm_Field, - bucket_metainfo_default_redundancy_share_size BucketMetainfo_DefaultRedundancyShareSize_Field, - bucket_metainfo_default_redundancy_required_shares BucketMetainfo_DefaultRedundancyRequiredShares_Field, - bucket_metainfo_default_redundancy_repair_shares BucketMetainfo_DefaultRedundancyRepairShares_Field, - bucket_metainfo_default_redundancy_optimal_shares BucketMetainfo_DefaultRedundancyOptimalShares_Field, - bucket_metainfo_default_redundancy_total_shares BucketMetainfo_DefaultRedundancyTotalShares_Field, - optional BucketMetainfo_Create_Fields) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - __now := obj.db.Hooks.Now().UTC() - __id_val := bucket_metainfo_id.value() - __project_id_val := bucket_metainfo_project_id.value() - __name_val := bucket_metainfo_name.value() - __partner_id_val := optional.PartnerId.value() - __user_agent_val := optional.UserAgent.value() - __path_cipher_val := bucket_metainfo_path_cipher.value() - __created_at_val := __now - __default_segment_size_val := bucket_metainfo_default_segment_size.value() - __default_encryption_cipher_suite_val := bucket_metainfo_default_encryption_cipher_suite.value() - __default_encryption_block_size_val := bucket_metainfo_default_encryption_block_size.value() - __default_redundancy_algorithm_val := bucket_metainfo_default_redundancy_algorithm.value() - __default_redundancy_share_size_val := bucket_metainfo_default_redundancy_share_size.value() - __default_redundancy_required_shares_val := bucket_metainfo_default_redundancy_required_shares.value() - __default_redundancy_repair_shares_val := bucket_metainfo_default_redundancy_repair_shares.value() - __default_redundancy_optimal_shares_val := bucket_metainfo_default_redundancy_optimal_shares.value() - __default_redundancy_total_shares_val := bucket_metainfo_default_redundancy_total_shares.value() - __placement_val := optional.Placement.value() - - var __embed_stmt = __sqlbundle_Literal("INSERT INTO bucket_metainfos ( id, project_id, name, partner_id, user_agent, path_cipher, created_at, default_segment_size, default_encryption_cipher_suite, default_encryption_block_size, default_redundancy_algorithm, default_redundancy_share_size, default_redundancy_required_shares, default_redundancy_repair_shares, default_redundancy_optimal_shares, default_redundancy_total_shares, placement ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement") - - var __values []interface{} - __values = append(__values, __id_val, __project_id_val, __name_val, __partner_id_val, __user_agent_val, __path_cipher_val, __created_at_val, __default_segment_size_val, __default_encryption_cipher_suite_val, __default_encryption_block_size_val, __default_redundancy_algorithm_val, __default_redundancy_share_size_val, __default_redundancy_required_shares_val, __default_redundancy_repair_shares_val, __default_redundancy_optimal_shares_val, __default_redundancy_total_shares_val, __placement_val) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, obj.makeErr(err) - } - return bucket_metainfo, nil - -} - -func (obj *pgxImpl) Create_ValueAttribution(ctx context.Context, - value_attribution_project_id ValueAttribution_ProjectId_Field, - value_attribution_bucket_name ValueAttribution_BucketName_Field, - value_attribution_partner_id ValueAttribution_PartnerId_Field, - optional ValueAttribution_Create_Fields) ( - value_attribution *ValueAttribution, err error) { - defer mon.Task()(&ctx)(&err) - - __now := obj.db.Hooks.Now().UTC() - __project_id_val := value_attribution_project_id.value() - __bucket_name_val := value_attribution_bucket_name.value() - __partner_id_val := value_attribution_partner_id.value() - __user_agent_val := optional.UserAgent.value() - __last_updated_val := __now - - var __embed_stmt = __sqlbundle_Literal("INSERT INTO value_attributions ( project_id, bucket_name, partner_id, user_agent, last_updated ) VALUES ( ?, ?, ?, ?, ? ) RETURNING value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated") - - var __values []interface{} - __values = append(__values, __project_id_val, __bucket_name_val, __partner_id_val, __user_agent_val, __last_updated_val) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - value_attribution = &ValueAttribution{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) - if err != nil { - return nil, obj.makeErr(err) - } - return value_attribution, nil - -} - func (obj *pgxImpl) Create_Project(ctx context.Context, project_id Project_Id_Field, project_name Project_Name_Field, @@ -12630,6 +12548,92 @@ func (obj *pgxImpl) Create_ApiKey(ctx context.Context, } +func (obj *pgxImpl) Create_BucketMetainfo(ctx context.Context, + bucket_metainfo_id BucketMetainfo_Id_Field, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field, + bucket_metainfo_path_cipher BucketMetainfo_PathCipher_Field, + bucket_metainfo_default_segment_size BucketMetainfo_DefaultSegmentSize_Field, + bucket_metainfo_default_encryption_cipher_suite BucketMetainfo_DefaultEncryptionCipherSuite_Field, + bucket_metainfo_default_encryption_block_size BucketMetainfo_DefaultEncryptionBlockSize_Field, + bucket_metainfo_default_redundancy_algorithm BucketMetainfo_DefaultRedundancyAlgorithm_Field, + bucket_metainfo_default_redundancy_share_size BucketMetainfo_DefaultRedundancyShareSize_Field, + bucket_metainfo_default_redundancy_required_shares BucketMetainfo_DefaultRedundancyRequiredShares_Field, + bucket_metainfo_default_redundancy_repair_shares BucketMetainfo_DefaultRedundancyRepairShares_Field, + bucket_metainfo_default_redundancy_optimal_shares BucketMetainfo_DefaultRedundancyOptimalShares_Field, + bucket_metainfo_default_redundancy_total_shares BucketMetainfo_DefaultRedundancyTotalShares_Field, + optional BucketMetainfo_Create_Fields) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + __now := obj.db.Hooks.Now().UTC() + __id_val := bucket_metainfo_id.value() + __project_id_val := bucket_metainfo_project_id.value() + __name_val := bucket_metainfo_name.value() + __partner_id_val := optional.PartnerId.value() + __user_agent_val := optional.UserAgent.value() + __path_cipher_val := bucket_metainfo_path_cipher.value() + __created_at_val := __now + __default_segment_size_val := bucket_metainfo_default_segment_size.value() + __default_encryption_cipher_suite_val := bucket_metainfo_default_encryption_cipher_suite.value() + __default_encryption_block_size_val := bucket_metainfo_default_encryption_block_size.value() + __default_redundancy_algorithm_val := bucket_metainfo_default_redundancy_algorithm.value() + __default_redundancy_share_size_val := bucket_metainfo_default_redundancy_share_size.value() + __default_redundancy_required_shares_val := bucket_metainfo_default_redundancy_required_shares.value() + __default_redundancy_repair_shares_val := bucket_metainfo_default_redundancy_repair_shares.value() + __default_redundancy_optimal_shares_val := bucket_metainfo_default_redundancy_optimal_shares.value() + __default_redundancy_total_shares_val := bucket_metainfo_default_redundancy_total_shares.value() + __placement_val := optional.Placement.value() + + var __embed_stmt = __sqlbundle_Literal("INSERT INTO bucket_metainfos ( id, project_id, name, partner_id, user_agent, path_cipher, created_at, default_segment_size, default_encryption_cipher_suite, default_encryption_block_size, default_redundancy_algorithm, default_redundancy_share_size, default_redundancy_required_shares, default_redundancy_repair_shares, default_redundancy_optimal_shares, default_redundancy_total_shares, placement ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement") + + var __values []interface{} + __values = append(__values, __id_val, __project_id_val, __name_val, __partner_id_val, __user_agent_val, __path_cipher_val, __created_at_val, __default_segment_size_val, __default_encryption_cipher_suite_val, __default_encryption_block_size_val, __default_redundancy_algorithm_val, __default_redundancy_share_size_val, __default_redundancy_required_shares_val, __default_redundancy_repair_shares_val, __default_redundancy_optimal_shares_val, __default_redundancy_total_shares_val, __placement_val) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, obj.makeErr(err) + } + return bucket_metainfo, nil + +} + +func (obj *pgxImpl) Create_ValueAttribution(ctx context.Context, + value_attribution_project_id ValueAttribution_ProjectId_Field, + value_attribution_bucket_name ValueAttribution_BucketName_Field, + value_attribution_partner_id ValueAttribution_PartnerId_Field, + optional ValueAttribution_Create_Fields) ( + value_attribution *ValueAttribution, err error) { + defer mon.Task()(&ctx)(&err) + + __now := obj.db.Hooks.Now().UTC() + __project_id_val := value_attribution_project_id.value() + __bucket_name_val := value_attribution_bucket_name.value() + __partner_id_val := value_attribution_partner_id.value() + __user_agent_val := optional.UserAgent.value() + __last_updated_val := __now + + var __embed_stmt = __sqlbundle_Literal("INSERT INTO value_attributions ( project_id, bucket_name, partner_id, user_agent, last_updated ) VALUES ( ?, ?, ?, ?, ? ) RETURNING value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated") + + var __values []interface{} + __values = append(__values, __project_id_val, __bucket_name_val, __partner_id_val, __user_agent_val, __last_updated_val) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + value_attribution = &ValueAttribution{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) + if err != nil { + return nil, obj.makeErr(err) + } + return value_attribution, nil + +} + func (obj *pgxImpl) Create_User(ctx context.Context, user_id User_Id_Field, user_email User_Email_Field, @@ -14848,265 +14852,6 @@ func (obj *pgxImpl) Get_OauthToken_By_Kind_And_Token(ctx context.Context, } -func (obj *pgxImpl) Get_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return (*BucketMetainfo)(nil), obj.makeErr(err) - } - return bucket_metainfo, nil - -} - -func (obj *pgxImpl) Get_BucketMetainfo_CreatedAt_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *CreatedAt_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.created_at FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &CreatedAt_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.CreatedAt) - if err != nil { - return (*CreatedAt_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxImpl) Get_BucketMetainfo_Id_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *Id_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &Id_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Id) - if err != nil { - return (*Id_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxImpl) Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *Placement_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &Placement_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Placement) - if err != nil { - return (*Placement_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxImpl) Has_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - has bool, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT EXISTS( SELECT 1 FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? )") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&has) - if err != nil { - return false, obj.makeErr(err) - } - return has, nil - -} - -func (obj *pgxImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_GreaterOrEqual_OrderBy_Asc_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name_greater_or_equal BucketMetainfo_Name_Field, - limit int, offset int64) ( - rows []*BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name >= ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater_or_equal.value()) - - __values = append(__values, limit, offset) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - for { - rows, err = func() (rows []*BucketMetainfo, err error) { - __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) - if err != nil { - return nil, err - } - defer __rows.Close() - - for __rows.Next() { - bucket_metainfo := &BucketMetainfo{} - err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, err - } - rows = append(rows, bucket_metainfo) - } - err = __rows.Err() - if err != nil { - return nil, err - } - return rows, nil - }() - if err != nil { - if obj.shouldRetry(err) { - continue - } - return nil, obj.makeErr(err) - } - return rows, nil - } - -} - -func (obj *pgxImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_Greater_OrderBy_Asc_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name_greater BucketMetainfo_Name_Field, - limit int, offset int64) ( - rows []*BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name > ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater.value()) - - __values = append(__values, limit, offset) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - for { - rows, err = func() (rows []*BucketMetainfo, err error) { - __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) - if err != nil { - return nil, err - } - defer __rows.Close() - - for __rows.Next() { - bucket_metainfo := &BucketMetainfo{} - err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, err - } - rows = append(rows, bucket_metainfo) - } - err = __rows.Err() - if err != nil { - return nil, err - } - return rows, nil - }() - if err != nil { - if obj.shouldRetry(err) { - continue - } - return nil, obj.makeErr(err) - } - return rows, nil - } - -} - -func (obj *pgxImpl) Count_BucketMetainfo_Name_By_ProjectId(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field) ( - count int64, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT COUNT(*) FROM bucket_metainfos WHERE bucket_metainfos.project_id = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&count) - if err != nil { - return 0, obj.makeErr(err) - } - - return count, nil - -} - -func (obj *pgxImpl) Get_ValueAttribution_By_ProjectId_And_BucketName(ctx context.Context, - value_attribution_project_id ValueAttribution_ProjectId_Field, - value_attribution_bucket_name ValueAttribution_BucketName_Field) ( - value_attribution *ValueAttribution, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated FROM value_attributions WHERE value_attributions.project_id = ? AND value_attributions.bucket_name = ?") - - var __values []interface{} - __values = append(__values, value_attribution_project_id.value(), value_attribution_bucket_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - value_attribution = &ValueAttribution{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) - if err != nil { - return (*ValueAttribution)(nil), obj.makeErr(err) - } - return value_attribution, nil - -} - func (obj *pgxImpl) Get_Project_Salt_By_Id(ctx context.Context, project_id Project_Id_Field) ( row *Salt_Row, err error) { @@ -15707,6 +15452,288 @@ func (obj *pgxImpl) Get_ApiKey_By_Name_And_ProjectId(ctx context.Context, } +func (obj *pgxImpl) Get_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return (*BucketMetainfo)(nil), obj.makeErr(err) + } + return bucket_metainfo, nil + +} + +func (obj *pgxImpl) Get_BucketMetainfo_CreatedAt_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *CreatedAt_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.created_at FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &CreatedAt_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.CreatedAt) + if err != nil { + return (*CreatedAt_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxImpl) Get_BucketMetainfo_Id_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *Id_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &Id_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Id) + if err != nil { + return (*Id_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxImpl) Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *Placement_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &Placement_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Placement) + if err != nil { + return (*Placement_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxImpl) Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *UserAgent_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.user_agent FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &UserAgent_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.UserAgent) + if err != nil { + return (*UserAgent_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxImpl) Has_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + has bool, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT EXISTS( SELECT 1 FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? )") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&has) + if err != nil { + return false, obj.makeErr(err) + } + return has, nil + +} + +func (obj *pgxImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_GreaterOrEqual_OrderBy_Asc_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name_greater_or_equal BucketMetainfo_Name_Field, + limit int, offset int64) ( + rows []*BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name >= ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater_or_equal.value()) + + __values = append(__values, limit, offset) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + for { + rows, err = func() (rows []*BucketMetainfo, err error) { + __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) + if err != nil { + return nil, err + } + defer __rows.Close() + + for __rows.Next() { + bucket_metainfo := &BucketMetainfo{} + err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, err + } + rows = append(rows, bucket_metainfo) + } + err = __rows.Err() + if err != nil { + return nil, err + } + return rows, nil + }() + if err != nil { + if obj.shouldRetry(err) { + continue + } + return nil, obj.makeErr(err) + } + return rows, nil + } + +} + +func (obj *pgxImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_Greater_OrderBy_Asc_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name_greater BucketMetainfo_Name_Field, + limit int, offset int64) ( + rows []*BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name > ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater.value()) + + __values = append(__values, limit, offset) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + for { + rows, err = func() (rows []*BucketMetainfo, err error) { + __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) + if err != nil { + return nil, err + } + defer __rows.Close() + + for __rows.Next() { + bucket_metainfo := &BucketMetainfo{} + err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, err + } + rows = append(rows, bucket_metainfo) + } + err = __rows.Err() + if err != nil { + return nil, err + } + return rows, nil + }() + if err != nil { + if obj.shouldRetry(err) { + continue + } + return nil, obj.makeErr(err) + } + return rows, nil + } + +} + +func (obj *pgxImpl) Count_BucketMetainfo_Name_By_ProjectId(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field) ( + count int64, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT COUNT(*) FROM bucket_metainfos WHERE bucket_metainfos.project_id = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&count) + if err != nil { + return 0, obj.makeErr(err) + } + + return count, nil + +} + +func (obj *pgxImpl) Get_ValueAttribution_By_ProjectId_And_BucketName(ctx context.Context, + value_attribution_project_id ValueAttribution_ProjectId_Field, + value_attribution_bucket_name ValueAttribution_BucketName_Field) ( + value_attribution *ValueAttribution, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated FROM value_attributions WHERE value_attributions.project_id = ? AND value_attributions.bucket_name = ?") + + var __values []interface{} + __values = append(__values, value_attribution_project_id.value(), value_attribution_bucket_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + value_attribution = &ValueAttribution{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) + if err != nil { + return (*ValueAttribution)(nil), obj.makeErr(err) + } + return value_attribution, nil + +} + func (obj *pgxImpl) All_User_By_NormalizedEmail(ctx context.Context, user_normalized_email User_NormalizedEmail_Field) ( rows []*User, err error) { @@ -17485,103 +17512,6 @@ func (obj *pgxImpl) UpdateNoReturn_OauthToken_By_Token_And_Kind(ctx context.Cont return nil } -func (obj *pgxImpl) Update_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field, - update BucketMetainfo_Update_Fields) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - var __sets = &__sqlbundle_Hole{} - - var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE bucket_metainfos SET "), __sets, __sqlbundle_Literal(" WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement")}} - - __sets_sql := __sqlbundle_Literals{Join: ", "} - var __values []interface{} - var __args []interface{} - - if update.PartnerId._set { - __values = append(__values, update.PartnerId.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("partner_id = ?")) - } - - if update.UserAgent._set { - __values = append(__values, update.UserAgent.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("user_agent = ?")) - } - - if update.DefaultSegmentSize._set { - __values = append(__values, update.DefaultSegmentSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_segment_size = ?")) - } - - if update.DefaultEncryptionCipherSuite._set { - __values = append(__values, update.DefaultEncryptionCipherSuite.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_cipher_suite = ?")) - } - - if update.DefaultEncryptionBlockSize._set { - __values = append(__values, update.DefaultEncryptionBlockSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_block_size = ?")) - } - - if update.DefaultRedundancyAlgorithm._set { - __values = append(__values, update.DefaultRedundancyAlgorithm.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_algorithm = ?")) - } - - if update.DefaultRedundancyShareSize._set { - __values = append(__values, update.DefaultRedundancyShareSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_share_size = ?")) - } - - if update.DefaultRedundancyRequiredShares._set { - __values = append(__values, update.DefaultRedundancyRequiredShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_required_shares = ?")) - } - - if update.DefaultRedundancyRepairShares._set { - __values = append(__values, update.DefaultRedundancyRepairShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_repair_shares = ?")) - } - - if update.DefaultRedundancyOptimalShares._set { - __values = append(__values, update.DefaultRedundancyOptimalShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_optimal_shares = ?")) - } - - if update.DefaultRedundancyTotalShares._set { - __values = append(__values, update.DefaultRedundancyTotalShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_total_shares = ?")) - } - - if update.Placement._set { - __values = append(__values, update.Placement.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("placement = ?")) - } - - if len(__sets_sql.SQLs) == 0 { - return nil, emptyUpdate() - } - - __args = append(__args, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - __values = append(__values, __args...) - __sets.SQL = __sets_sql - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err == sql.ErrNoRows { - return nil, nil - } - if err != nil { - return nil, obj.makeErr(err) - } - return bucket_metainfo, nil -} - func (obj *pgxImpl) Update_Project_By_Id(ctx context.Context, project_id Project_Id_Field, update Project_Update_Fields) ( @@ -17705,6 +17635,103 @@ func (obj *pgxImpl) UpdateNoReturn_ApiKey_By_Id(ctx context.Context, return nil } +func (obj *pgxImpl) Update_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field, + update BucketMetainfo_Update_Fields) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + var __sets = &__sqlbundle_Hole{} + + var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE bucket_metainfos SET "), __sets, __sqlbundle_Literal(" WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement")}} + + __sets_sql := __sqlbundle_Literals{Join: ", "} + var __values []interface{} + var __args []interface{} + + if update.PartnerId._set { + __values = append(__values, update.PartnerId.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("partner_id = ?")) + } + + if update.UserAgent._set { + __values = append(__values, update.UserAgent.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("user_agent = ?")) + } + + if update.DefaultSegmentSize._set { + __values = append(__values, update.DefaultSegmentSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_segment_size = ?")) + } + + if update.DefaultEncryptionCipherSuite._set { + __values = append(__values, update.DefaultEncryptionCipherSuite.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_cipher_suite = ?")) + } + + if update.DefaultEncryptionBlockSize._set { + __values = append(__values, update.DefaultEncryptionBlockSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_block_size = ?")) + } + + if update.DefaultRedundancyAlgorithm._set { + __values = append(__values, update.DefaultRedundancyAlgorithm.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_algorithm = ?")) + } + + if update.DefaultRedundancyShareSize._set { + __values = append(__values, update.DefaultRedundancyShareSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_share_size = ?")) + } + + if update.DefaultRedundancyRequiredShares._set { + __values = append(__values, update.DefaultRedundancyRequiredShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_required_shares = ?")) + } + + if update.DefaultRedundancyRepairShares._set { + __values = append(__values, update.DefaultRedundancyRepairShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_repair_shares = ?")) + } + + if update.DefaultRedundancyOptimalShares._set { + __values = append(__values, update.DefaultRedundancyOptimalShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_optimal_shares = ?")) + } + + if update.DefaultRedundancyTotalShares._set { + __values = append(__values, update.DefaultRedundancyTotalShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_total_shares = ?")) + } + + if update.Placement._set { + __values = append(__values, update.Placement.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("placement = ?")) + } + + if len(__sets_sql.SQLs) == 0 { + return nil, emptyUpdate() + } + + __args = append(__args, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + __values = append(__values, __args...) + __sets.SQL = __sets_sql + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err == sql.ErrNoRows { + return nil, nil + } + if err != nil { + return nil, obj.makeErr(err) + } + return bucket_metainfo, nil +} + func (obj *pgxImpl) Update_User_By_Id(ctx context.Context, user_id User_Id_Field, update User_Update_Fields) ( @@ -18189,34 +18216,6 @@ func (obj *pgxImpl) Delete_OauthClient_By_Id(ctx context.Context, } -func (obj *pgxImpl) Delete_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - deleted bool, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("DELETE FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - __res, err := obj.driver.ExecContext(ctx, __stmt, __values...) - if err != nil { - return false, obj.makeErr(err) - } - - __count, err := __res.RowsAffected() - if err != nil { - return false, obj.makeErr(err) - } - - return __count > 0, nil - -} - func (obj *pgxImpl) Delete_Project_By_Id(ctx context.Context, project_id Project_Id_Field) ( deleted bool, err error) { @@ -18299,6 +18298,34 @@ func (obj *pgxImpl) Delete_ApiKey_By_Id(ctx context.Context, } +func (obj *pgxImpl) Delete_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + deleted bool, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("DELETE FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + __res, err := obj.driver.ExecContext(ctx, __stmt, __values...) + if err != nil { + return false, obj.makeErr(err) + } + + __count, err := __res.RowsAffected() + if err != nil { + return false, obj.makeErr(err) + } + + return __count > 0, nil + +} + func (obj *pgxImpl) Delete_RepairQueue_By_UpdatedAt_Less(ctx context.Context, repair_queue_updated_at_less RepairQueue_UpdatedAt_Field) ( count int64, err error) { @@ -19777,92 +19804,6 @@ func (obj *pgxcockroachImpl) CreateNoReturn_OauthToken(ctx context.Context, } -func (obj *pgxcockroachImpl) Create_BucketMetainfo(ctx context.Context, - bucket_metainfo_id BucketMetainfo_Id_Field, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field, - bucket_metainfo_path_cipher BucketMetainfo_PathCipher_Field, - bucket_metainfo_default_segment_size BucketMetainfo_DefaultSegmentSize_Field, - bucket_metainfo_default_encryption_cipher_suite BucketMetainfo_DefaultEncryptionCipherSuite_Field, - bucket_metainfo_default_encryption_block_size BucketMetainfo_DefaultEncryptionBlockSize_Field, - bucket_metainfo_default_redundancy_algorithm BucketMetainfo_DefaultRedundancyAlgorithm_Field, - bucket_metainfo_default_redundancy_share_size BucketMetainfo_DefaultRedundancyShareSize_Field, - bucket_metainfo_default_redundancy_required_shares BucketMetainfo_DefaultRedundancyRequiredShares_Field, - bucket_metainfo_default_redundancy_repair_shares BucketMetainfo_DefaultRedundancyRepairShares_Field, - bucket_metainfo_default_redundancy_optimal_shares BucketMetainfo_DefaultRedundancyOptimalShares_Field, - bucket_metainfo_default_redundancy_total_shares BucketMetainfo_DefaultRedundancyTotalShares_Field, - optional BucketMetainfo_Create_Fields) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - __now := obj.db.Hooks.Now().UTC() - __id_val := bucket_metainfo_id.value() - __project_id_val := bucket_metainfo_project_id.value() - __name_val := bucket_metainfo_name.value() - __partner_id_val := optional.PartnerId.value() - __user_agent_val := optional.UserAgent.value() - __path_cipher_val := bucket_metainfo_path_cipher.value() - __created_at_val := __now - __default_segment_size_val := bucket_metainfo_default_segment_size.value() - __default_encryption_cipher_suite_val := bucket_metainfo_default_encryption_cipher_suite.value() - __default_encryption_block_size_val := bucket_metainfo_default_encryption_block_size.value() - __default_redundancy_algorithm_val := bucket_metainfo_default_redundancy_algorithm.value() - __default_redundancy_share_size_val := bucket_metainfo_default_redundancy_share_size.value() - __default_redundancy_required_shares_val := bucket_metainfo_default_redundancy_required_shares.value() - __default_redundancy_repair_shares_val := bucket_metainfo_default_redundancy_repair_shares.value() - __default_redundancy_optimal_shares_val := bucket_metainfo_default_redundancy_optimal_shares.value() - __default_redundancy_total_shares_val := bucket_metainfo_default_redundancy_total_shares.value() - __placement_val := optional.Placement.value() - - var __embed_stmt = __sqlbundle_Literal("INSERT INTO bucket_metainfos ( id, project_id, name, partner_id, user_agent, path_cipher, created_at, default_segment_size, default_encryption_cipher_suite, default_encryption_block_size, default_redundancy_algorithm, default_redundancy_share_size, default_redundancy_required_shares, default_redundancy_repair_shares, default_redundancy_optimal_shares, default_redundancy_total_shares, placement ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement") - - var __values []interface{} - __values = append(__values, __id_val, __project_id_val, __name_val, __partner_id_val, __user_agent_val, __path_cipher_val, __created_at_val, __default_segment_size_val, __default_encryption_cipher_suite_val, __default_encryption_block_size_val, __default_redundancy_algorithm_val, __default_redundancy_share_size_val, __default_redundancy_required_shares_val, __default_redundancy_repair_shares_val, __default_redundancy_optimal_shares_val, __default_redundancy_total_shares_val, __placement_val) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, obj.makeErr(err) - } - return bucket_metainfo, nil - -} - -func (obj *pgxcockroachImpl) Create_ValueAttribution(ctx context.Context, - value_attribution_project_id ValueAttribution_ProjectId_Field, - value_attribution_bucket_name ValueAttribution_BucketName_Field, - value_attribution_partner_id ValueAttribution_PartnerId_Field, - optional ValueAttribution_Create_Fields) ( - value_attribution *ValueAttribution, err error) { - defer mon.Task()(&ctx)(&err) - - __now := obj.db.Hooks.Now().UTC() - __project_id_val := value_attribution_project_id.value() - __bucket_name_val := value_attribution_bucket_name.value() - __partner_id_val := value_attribution_partner_id.value() - __user_agent_val := optional.UserAgent.value() - __last_updated_val := __now - - var __embed_stmt = __sqlbundle_Literal("INSERT INTO value_attributions ( project_id, bucket_name, partner_id, user_agent, last_updated ) VALUES ( ?, ?, ?, ?, ? ) RETURNING value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated") - - var __values []interface{} - __values = append(__values, __project_id_val, __bucket_name_val, __partner_id_val, __user_agent_val, __last_updated_val) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - value_attribution = &ValueAttribution{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) - if err != nil { - return nil, obj.makeErr(err) - } - return value_attribution, nil - -} - func (obj *pgxcockroachImpl) Create_Project(ctx context.Context, project_id Project_Id_Field, project_name Project_Name_Field, @@ -19993,6 +19934,92 @@ func (obj *pgxcockroachImpl) Create_ApiKey(ctx context.Context, } +func (obj *pgxcockroachImpl) Create_BucketMetainfo(ctx context.Context, + bucket_metainfo_id BucketMetainfo_Id_Field, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field, + bucket_metainfo_path_cipher BucketMetainfo_PathCipher_Field, + bucket_metainfo_default_segment_size BucketMetainfo_DefaultSegmentSize_Field, + bucket_metainfo_default_encryption_cipher_suite BucketMetainfo_DefaultEncryptionCipherSuite_Field, + bucket_metainfo_default_encryption_block_size BucketMetainfo_DefaultEncryptionBlockSize_Field, + bucket_metainfo_default_redundancy_algorithm BucketMetainfo_DefaultRedundancyAlgorithm_Field, + bucket_metainfo_default_redundancy_share_size BucketMetainfo_DefaultRedundancyShareSize_Field, + bucket_metainfo_default_redundancy_required_shares BucketMetainfo_DefaultRedundancyRequiredShares_Field, + bucket_metainfo_default_redundancy_repair_shares BucketMetainfo_DefaultRedundancyRepairShares_Field, + bucket_metainfo_default_redundancy_optimal_shares BucketMetainfo_DefaultRedundancyOptimalShares_Field, + bucket_metainfo_default_redundancy_total_shares BucketMetainfo_DefaultRedundancyTotalShares_Field, + optional BucketMetainfo_Create_Fields) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + __now := obj.db.Hooks.Now().UTC() + __id_val := bucket_metainfo_id.value() + __project_id_val := bucket_metainfo_project_id.value() + __name_val := bucket_metainfo_name.value() + __partner_id_val := optional.PartnerId.value() + __user_agent_val := optional.UserAgent.value() + __path_cipher_val := bucket_metainfo_path_cipher.value() + __created_at_val := __now + __default_segment_size_val := bucket_metainfo_default_segment_size.value() + __default_encryption_cipher_suite_val := bucket_metainfo_default_encryption_cipher_suite.value() + __default_encryption_block_size_val := bucket_metainfo_default_encryption_block_size.value() + __default_redundancy_algorithm_val := bucket_metainfo_default_redundancy_algorithm.value() + __default_redundancy_share_size_val := bucket_metainfo_default_redundancy_share_size.value() + __default_redundancy_required_shares_val := bucket_metainfo_default_redundancy_required_shares.value() + __default_redundancy_repair_shares_val := bucket_metainfo_default_redundancy_repair_shares.value() + __default_redundancy_optimal_shares_val := bucket_metainfo_default_redundancy_optimal_shares.value() + __default_redundancy_total_shares_val := bucket_metainfo_default_redundancy_total_shares.value() + __placement_val := optional.Placement.value() + + var __embed_stmt = __sqlbundle_Literal("INSERT INTO bucket_metainfos ( id, project_id, name, partner_id, user_agent, path_cipher, created_at, default_segment_size, default_encryption_cipher_suite, default_encryption_block_size, default_redundancy_algorithm, default_redundancy_share_size, default_redundancy_required_shares, default_redundancy_repair_shares, default_redundancy_optimal_shares, default_redundancy_total_shares, placement ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement") + + var __values []interface{} + __values = append(__values, __id_val, __project_id_val, __name_val, __partner_id_val, __user_agent_val, __path_cipher_val, __created_at_val, __default_segment_size_val, __default_encryption_cipher_suite_val, __default_encryption_block_size_val, __default_redundancy_algorithm_val, __default_redundancy_share_size_val, __default_redundancy_required_shares_val, __default_redundancy_repair_shares_val, __default_redundancy_optimal_shares_val, __default_redundancy_total_shares_val, __placement_val) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, obj.makeErr(err) + } + return bucket_metainfo, nil + +} + +func (obj *pgxcockroachImpl) Create_ValueAttribution(ctx context.Context, + value_attribution_project_id ValueAttribution_ProjectId_Field, + value_attribution_bucket_name ValueAttribution_BucketName_Field, + value_attribution_partner_id ValueAttribution_PartnerId_Field, + optional ValueAttribution_Create_Fields) ( + value_attribution *ValueAttribution, err error) { + defer mon.Task()(&ctx)(&err) + + __now := obj.db.Hooks.Now().UTC() + __project_id_val := value_attribution_project_id.value() + __bucket_name_val := value_attribution_bucket_name.value() + __partner_id_val := value_attribution_partner_id.value() + __user_agent_val := optional.UserAgent.value() + __last_updated_val := __now + + var __embed_stmt = __sqlbundle_Literal("INSERT INTO value_attributions ( project_id, bucket_name, partner_id, user_agent, last_updated ) VALUES ( ?, ?, ?, ?, ? ) RETURNING value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated") + + var __values []interface{} + __values = append(__values, __project_id_val, __bucket_name_val, __partner_id_val, __user_agent_val, __last_updated_val) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + value_attribution = &ValueAttribution{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) + if err != nil { + return nil, obj.makeErr(err) + } + return value_attribution, nil + +} + func (obj *pgxcockroachImpl) Create_User(ctx context.Context, user_id User_Id_Field, user_email User_Email_Field, @@ -22211,265 +22238,6 @@ func (obj *pgxcockroachImpl) Get_OauthToken_By_Kind_And_Token(ctx context.Contex } -func (obj *pgxcockroachImpl) Get_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return (*BucketMetainfo)(nil), obj.makeErr(err) - } - return bucket_metainfo, nil - -} - -func (obj *pgxcockroachImpl) Get_BucketMetainfo_CreatedAt_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *CreatedAt_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.created_at FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &CreatedAt_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.CreatedAt) - if err != nil { - return (*CreatedAt_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxcockroachImpl) Get_BucketMetainfo_Id_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *Id_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &Id_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Id) - if err != nil { - return (*Id_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxcockroachImpl) Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - row *Placement_Row, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - row = &Placement_Row{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Placement) - if err != nil { - return (*Placement_Row)(nil), obj.makeErr(err) - } - return row, nil - -} - -func (obj *pgxcockroachImpl) Has_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - has bool, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT EXISTS( SELECT 1 FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? )") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&has) - if err != nil { - return false, obj.makeErr(err) - } - return has, nil - -} - -func (obj *pgxcockroachImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_GreaterOrEqual_OrderBy_Asc_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name_greater_or_equal BucketMetainfo_Name_Field, - limit int, offset int64) ( - rows []*BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name >= ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater_or_equal.value()) - - __values = append(__values, limit, offset) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - for { - rows, err = func() (rows []*BucketMetainfo, err error) { - __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) - if err != nil { - return nil, err - } - defer __rows.Close() - - for __rows.Next() { - bucket_metainfo := &BucketMetainfo{} - err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, err - } - rows = append(rows, bucket_metainfo) - } - err = __rows.Err() - if err != nil { - return nil, err - } - return rows, nil - }() - if err != nil { - if obj.shouldRetry(err) { - continue - } - return nil, obj.makeErr(err) - } - return rows, nil - } - -} - -func (obj *pgxcockroachImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_Greater_OrderBy_Asc_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name_greater BucketMetainfo_Name_Field, - limit int, offset int64) ( - rows []*BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name > ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater.value()) - - __values = append(__values, limit, offset) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - for { - rows, err = func() (rows []*BucketMetainfo, err error) { - __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) - if err != nil { - return nil, err - } - defer __rows.Close() - - for __rows.Next() { - bucket_metainfo := &BucketMetainfo{} - err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err != nil { - return nil, err - } - rows = append(rows, bucket_metainfo) - } - err = __rows.Err() - if err != nil { - return nil, err - } - return rows, nil - }() - if err != nil { - if obj.shouldRetry(err) { - continue - } - return nil, obj.makeErr(err) - } - return rows, nil - } - -} - -func (obj *pgxcockroachImpl) Count_BucketMetainfo_Name_By_ProjectId(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field) ( - count int64, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT COUNT(*) FROM bucket_metainfos WHERE bucket_metainfos.project_id = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&count) - if err != nil { - return 0, obj.makeErr(err) - } - - return count, nil - -} - -func (obj *pgxcockroachImpl) Get_ValueAttribution_By_ProjectId_And_BucketName(ctx context.Context, - value_attribution_project_id ValueAttribution_ProjectId_Field, - value_attribution_bucket_name ValueAttribution_BucketName_Field) ( - value_attribution *ValueAttribution, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("SELECT value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated FROM value_attributions WHERE value_attributions.project_id = ? AND value_attributions.bucket_name = ?") - - var __values []interface{} - __values = append(__values, value_attribution_project_id.value(), value_attribution_bucket_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - value_attribution = &ValueAttribution{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) - if err != nil { - return (*ValueAttribution)(nil), obj.makeErr(err) - } - return value_attribution, nil - -} - func (obj *pgxcockroachImpl) Get_Project_Salt_By_Id(ctx context.Context, project_id Project_Id_Field) ( row *Salt_Row, err error) { @@ -23070,6 +22838,288 @@ func (obj *pgxcockroachImpl) Get_ApiKey_By_Name_And_ProjectId(ctx context.Contex } +func (obj *pgxcockroachImpl) Get_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return (*BucketMetainfo)(nil), obj.makeErr(err) + } + return bucket_metainfo, nil + +} + +func (obj *pgxcockroachImpl) Get_BucketMetainfo_CreatedAt_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *CreatedAt_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.created_at FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &CreatedAt_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.CreatedAt) + if err != nil { + return (*CreatedAt_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxcockroachImpl) Get_BucketMetainfo_Id_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *Id_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &Id_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Id) + if err != nil { + return (*Id_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxcockroachImpl) Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *Placement_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &Placement_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.Placement) + if err != nil { + return (*Placement_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxcockroachImpl) Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *UserAgent_Row, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.user_agent FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + row = &UserAgent_Row{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&row.UserAgent) + if err != nil { + return (*UserAgent_Row)(nil), obj.makeErr(err) + } + return row, nil + +} + +func (obj *pgxcockroachImpl) Has_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + has bool, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT EXISTS( SELECT 1 FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? )") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&has) + if err != nil { + return false, obj.makeErr(err) + } + return has, nil + +} + +func (obj *pgxcockroachImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_GreaterOrEqual_OrderBy_Asc_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name_greater_or_equal BucketMetainfo_Name_Field, + limit int, offset int64) ( + rows []*BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name >= ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater_or_equal.value()) + + __values = append(__values, limit, offset) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + for { + rows, err = func() (rows []*BucketMetainfo, err error) { + __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) + if err != nil { + return nil, err + } + defer __rows.Close() + + for __rows.Next() { + bucket_metainfo := &BucketMetainfo{} + err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, err + } + rows = append(rows, bucket_metainfo) + } + err = __rows.Err() + if err != nil { + return nil, err + } + return rows, nil + }() + if err != nil { + if obj.shouldRetry(err) { + continue + } + return nil, obj.makeErr(err) + } + return rows, nil + } + +} + +func (obj *pgxcockroachImpl) Limited_BucketMetainfo_By_ProjectId_And_Name_Greater_OrderBy_Asc_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name_greater BucketMetainfo_Name_Field, + limit int, offset int64) ( + rows []*BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name > ? ORDER BY bucket_metainfos.name LIMIT ? OFFSET ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name_greater.value()) + + __values = append(__values, limit, offset) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + for { + rows, err = func() (rows []*BucketMetainfo, err error) { + __rows, err := obj.driver.QueryContext(ctx, __stmt, __values...) + if err != nil { + return nil, err + } + defer __rows.Close() + + for __rows.Next() { + bucket_metainfo := &BucketMetainfo{} + err = __rows.Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err != nil { + return nil, err + } + rows = append(rows, bucket_metainfo) + } + err = __rows.Err() + if err != nil { + return nil, err + } + return rows, nil + }() + if err != nil { + if obj.shouldRetry(err) { + continue + } + return nil, obj.makeErr(err) + } + return rows, nil + } + +} + +func (obj *pgxcockroachImpl) Count_BucketMetainfo_Name_By_ProjectId(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field) ( + count int64, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT COUNT(*) FROM bucket_metainfos WHERE bucket_metainfos.project_id = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&count) + if err != nil { + return 0, obj.makeErr(err) + } + + return count, nil + +} + +func (obj *pgxcockroachImpl) Get_ValueAttribution_By_ProjectId_And_BucketName(ctx context.Context, + value_attribution_project_id ValueAttribution_ProjectId_Field, + value_attribution_bucket_name ValueAttribution_BucketName_Field) ( + value_attribution *ValueAttribution, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("SELECT value_attributions.project_id, value_attributions.bucket_name, value_attributions.partner_id, value_attributions.user_agent, value_attributions.last_updated FROM value_attributions WHERE value_attributions.project_id = ? AND value_attributions.bucket_name = ?") + + var __values []interface{} + __values = append(__values, value_attribution_project_id.value(), value_attribution_bucket_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + value_attribution = &ValueAttribution{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&value_attribution.ProjectId, &value_attribution.BucketName, &value_attribution.PartnerId, &value_attribution.UserAgent, &value_attribution.LastUpdated) + if err != nil { + return (*ValueAttribution)(nil), obj.makeErr(err) + } + return value_attribution, nil + +} + func (obj *pgxcockroachImpl) All_User_By_NormalizedEmail(ctx context.Context, user_normalized_email User_NormalizedEmail_Field) ( rows []*User, err error) { @@ -24848,103 +24898,6 @@ func (obj *pgxcockroachImpl) UpdateNoReturn_OauthToken_By_Token_And_Kind(ctx con return nil } -func (obj *pgxcockroachImpl) Update_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field, - update BucketMetainfo_Update_Fields) ( - bucket_metainfo *BucketMetainfo, err error) { - defer mon.Task()(&ctx)(&err) - var __sets = &__sqlbundle_Hole{} - - var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE bucket_metainfos SET "), __sets, __sqlbundle_Literal(" WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement")}} - - __sets_sql := __sqlbundle_Literals{Join: ", "} - var __values []interface{} - var __args []interface{} - - if update.PartnerId._set { - __values = append(__values, update.PartnerId.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("partner_id = ?")) - } - - if update.UserAgent._set { - __values = append(__values, update.UserAgent.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("user_agent = ?")) - } - - if update.DefaultSegmentSize._set { - __values = append(__values, update.DefaultSegmentSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_segment_size = ?")) - } - - if update.DefaultEncryptionCipherSuite._set { - __values = append(__values, update.DefaultEncryptionCipherSuite.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_cipher_suite = ?")) - } - - if update.DefaultEncryptionBlockSize._set { - __values = append(__values, update.DefaultEncryptionBlockSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_block_size = ?")) - } - - if update.DefaultRedundancyAlgorithm._set { - __values = append(__values, update.DefaultRedundancyAlgorithm.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_algorithm = ?")) - } - - if update.DefaultRedundancyShareSize._set { - __values = append(__values, update.DefaultRedundancyShareSize.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_share_size = ?")) - } - - if update.DefaultRedundancyRequiredShares._set { - __values = append(__values, update.DefaultRedundancyRequiredShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_required_shares = ?")) - } - - if update.DefaultRedundancyRepairShares._set { - __values = append(__values, update.DefaultRedundancyRepairShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_repair_shares = ?")) - } - - if update.DefaultRedundancyOptimalShares._set { - __values = append(__values, update.DefaultRedundancyOptimalShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_optimal_shares = ?")) - } - - if update.DefaultRedundancyTotalShares._set { - __values = append(__values, update.DefaultRedundancyTotalShares.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_total_shares = ?")) - } - - if update.Placement._set { - __values = append(__values, update.Placement.value()) - __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("placement = ?")) - } - - if len(__sets_sql.SQLs) == 0 { - return nil, emptyUpdate() - } - - __args = append(__args, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - __values = append(__values, __args...) - __sets.SQL = __sets_sql - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - bucket_metainfo = &BucketMetainfo{} - err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) - if err == sql.ErrNoRows { - return nil, nil - } - if err != nil { - return nil, obj.makeErr(err) - } - return bucket_metainfo, nil -} - func (obj *pgxcockroachImpl) Update_Project_By_Id(ctx context.Context, project_id Project_Id_Field, update Project_Update_Fields) ( @@ -25068,6 +25021,103 @@ func (obj *pgxcockroachImpl) UpdateNoReturn_ApiKey_By_Id(ctx context.Context, return nil } +func (obj *pgxcockroachImpl) Update_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field, + update BucketMetainfo_Update_Fields) ( + bucket_metainfo *BucketMetainfo, err error) { + defer mon.Task()(&ctx)(&err) + var __sets = &__sqlbundle_Hole{} + + var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE bucket_metainfos SET "), __sets, __sqlbundle_Literal(" WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ? RETURNING bucket_metainfos.id, bucket_metainfos.project_id, bucket_metainfos.name, bucket_metainfos.partner_id, bucket_metainfos.user_agent, bucket_metainfos.path_cipher, bucket_metainfos.created_at, bucket_metainfos.default_segment_size, bucket_metainfos.default_encryption_cipher_suite, bucket_metainfos.default_encryption_block_size, bucket_metainfos.default_redundancy_algorithm, bucket_metainfos.default_redundancy_share_size, bucket_metainfos.default_redundancy_required_shares, bucket_metainfos.default_redundancy_repair_shares, bucket_metainfos.default_redundancy_optimal_shares, bucket_metainfos.default_redundancy_total_shares, bucket_metainfos.placement")}} + + __sets_sql := __sqlbundle_Literals{Join: ", "} + var __values []interface{} + var __args []interface{} + + if update.PartnerId._set { + __values = append(__values, update.PartnerId.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("partner_id = ?")) + } + + if update.UserAgent._set { + __values = append(__values, update.UserAgent.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("user_agent = ?")) + } + + if update.DefaultSegmentSize._set { + __values = append(__values, update.DefaultSegmentSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_segment_size = ?")) + } + + if update.DefaultEncryptionCipherSuite._set { + __values = append(__values, update.DefaultEncryptionCipherSuite.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_cipher_suite = ?")) + } + + if update.DefaultEncryptionBlockSize._set { + __values = append(__values, update.DefaultEncryptionBlockSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_encryption_block_size = ?")) + } + + if update.DefaultRedundancyAlgorithm._set { + __values = append(__values, update.DefaultRedundancyAlgorithm.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_algorithm = ?")) + } + + if update.DefaultRedundancyShareSize._set { + __values = append(__values, update.DefaultRedundancyShareSize.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_share_size = ?")) + } + + if update.DefaultRedundancyRequiredShares._set { + __values = append(__values, update.DefaultRedundancyRequiredShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_required_shares = ?")) + } + + if update.DefaultRedundancyRepairShares._set { + __values = append(__values, update.DefaultRedundancyRepairShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_repair_shares = ?")) + } + + if update.DefaultRedundancyOptimalShares._set { + __values = append(__values, update.DefaultRedundancyOptimalShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_optimal_shares = ?")) + } + + if update.DefaultRedundancyTotalShares._set { + __values = append(__values, update.DefaultRedundancyTotalShares.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("default_redundancy_total_shares = ?")) + } + + if update.Placement._set { + __values = append(__values, update.Placement.value()) + __sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("placement = ?")) + } + + if len(__sets_sql.SQLs) == 0 { + return nil, emptyUpdate() + } + + __args = append(__args, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + __values = append(__values, __args...) + __sets.SQL = __sets_sql + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + bucket_metainfo = &BucketMetainfo{} + err = obj.queryRowContext(ctx, __stmt, __values...).Scan(&bucket_metainfo.Id, &bucket_metainfo.ProjectId, &bucket_metainfo.Name, &bucket_metainfo.PartnerId, &bucket_metainfo.UserAgent, &bucket_metainfo.PathCipher, &bucket_metainfo.CreatedAt, &bucket_metainfo.DefaultSegmentSize, &bucket_metainfo.DefaultEncryptionCipherSuite, &bucket_metainfo.DefaultEncryptionBlockSize, &bucket_metainfo.DefaultRedundancyAlgorithm, &bucket_metainfo.DefaultRedundancyShareSize, &bucket_metainfo.DefaultRedundancyRequiredShares, &bucket_metainfo.DefaultRedundancyRepairShares, &bucket_metainfo.DefaultRedundancyOptimalShares, &bucket_metainfo.DefaultRedundancyTotalShares, &bucket_metainfo.Placement) + if err == sql.ErrNoRows { + return nil, nil + } + if err != nil { + return nil, obj.makeErr(err) + } + return bucket_metainfo, nil +} + func (obj *pgxcockroachImpl) Update_User_By_Id(ctx context.Context, user_id User_Id_Field, update User_Update_Fields) ( @@ -25552,34 +25602,6 @@ func (obj *pgxcockroachImpl) Delete_OauthClient_By_Id(ctx context.Context, } -func (obj *pgxcockroachImpl) Delete_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, - bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, - bucket_metainfo_name BucketMetainfo_Name_Field) ( - deleted bool, err error) { - defer mon.Task()(&ctx)(&err) - - var __embed_stmt = __sqlbundle_Literal("DELETE FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") - - var __values []interface{} - __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) - - var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) - obj.logStmt(__stmt, __values...) - - __res, err := obj.driver.ExecContext(ctx, __stmt, __values...) - if err != nil { - return false, obj.makeErr(err) - } - - __count, err := __res.RowsAffected() - if err != nil { - return false, obj.makeErr(err) - } - - return __count > 0, nil - -} - func (obj *pgxcockroachImpl) Delete_Project_By_Id(ctx context.Context, project_id Project_Id_Field) ( deleted bool, err error) { @@ -25662,6 +25684,34 @@ func (obj *pgxcockroachImpl) Delete_ApiKey_By_Id(ctx context.Context, } +func (obj *pgxcockroachImpl) Delete_BucketMetainfo_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + deleted bool, err error) { + defer mon.Task()(&ctx)(&err) + + var __embed_stmt = __sqlbundle_Literal("DELETE FROM bucket_metainfos WHERE bucket_metainfos.project_id = ? AND bucket_metainfos.name = ?") + + var __values []interface{} + __values = append(__values, bucket_metainfo_project_id.value(), bucket_metainfo_name.value()) + + var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt) + obj.logStmt(__stmt, __values...) + + __res, err := obj.driver.ExecContext(ctx, __stmt, __values...) + if err != nil { + return false, obj.makeErr(err) + } + + __count, err := __res.RowsAffected() + if err != nil { + return false, obj.makeErr(err) + } + + return __count > 0, nil + +} + func (obj *pgxcockroachImpl) Delete_RepairQueue_By_UpdatedAt_Less(ctx context.Context, repair_queue_updated_at_less RepairQueue_UpdatedAt_Field) ( count int64, err error) { @@ -27316,6 +27366,17 @@ func (rx *Rx) Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx context.Con return tx.Get_BucketMetainfo_Placement_By_ProjectId_And_Name(ctx, bucket_metainfo_project_id, bucket_metainfo_name) } +func (rx *Rx) Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *UserAgent_Row, err error) { + var tx *Tx + if tx, err = rx.getTx(ctx); err != nil { + return + } + return tx.Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx, bucket_metainfo_project_id, bucket_metainfo_name) +} + func (rx *Rx) Get_GracefulExitProgress_By_NodeId(ctx context.Context, graceful_exit_progress_node_id GracefulExitProgress_NodeId_Field) ( graceful_exit_progress *GracefulExitProgress, err error) { @@ -28669,6 +28730,11 @@ type Methods interface { bucket_metainfo_name BucketMetainfo_Name_Field) ( row *Placement_Row, err error) + Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx context.Context, + bucket_metainfo_project_id BucketMetainfo_ProjectId_Field, + bucket_metainfo_name BucketMetainfo_Name_Field) ( + row *UserAgent_Row, err error) + Get_GracefulExitProgress_By_NodeId(ctx context.Context, graceful_exit_progress_node_id GracefulExitProgress_NodeId_Field) ( graceful_exit_progress *GracefulExitProgress, err error) diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index b488fc2c1..d7e23c4d9 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -16,6 +16,7 @@ import ( "storj.io/common/memory" "storj.io/common/pb" + "storj.io/common/useragent" "storj.io/common/uuid" "storj.io/private/dbutil" "storj.io/private/dbutil/pgutil" @@ -505,7 +506,21 @@ func (db *ProjectAccounting) GetProjectSegmentLimit(ctx context.Context, project } // GetProjectTotal retrieves project usage for a given period. -func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid.UUID, since, before time.Time) (usage *accounting.ProjectUsage, err error) { +func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid.UUID, since, before time.Time) (_ *accounting.ProjectUsage, err error) { + defer mon.Task()(&ctx)(&err) + usages, err := db.GetProjectTotalByPartner(ctx, projectID, nil, since, before) + if err != nil { + return nil, err + } + if usage, ok := usages[""]; ok { + return &usage, nil + } + return &accounting.ProjectUsage{Since: since, Before: before}, nil +} + +// GetProjectTotalByPartner retrieves project usage for a given period categorized by partner name. +// Unpartnered usage or usage for a partner not present in partnerNames is mapped to the empty string. +func (db *ProjectAccounting) GetProjectTotalByPartner(ctx context.Context, projectID uuid.UUID, partnerNames []string, since, before time.Time) (usages map[string]accounting.ProjectUsage, err error) { defer mon.Task()(&ctx)(&err) since = timeTruncateDown(since) bucketNames, err := db.getBucketsSinceAndBefore(ctx, projectID, since, before) @@ -531,16 +546,54 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid ORDER BY bucket_storage_tallies.interval_start DESC `) - bucketsTallies := make(map[string][]*accounting.BucketStorageTally) + totalEgressQuery := db.db.Rebind(` + SELECT + COALESCE(SUM(settled) + SUM(inline), 0) + FROM + bucket_bandwidth_rollups + WHERE + bucket_name = ? AND + project_id = ? AND + interval_start >= ? AND + interval_start < ? AND + action = ?; + `) + + usages = make(map[string]accounting.ProjectUsage) for _, bucket := range bucketNames { - storageTallies := make([]*accounting.BucketStorageTally, 0) + userAgentRow, err := db.db.Get_BucketMetainfo_UserAgent_By_ProjectId_And_Name(ctx, + dbx.BucketMetainfo_ProjectId(projectID[:]), + dbx.BucketMetainfo_Name([]byte(bucket))) + if err != nil && !errors.Is(err, sql.ErrNoRows) { + return nil, err + } + + var partner string + if userAgentRow != nil && userAgentRow.UserAgent != nil { + entries, err := useragent.ParseEntries(userAgentRow.UserAgent) + if err != nil { + return nil, err + } + + for _, iterPartner := range partnerNames { + if entries[0].Product == iterPartner { + partner = iterPartner + break + } + } + } + if _, ok := usages[partner]; !ok { + usages[partner] = accounting.ProjectUsage{Since: since, Before: before} + } + usage := usages[partner] storageTalliesRows, err := db.db.QueryContext(ctx, storageQuery, projectID[:], []byte(bucket), since, before) if err != nil { return nil, err } - // generating tallies for each bucket name. + + var prevTally *accounting.BucketStorageTally for storageTalliesRows.Next() { tally := accounting.BucketStorageTally{} @@ -553,8 +606,17 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid tally.TotalBytes = inline + remote } - tally.BucketName = bucket - storageTallies = append(storageTallies, &tally) + if prevTally == nil { + prevTally = &tally + continue + } + + hours := prevTally.IntervalStart.Sub(tally.IntervalStart).Hours() + usage.Storage += memory.Size(tally.TotalBytes).Float64() * hours + usage.SegmentCount += float64(tally.TotalSegmentCount) * hours + usage.ObjectCount += float64(tally.ObjectCount) * hours + + prevTally = &tally } err = errs.Combine(storageTalliesRows.Err(), storageTalliesRows.Close()) @@ -562,53 +624,21 @@ func (db *ProjectAccounting) GetProjectTotal(ctx context.Context, projectID uuid return nil, err } - bucketsTallies[bucket] = storageTallies - } - - totalEgress, err := db.getTotalEgress(ctx, projectID, since, before) - if err != nil { - return nil, err - } - - usage = new(accounting.ProjectUsage) - usage.Egress = memory.Size(totalEgress).Int64() - // sum up storage, objects, and segments - for _, tallies := range bucketsTallies { - for i := len(tallies) - 1; i > 0; i-- { - current := (tallies)[i] - hours := (tallies)[i-1].IntervalStart.Sub(current.IntervalStart).Hours() - usage.Storage += memory.Size(current.Bytes()).Float64() * hours - usage.SegmentCount += float64(current.TotalSegmentCount) * hours - usage.ObjectCount += float64(current.ObjectCount) * hours + totalEgressRow := db.db.QueryRowContext(ctx, totalEgressQuery, []byte(bucket), projectID[:], since, before, pb.PieceAction_GET) + if err != nil { + return nil, err } + + var egress int64 + if err = totalEgressRow.Scan(&egress); err != nil { + return nil, err + } + usage.Egress += egress + + usages[partner] = usage } - usage.Since = since - usage.Before = before - return usage, nil -} - -// getTotalEgress returns total egress (settled + inline) of each bucket_bandwidth_rollup -// in selected time period, project id. -// only process PieceAction_GET. -func (db *ProjectAccounting) getTotalEgress(ctx context.Context, projectID uuid.UUID, since, before time.Time) (totalEgress int64, err error) { - totalEgressQuery := db.db.Rebind(` - SELECT - COALESCE(SUM(settled) + SUM(inline), 0) - FROM - bucket_bandwidth_rollups - WHERE - project_id = ? AND - interval_start >= ? AND - interval_start < ? AND - action = ?; - `) - - totalEgressRow := db.db.QueryRowContext(ctx, totalEgressQuery, projectID[:], since, before, pb.PieceAction_GET) - - err = totalEgressRow.Scan(&totalEgress) - - return totalEgress, err + return usages, nil } // GetBucketUsageRollups retrieves summed usage rollups for every bucket of particular project for a given period. @@ -1010,31 +1040,45 @@ func (db *ProjectAccounting) archiveRollupsBeforeByAction(ctx context.Context, a } // getBucketsSinceAndBefore lists distinct bucket names for a project within a specific timeframe. -func (db *ProjectAccounting) getBucketsSinceAndBefore(ctx context.Context, projectID uuid.UUID, since, before time.Time) (_ []string, err error) { +func (db *ProjectAccounting) getBucketsSinceAndBefore(ctx context.Context, projectID uuid.UUID, since, before time.Time) (buckets []string, err error) { defer mon.Task()(&ctx)(&err) - bucketsQuery := db.db.Rebind(`SELECT DISTINCT bucket_name - FROM bucket_storage_tallies + + queryFormat := `SELECT DISTINCT bucket_name + FROM %s WHERE project_id = ? AND interval_start >= ? - AND interval_start < ?`) - bucketRows, err := db.db.QueryContext(ctx, bucketsQuery, projectID[:], since, before) - if err != nil { - return nil, err - } - defer func() { err = errs.Combine(err, bucketRows.Close()) }() + AND interval_start < ?` - var buckets []string - for bucketRows.Next() { - var bucket string - err = bucketRows.Scan(&bucket) + bucketMap := make(map[string]struct{}) + + for _, tableName := range []string{"bucket_storage_tallies", "bucket_bandwidth_rollups"} { + query := db.db.Rebind(fmt.Sprintf(queryFormat, tableName)) + + rows, err := db.db.QueryContext(ctx, query, projectID[:], since, before) if err != nil { return nil, err } + for rows.Next() { + var bucket string + err = rows.Scan(&bucket) + if err != nil { + return nil, errs.Combine(err, rows.Close()) + } + bucketMap[bucket] = struct{}{} + } + + err = errs.Combine(rows.Err(), rows.Close()) + if err != nil { + return nil, err + } + } + + for bucket := range bucketMap { buckets = append(buckets, bucket) } - return buckets, bucketRows.Err() + return buckets, nil } // timeTruncateDown truncates down to the hour before to be in sync with orders endpoint. diff --git a/satellite/satellitedb/projectaccounting_test.go b/satellite/satellitedb/projectaccounting_test.go index 03419e3d8..f9684b2d0 100644 --- a/satellite/satellitedb/projectaccounting_test.go +++ b/satellite/satellitedb/projectaccounting_test.go @@ -11,6 +11,7 @@ import ( "storj.io/common/memory" "storj.io/common/pb" + "storj.io/common/storj" "storj.io/common/testcontext" "storj.io/common/testrand" "storj.io/storj/private/testplanet" @@ -174,74 +175,169 @@ func Test_GetSingleBucketRollup(t *testing.T) { ) } -func Test_GetProjectTotal(t *testing.T) { +func Test_GetProjectTotalByPartner(t *testing.T) { + const ( + epsilon = 1e-8 + usagePeriod = time.Hour + tallyRollupCount = 2 + ) + since := time.Time{} + before := since.Add(2 * usagePeriod) + testplanet.Run(t, testplanet.Config{SatelliteCount: 1, StorageNodeCount: 1}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) { - bucketName := testrand.BucketName() - projectID := testrand.UUID() + sat := planet.Satellites[0] - db := planet.Satellites[0].DB + user, err := sat.AddUser(ctx, console.CreateUser{ + FullName: "Test User", + Email: "user@mail.test", + }, 1) + require.NoError(t, err) - // The 3rd tally is only present to prevent CreateStorageTally from skipping the 2nd. - var tallies []accounting.BucketStorageTally - for i := 0; i < 3; i++ { - tally := accounting.BucketStorageTally{ - BucketName: bucketName, - ProjectID: projectID, - IntervalStart: time.Time{}.Add(time.Duration(i) * time.Hour), - TotalBytes: int64(testrand.Intn(1000)), - ObjectCount: int64(testrand.Intn(1000)), - TotalSegmentCount: int64(testrand.Intn(1000)), - } - tallies = append(tallies, tally) - require.NoError(t, db.ProjectAccounting().CreateStorageTally(ctx, tally)) + project, err := sat.AddProject(ctx, user.ID, "testproject") + require.NoError(t, err) + + type expectedTotal struct { + storage float64 + segments float64 + objects float64 + egress int64 + } + expectedTotals := make(map[string]expectedTotal) + var beforeTotal expectedTotal + + requireTotal := func(t *testing.T, expected expectedTotal, actual accounting.ProjectUsage) { + require.InDelta(t, expected.storage, actual.Storage, epsilon) + require.InDelta(t, expected.segments, actual.SegmentCount, epsilon) + require.InDelta(t, expected.objects, actual.ObjectCount, epsilon) + require.Equal(t, expected.egress, actual.Egress) + require.Equal(t, since, actual.Since) + require.Equal(t, before, actual.Before) } - var rollups []orders.BucketBandwidthRollup - var expectedEgress int64 - for i := 0; i < 2; i++ { - rollup := orders.BucketBandwidthRollup{ - ProjectID: projectID, - BucketName: bucketName, - Action: pb.PieceAction_GET, - IntervalStart: tallies[i].IntervalStart, - Inline: int64(testrand.Intn(1000)), - Settled: int64(testrand.Intn(1000)), + partnerNames := []string{"", "partner1", "partner2"} + for _, name := range partnerNames { + total := expectedTotal{} + + bucket := storj.Bucket{ + ID: testrand.UUID(), + Name: testrand.BucketName(), + ProjectID: project.ID, } - rollups = append(rollups, rollup) - expectedEgress += rollup.Inline + rollup.Settled + if name != "" { + bucket.UserAgent = []byte(name) + } + _, err := sat.DB.Buckets().CreateBucket(ctx, bucket) + require.NoError(t, err) + + // We use multiple tallies and rollups to ensure that + // GetProjectTotalByPartner is capable of summing them. + for i := 0; i <= tallyRollupCount; i++ { + tally := accounting.BucketStorageTally{ + BucketName: bucket.Name, + ProjectID: project.ID, + IntervalStart: since.Add(time.Duration(i) * usagePeriod / tallyRollupCount), + TotalBytes: int64(testrand.Intn(1000)), + ObjectCount: int64(testrand.Intn(1000)), + TotalSegmentCount: int64(testrand.Intn(1000)), + } + require.NoError(t, sat.DB.ProjectAccounting().CreateStorageTally(ctx, tally)) + + // The last tally's usage data is unused. + usageHours := (usagePeriod / tallyRollupCount).Hours() + if i < tallyRollupCount { + total.storage += float64(tally.Bytes()) * usageHours + total.objects += float64(tally.ObjectCount) * usageHours + total.segments += float64(tally.TotalSegmentCount) * usageHours + } + + if i < tallyRollupCount-1 { + beforeTotal.storage += float64(tally.Bytes()) * usageHours + beforeTotal.objects += float64(tally.ObjectCount) * usageHours + beforeTotal.segments += float64(tally.TotalSegmentCount) * usageHours + } + } + + var rollups []orders.BucketBandwidthRollup + for i := 0; i < tallyRollupCount; i++ { + rollup := orders.BucketBandwidthRollup{ + BucketName: bucket.Name, + ProjectID: project.ID, + Action: pb.PieceAction_GET, + IntervalStart: since.Add(time.Duration(i) * usagePeriod / tallyRollupCount), + Inline: int64(testrand.Intn(1000)), + Settled: int64(testrand.Intn(1000)), + } + rollups = append(rollups, rollup) + total.egress += rollup.Inline + rollup.Settled + + if i < tallyRollupCount { + beforeTotal.egress += rollup.Inline + rollup.Settled + } + } + require.NoError(t, sat.DB.Orders().UpdateBandwidthBatch(ctx, rollups)) + + expectedTotals[name] = total } - require.NoError(t, db.Orders().UpdateBandwidthBatch(ctx, rollups)) - usage, err := db.ProjectAccounting().GetProjectTotal(ctx, projectID, tallies[0].IntervalStart, tallies[2].IntervalStart.Add(time.Minute)) - require.NoError(t, err) + t.Run("sum all partner usages", func(t *testing.T) { + usages, err := sat.DB.ProjectAccounting().GetProjectTotalByPartner(ctx, project.ID, nil, since, before) + require.NoError(t, err) + require.Len(t, usages, 1) + require.Contains(t, usages, "") - const epsilon = 1e-8 - require.InDelta(t, usage.Storage, float64(tallies[0].Bytes()+tallies[1].Bytes()), epsilon) - require.InDelta(t, usage.SegmentCount, float64(tallies[0].TotalSegmentCount+tallies[1].TotalSegmentCount), epsilon) - require.InDelta(t, usage.ObjectCount, float64(tallies[0].ObjectCount+tallies[1].ObjectCount), epsilon) - require.Equal(t, usage.Egress, expectedEgress) - require.Equal(t, usage.Since, tallies[0].IntervalStart) - require.Equal(t, usage.Before, tallies[2].IntervalStart.Add(time.Minute)) + var summedTotal expectedTotal + for _, total := range expectedTotals { + summedTotal.storage += total.storage + summedTotal.segments += total.segments + summedTotal.objects += total.objects + summedTotal.egress += total.egress + } - // Ensure that GetProjectTotal treats the 'before' arg as exclusive - usage, err = db.ProjectAccounting().GetProjectTotal(ctx, projectID, tallies[0].IntervalStart, tallies[2].IntervalStart) - require.NoError(t, err) - require.InDelta(t, usage.Storage, float64(tallies[0].Bytes()), epsilon) - require.InDelta(t, usage.SegmentCount, float64(tallies[0].TotalSegmentCount), epsilon) - require.InDelta(t, usage.ObjectCount, float64(tallies[0].ObjectCount), epsilon) - require.Equal(t, usage.Egress, expectedEgress) - require.Equal(t, usage.Since, tallies[0].IntervalStart) - require.Equal(t, usage.Before, tallies[2].IntervalStart) + requireTotal(t, summedTotal, usages[""]) + }) - usage, err = db.ProjectAccounting().GetProjectTotal(ctx, projectID, rollups[0].IntervalStart, rollups[1].IntervalStart) - require.NoError(t, err) - require.Zero(t, usage.Storage) - require.Zero(t, usage.SegmentCount) - require.Zero(t, usage.ObjectCount) - require.Equal(t, usage.Egress, rollups[0].Inline+rollups[0].Settled) - require.Equal(t, usage.Since, rollups[0].IntervalStart) - require.Equal(t, usage.Before, rollups[1].IntervalStart) + t.Run("individual partner usages", func(t *testing.T) { + usages, err := sat.DB.ProjectAccounting().GetProjectTotalByPartner(ctx, project.ID, partnerNames, since, before) + require.NoError(t, err) + require.Len(t, usages, len(expectedTotals)) + for _, name := range partnerNames { + require.Contains(t, usages, name) + } + + for partner, usage := range usages { + requireTotal(t, expectedTotals[partner], usage) + } + }) + + t.Run("select one partner usage and sum remaining usages", func(t *testing.T) { + partner := partnerNames[len(partnerNames)-1] + usages, err := sat.DB.ProjectAccounting().GetProjectTotalByPartner(ctx, project.ID, []string{partner}, since, before) + require.NoError(t, err) + require.Len(t, usages, 2) + require.Contains(t, usages, "") + require.Contains(t, usages, partner) + + var summedTotal expectedTotal + for _, partner := range partnerNames[:len(partnerNames)-1] { + summedTotal.storage += expectedTotals[partner].storage + summedTotal.segments += expectedTotals[partner].segments + summedTotal.objects += expectedTotals[partner].objects + summedTotal.egress += expectedTotals[partner].egress + } + + requireTotal(t, expectedTotals[partner], usages[partner]) + requireTotal(t, summedTotal, usages[""]) + }) + + t.Run("ensure before is exclusive", func(t *testing.T) { + before = since.Add(usagePeriod) + usages, err := sat.DB.ProjectAccounting().GetProjectTotalByPartner(ctx, project.ID, nil, since, before) + require.NoError(t, err) + require.Len(t, usages, 1) + require.Contains(t, usages, "") + requireTotal(t, beforeTotal, usages[""]) + }) }, ) }