Add statistics on the sync and save org ID with fieldseeker tables

We need the org ID so that we can avoid bleedover between different
organizations.
This commit is contained in:
Eli Ribble 2025-11-07 09:30:31 +00:00
parent bf6e40d877
commit b0432f3243
No known key found for this signature in database
178 changed files with 9075 additions and 6223 deletions

View file

@ -37,7 +37,7 @@ func (mods FSSpeciesabundanceModSlice) Apply(ctx context.Context, n *FSSpeciesab
// FSSpeciesabundanceTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type FSSpeciesabundanceTemplate struct {
OrganizationID func() null.Val[int32]
OrganizationID func() int32
Bloodedfem func() null.Val[int16]
Creationdate func() null.Val[int64]
Creator func() null.Val[string]
@ -98,7 +98,7 @@ func (t FSSpeciesabundanceTemplate) setModelRels(o *models.FSSpeciesabundance) {
if t.r.Organization != nil {
rel := t.r.Organization.o.Build()
rel.R.FSSpeciesabundances = append(rel.R.FSSpeciesabundances, o)
o.OrganizationID = null.From(rel.ID) // h2
o.OrganizationID = rel.ID // h2
o.R.Organization = rel
}
}
@ -110,7 +110,7 @@ func (o FSSpeciesabundanceTemplate) BuildSetter() *models.FSSpeciesabundanceSett
if o.OrganizationID != nil {
val := o.OrganizationID()
m.OrganizationID = omitnull.FromNull(val)
m.OrganizationID = omit.From(val)
}
if o.Bloodedfem != nil {
val := o.Bloodedfem()
@ -381,6 +381,10 @@ func (o FSSpeciesabundanceTemplate) BuildMany(number int) models.FSSpeciesabunda
}
func ensureCreatableFSSpeciesabundance(m *models.FSSpeciesabundanceSetter) {
if !(m.OrganizationID.IsValue()) {
val := random_int32(nil)
m.OrganizationID = omit.From(val)
}
if !(m.Objectid.IsValue()) {
val := random_int32(nil)
m.Objectid = omit.From(val)
@ -393,25 +397,6 @@ func ensureCreatableFSSpeciesabundance(m *models.FSSpeciesabundanceSetter) {
func (o *FSSpeciesabundanceTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FSSpeciesabundance) error {
var err error
isOrganizationDone, _ := fsSpeciesabundanceRelOrganizationCtx.Value(ctx)
if !isOrganizationDone && o.r.Organization != nil {
ctx = fsSpeciesabundanceRelOrganizationCtx.WithValue(ctx, true)
if o.r.Organization.o.alreadyPersisted {
m.R.Organization = o.r.Organization.o.Build()
} else {
var rel0 *models.Organization
rel0, err = o.r.Organization.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachOrganization(ctx, exec, rel0)
if err != nil {
return err
}
}
}
return err
}
@ -422,11 +407,30 @@ func (o *FSSpeciesabundanceTemplate) Create(ctx context.Context, exec bob.Execut
opt := o.BuildSetter()
ensureCreatableFSSpeciesabundance(opt)
if o.r.Organization == nil {
FSSpeciesabundanceMods.WithNewOrganization().Apply(ctx, o)
}
var rel0 *models.Organization
if o.r.Organization.o.alreadyPersisted {
rel0 = o.r.Organization.o.Build()
} else {
rel0, err = o.r.Organization.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.OrganizationID = omit.From(rel0.ID)
m, err := models.FSSpeciesabundances.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Organization = rel0
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
@ -541,14 +545,14 @@ func (m fsSpeciesabundanceMods) RandomizeAllColumns(f *faker.Faker) FSSpeciesabu
}
// Set the model columns to this value
func (m fsSpeciesabundanceMods) OrganizationID(val null.Val[int32]) FSSpeciesabundanceMod {
func (m fsSpeciesabundanceMods) OrganizationID(val int32) FSSpeciesabundanceMod {
return FSSpeciesabundanceModFunc(func(_ context.Context, o *FSSpeciesabundanceTemplate) {
o.OrganizationID = func() null.Val[int32] { return val }
o.OrganizationID = func() int32 { return val }
})
}
// Set the Column from the function
func (m fsSpeciesabundanceMods) OrganizationIDFunc(f func() null.Val[int32]) FSSpeciesabundanceMod {
func (m fsSpeciesabundanceMods) OrganizationIDFunc(f func() int32) FSSpeciesabundanceMod {
return FSSpeciesabundanceModFunc(func(_ context.Context, o *FSSpeciesabundanceTemplate) {
o.OrganizationID = f
})
@ -563,32 +567,10 @@ func (m fsSpeciesabundanceMods) UnsetOrganizationID() FSSpeciesabundanceMod {
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m fsSpeciesabundanceMods) RandomOrganizationID(f *faker.Faker) FSSpeciesabundanceMod {
return FSSpeciesabundanceModFunc(func(_ context.Context, o *FSSpeciesabundanceTemplate) {
o.OrganizationID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m fsSpeciesabundanceMods) RandomOrganizationIDNotNull(f *faker.Faker) FSSpeciesabundanceMod {
return FSSpeciesabundanceModFunc(func(_ context.Context, o *FSSpeciesabundanceTemplate) {
o.OrganizationID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
o.OrganizationID = func() int32 {
return random_int32(f)
}
})
}