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:
parent
bf6e40d877
commit
b0432f3243
178 changed files with 9075 additions and 6223 deletions
|
|
@ -37,7 +37,7 @@ func (mods FSProposedtreatmentareaModSlice) Apply(ctx context.Context, n *FSProp
|
|||
// FSProposedtreatmentareaTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type FSProposedtreatmentareaTemplate struct {
|
||||
OrganizationID func() null.Val[int32]
|
||||
OrganizationID func() int32
|
||||
Acres func() null.Val[float64]
|
||||
Comments func() null.Val[string]
|
||||
Completed func() null.Val[int16]
|
||||
|
|
@ -102,7 +102,7 @@ func (t FSProposedtreatmentareaTemplate) setModelRels(o *models.FSProposedtreatm
|
|||
if t.r.Organization != nil {
|
||||
rel := t.r.Organization.o.Build()
|
||||
rel.R.FSProposedtreatmentareas = append(rel.R.FSProposedtreatmentareas, o)
|
||||
o.OrganizationID = null.From(rel.ID) // h2
|
||||
o.OrganizationID = rel.ID // h2
|
||||
o.R.Organization = rel
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ func (o FSProposedtreatmentareaTemplate) BuildSetter() *models.FSProposedtreatme
|
|||
|
||||
if o.OrganizationID != nil {
|
||||
val := o.OrganizationID()
|
||||
m.OrganizationID = omitnull.FromNull(val)
|
||||
m.OrganizationID = omit.From(val)
|
||||
}
|
||||
if o.Acres != nil {
|
||||
val := o.Acres()
|
||||
|
|
@ -413,6 +413,10 @@ func (o FSProposedtreatmentareaTemplate) BuildMany(number int) models.FSProposed
|
|||
}
|
||||
|
||||
func ensureCreatableFSProposedtreatmentarea(m *models.FSProposedtreatmentareaSetter) {
|
||||
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)
|
||||
|
|
@ -425,25 +429,6 @@ func ensureCreatableFSProposedtreatmentarea(m *models.FSProposedtreatmentareaSet
|
|||
func (o *FSProposedtreatmentareaTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FSProposedtreatmentarea) error {
|
||||
var err error
|
||||
|
||||
isOrganizationDone, _ := fsProposedtreatmentareaRelOrganizationCtx.Value(ctx)
|
||||
if !isOrganizationDone && o.r.Organization != nil {
|
||||
ctx = fsProposedtreatmentareaRelOrganizationCtx.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
|
||||
}
|
||||
|
||||
|
|
@ -454,11 +439,30 @@ func (o *FSProposedtreatmentareaTemplate) Create(ctx context.Context, exec bob.E
|
|||
opt := o.BuildSetter()
|
||||
ensureCreatableFSProposedtreatmentarea(opt)
|
||||
|
||||
if o.r.Organization == nil {
|
||||
FSProposedtreatmentareaMods.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.FSProposedtreatmentareas.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
|
||||
}
|
||||
|
|
@ -577,14 +581,14 @@ func (m fsProposedtreatmentareaMods) RandomizeAllColumns(f *faker.Faker) FSPropo
|
|||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m fsProposedtreatmentareaMods) OrganizationID(val null.Val[int32]) FSProposedtreatmentareaMod {
|
||||
func (m fsProposedtreatmentareaMods) OrganizationID(val int32) FSProposedtreatmentareaMod {
|
||||
return FSProposedtreatmentareaModFunc(func(_ context.Context, o *FSProposedtreatmentareaTemplate) {
|
||||
o.OrganizationID = func() null.Val[int32] { return val }
|
||||
o.OrganizationID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m fsProposedtreatmentareaMods) OrganizationIDFunc(f func() null.Val[int32]) FSProposedtreatmentareaMod {
|
||||
func (m fsProposedtreatmentareaMods) OrganizationIDFunc(f func() int32) FSProposedtreatmentareaMod {
|
||||
return FSProposedtreatmentareaModFunc(func(_ context.Context, o *FSProposedtreatmentareaTemplate) {
|
||||
o.OrganizationID = f
|
||||
})
|
||||
|
|
@ -599,32 +603,10 @@ func (m fsProposedtreatmentareaMods) UnsetOrganizationID() FSProposedtreatmentar
|
|||
|
||||
// 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 fsProposedtreatmentareaMods) RandomOrganizationID(f *faker.Faker) FSProposedtreatmentareaMod {
|
||||
return FSProposedtreatmentareaModFunc(func(_ context.Context, o *FSProposedtreatmentareaTemplate) {
|
||||
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 fsProposedtreatmentareaMods) RandomOrganizationIDNotNull(f *faker.Faker) FSProposedtreatmentareaMod {
|
||||
return FSProposedtreatmentareaModFunc(func(_ context.Context, o *FSProposedtreatmentareaTemplate) {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue