Move comms work to background goroutine

This is a sort of random checkpoint of work
 * add schema for tracking messages sent to DB
 * add terms of service and privacy policy for RCS compliance
 * standardize some things about background workers
 * update some missing stuff from generated DB code
This commit is contained in:
Eli Ribble 2026-01-20 17:10:22 +00:00
parent 8f44e57c72
commit 842e6cff43
No known key found for this signature in database
47 changed files with 7361 additions and 179 deletions

View file

@ -17,6 +17,26 @@ var (
arcgisUserPrivilegeWithParentsCascadingCtx = newContextual[bool]("arcgisUserPrivilegeWithParentsCascading")
arcgisUserPrivilegeRelUserUserCtx = newContextual[bool]("arcgis.user_.arcgis.user_privilege.arcgis.user_privilege.user_privilege_user_id_fkey")
// Relationship Contexts for comms.email
commsEmailWithParentsCascadingCtx = newContextual[bool]("commsEmailWithParentsCascading")
commsEmailRelDestinationEmailLogsCtx = newContextual[bool]("comms.email.comms.email_log.comms.email_log.email_log_destination_fkey")
// Relationship Contexts for comms.email_log
commsEmailLogWithParentsCascadingCtx = newContextual[bool]("commsEmailLogWithParentsCascading")
commsEmailLogRelDestinationEmailCtx = newContextual[bool]("comms.email.comms.email_log.comms.email_log.email_log_destination_fkey")
commsEmailLogRelSourcePhoneCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey")
// Relationship Contexts for comms.phone
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
commsPhoneRelSourceEmailLogsCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey")
commsPhoneRelDestinationSMSLogsCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_destination_fkey")
commsPhoneRelSourceSMSLogsCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_source_fkey")
// Relationship Contexts for comms.sms_log
commsSMSLogWithParentsCascadingCtx = newContextual[bool]("commsSMSLogWithParentsCascading")
commsSMSLogRelDestinationPhoneCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_destination_fkey")
commsSMSLogRelSourcePhoneCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_source_fkey")
// Relationship Contexts for fieldseeker.containerrelate
fieldseekerContainerrelateWithParentsCascadingCtx = newContextual[bool]("fieldseekerContainerrelateWithParentsCascading")
fieldseekerContainerrelateRelOrganizationCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")

View file

@ -20,6 +20,10 @@ import (
type Factory struct {
baseArcgisUserMods ArcgisUserModSlice
baseArcgisUserPrivilegeMods ArcgisUserPrivilegeModSlice
baseCommsEmailMods CommsEmailModSlice
baseCommsEmailLogMods CommsEmailLogModSlice
baseCommsPhoneMods CommsPhoneModSlice
baseCommsSMSLogMods CommsSMSLogModSlice
baseFieldseekerContainerrelateMods FieldseekerContainerrelateModSlice
baseFieldseekerFieldscoutinglogMods FieldseekerFieldscoutinglogModSlice
baseFieldseekerHabitatrelateMods FieldseekerHabitatrelateModSlice
@ -156,6 +160,143 @@ func (f *Factory) FromExistingArcgisUserPrivilege(m *models.ArcgisUserPrivilege)
return o
}
func (f *Factory) NewCommsEmail(mods ...CommsEmailMod) *CommsEmailTemplate {
return f.NewCommsEmailWithContext(context.Background(), mods...)
}
func (f *Factory) NewCommsEmailWithContext(ctx context.Context, mods ...CommsEmailMod) *CommsEmailTemplate {
o := &CommsEmailTemplate{f: f}
if f != nil {
f.baseCommsEmailMods.Apply(ctx, o)
}
CommsEmailModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingCommsEmail(m *models.CommsEmail) *CommsEmailTemplate {
o := &CommsEmailTemplate{f: f, alreadyPersisted: true}
o.Address = func() string { return m.Address }
o.Confirmed = func() bool { return m.Confirmed }
o.IsSubscribed = func() bool { return m.IsSubscribed }
ctx := context.Background()
if len(m.R.DestinationEmailLogs) > 0 {
CommsEmailMods.AddExistingDestinationEmailLogs(m.R.DestinationEmailLogs...).Apply(ctx, o)
}
return o
}
func (f *Factory) NewCommsEmailLog(mods ...CommsEmailLogMod) *CommsEmailLogTemplate {
return f.NewCommsEmailLogWithContext(context.Background(), mods...)
}
func (f *Factory) NewCommsEmailLogWithContext(ctx context.Context, mods ...CommsEmailLogMod) *CommsEmailLogTemplate {
o := &CommsEmailLogTemplate{f: f}
if f != nil {
f.baseCommsEmailLogMods.Apply(ctx, o)
}
CommsEmailLogModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingCommsEmailLog(m *models.CommsEmailLog) *CommsEmailLogTemplate {
o := &CommsEmailLogTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Destination = func() string { return m.Destination }
o.Source = func() string { return m.Source }
o.Type = func() enums.CommsEmailmessagetype { return m.Type }
ctx := context.Background()
if m.R.DestinationEmail != nil {
CommsEmailLogMods.WithExistingDestinationEmail(m.R.DestinationEmail).Apply(ctx, o)
}
if m.R.SourcePhone != nil {
CommsEmailLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o)
}
return o
}
func (f *Factory) NewCommsPhone(mods ...CommsPhoneMod) *CommsPhoneTemplate {
return f.NewCommsPhoneWithContext(context.Background(), mods...)
}
func (f *Factory) NewCommsPhoneWithContext(ctx context.Context, mods ...CommsPhoneMod) *CommsPhoneTemplate {
o := &CommsPhoneTemplate{f: f}
if f != nil {
f.baseCommsPhoneMods.Apply(ctx, o)
}
CommsPhoneModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingCommsPhone(m *models.CommsPhone) *CommsPhoneTemplate {
o := &CommsPhoneTemplate{f: f, alreadyPersisted: true}
o.E164 = func() string { return m.E164 }
o.IsSubscribed = func() bool { return m.IsSubscribed }
ctx := context.Background()
if len(m.R.SourceEmailLogs) > 0 {
CommsPhoneMods.AddExistingSourceEmailLogs(m.R.SourceEmailLogs...).Apply(ctx, o)
}
if len(m.R.DestinationSMSLogs) > 0 {
CommsPhoneMods.AddExistingDestinationSMSLogs(m.R.DestinationSMSLogs...).Apply(ctx, o)
}
if len(m.R.SourceSMSLogs) > 0 {
CommsPhoneMods.AddExistingSourceSMSLogs(m.R.SourceSMSLogs...).Apply(ctx, o)
}
return o
}
func (f *Factory) NewCommsSMSLog(mods ...CommsSMSLogMod) *CommsSMSLogTemplate {
return f.NewCommsSMSLogWithContext(context.Background(), mods...)
}
func (f *Factory) NewCommsSMSLogWithContext(ctx context.Context, mods ...CommsSMSLogMod) *CommsSMSLogTemplate {
o := &CommsSMSLogTemplate{f: f}
if f != nil {
f.baseCommsSMSLogMods.Apply(ctx, o)
}
CommsSMSLogModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingCommsSMSLog(m *models.CommsSMSLog) *CommsSMSLogTemplate {
o := &CommsSMSLogTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Destination = func() string { return m.Destination }
o.Source = func() string { return m.Source }
o.Type = func() enums.CommsSmsmessagetype { return m.Type }
ctx := context.Background()
if m.R.DestinationPhone != nil {
CommsSMSLogMods.WithExistingDestinationPhone(m.R.DestinationPhone).Apply(ctx, o)
}
if m.R.SourcePhone != nil {
CommsSMSLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o)
}
return o
}
func (f *Factory) NewFieldseekerContainerrelate(mods ...FieldseekerContainerrelateMod) *FieldseekerContainerrelateTemplate {
return f.NewFieldseekerContainerrelateWithContext(context.Background(), mods...)
}
@ -2536,6 +2677,7 @@ func (f *Factory) FromExistingPublicreportImage(m *models.PublicreportImage) *Pu
o.ID = func() int32 { return m.ID }
o.ContentType = func() string { return m.ContentType }
o.Created = func() time.Time { return m.Created }
o.Location = func() null.Val[string] { return m.Location }
o.ResolutionX = func() int32 { return m.ResolutionX }
o.ResolutionY = func() int32 { return m.ResolutionY }
o.StorageUUID = func() uuid.UUID { return m.StorageUUID }
@ -3032,6 +3174,38 @@ func (f *Factory) AddBaseArcgisUserPrivilegeMod(mods ...ArcgisUserPrivilegeMod)
f.baseArcgisUserPrivilegeMods = append(f.baseArcgisUserPrivilegeMods, mods...)
}
func (f *Factory) ClearBaseCommsEmailMods() {
f.baseCommsEmailMods = nil
}
func (f *Factory) AddBaseCommsEmailMod(mods ...CommsEmailMod) {
f.baseCommsEmailMods = append(f.baseCommsEmailMods, mods...)
}
func (f *Factory) ClearBaseCommsEmailLogMods() {
f.baseCommsEmailLogMods = nil
}
func (f *Factory) AddBaseCommsEmailLogMod(mods ...CommsEmailLogMod) {
f.baseCommsEmailLogMods = append(f.baseCommsEmailLogMods, mods...)
}
func (f *Factory) ClearBaseCommsPhoneMods() {
f.baseCommsPhoneMods = nil
}
func (f *Factory) AddBaseCommsPhoneMod(mods ...CommsPhoneMod) {
f.baseCommsPhoneMods = append(f.baseCommsPhoneMods, mods...)
}
func (f *Factory) ClearBaseCommsSMSLogMods() {
f.baseCommsSMSLogMods = nil
}
func (f *Factory) AddBaseCommsSMSLogMod(mods ...CommsSMSLogMod) {
f.baseCommsSMSLogMods = append(f.baseCommsSMSLogMods, mods...)
}
func (f *Factory) ClearBaseFieldseekerContainerrelateMods() {
f.baseFieldseekerContainerrelateMods = nil
}

View file

@ -89,6 +89,26 @@ func random_enums_Audiodatatype(f *faker.Faker, limits ...string) enums.Audiodat
return all[f.IntBetween(0, len(all)-1)]
}
func random_enums_CommsEmailmessagetype(f *faker.Faker, limits ...string) enums.CommsEmailmessagetype {
if f == nil {
f = &defaultFaker
}
var e enums.CommsEmailmessagetype
all := e.All()
return all[f.IntBetween(0, len(all)-1)]
}
func random_enums_CommsSmsmessagetype(f *faker.Faker, limits ...string) enums.CommsSmsmessagetype {
if f == nil {
f = &defaultFaker
}
var e enums.CommsSmsmessagetype
all := e.All()
return all[f.IntBetween(0, len(all)-1)]
}
func random_enums_H3aggregationtype(f *faker.Faker, limits ...string) enums.H3aggregationtype {
if f == nil {
f = &defaultFaker

View file

@ -0,0 +1,434 @@
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type CommsEmailMod interface {
Apply(context.Context, *CommsEmailTemplate)
}
type CommsEmailModFunc func(context.Context, *CommsEmailTemplate)
func (f CommsEmailModFunc) Apply(ctx context.Context, n *CommsEmailTemplate) {
f(ctx, n)
}
type CommsEmailModSlice []CommsEmailMod
func (mods CommsEmailModSlice) Apply(ctx context.Context, n *CommsEmailTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsEmailTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsEmailTemplate struct {
Address func() string
Confirmed func() bool
IsSubscribed func() bool
r commsEmailR
f *Factory
alreadyPersisted bool
}
type commsEmailR struct {
DestinationEmailLogs []*commsEmailRDestinationEmailLogsR
}
type commsEmailRDestinationEmailLogsR struct {
number int
o *CommsEmailLogTemplate
}
// Apply mods to the CommsEmailTemplate
func (o *CommsEmailTemplate) Apply(ctx context.Context, mods ...CommsEmailMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsEmail
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsEmailTemplate) setModelRels(o *models.CommsEmail) {
if t.r.DestinationEmailLogs != nil {
rel := models.CommsEmailLogSlice{}
for _, r := range t.r.DestinationEmailLogs {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Destination = o.Address // h2
rel.R.DestinationEmail = o
}
rel = append(rel, related...)
}
o.R.DestinationEmailLogs = rel
}
}
// BuildSetter returns an *models.CommsEmailSetter
// this does nothing with the relationship templates
func (o CommsEmailTemplate) BuildSetter() *models.CommsEmailSetter {
m := &models.CommsEmailSetter{}
if o.Address != nil {
val := o.Address()
m.Address = omit.From(val)
}
if o.Confirmed != nil {
val := o.Confirmed()
m.Confirmed = omit.From(val)
}
if o.IsSubscribed != nil {
val := o.IsSubscribed()
m.IsSubscribed = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsEmailSetter
// this does nothing with the relationship templates
func (o CommsEmailTemplate) BuildManySetter(number int) []*models.CommsEmailSetter {
m := make([]*models.CommsEmailSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsEmail
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailTemplate.Create
func (o CommsEmailTemplate) Build() *models.CommsEmail {
m := &models.CommsEmail{}
if o.Address != nil {
m.Address = o.Address()
}
if o.Confirmed != nil {
m.Confirmed = o.Confirmed()
}
if o.IsSubscribed != nil {
m.IsSubscribed = o.IsSubscribed()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsEmailSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailTemplate.CreateMany
func (o CommsEmailTemplate) BuildMany(number int) models.CommsEmailSlice {
m := make(models.CommsEmailSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsEmail(m *models.CommsEmailSetter) {
if !(m.Address.IsValue()) {
val := random_string(nil)
m.Address = omit.From(val)
}
if !(m.Confirmed.IsValue()) {
val := random_bool(nil)
m.Confirmed = omit.From(val)
}
if !(m.IsSubscribed.IsValue()) {
val := random_bool(nil)
m.IsSubscribed = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsEmail
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsEmailTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsEmail) error {
var err error
isDestinationEmailLogsDone, _ := commsEmailRelDestinationEmailLogsCtx.Value(ctx)
if !isDestinationEmailLogsDone && o.r.DestinationEmailLogs != nil {
ctx = commsEmailRelDestinationEmailLogsCtx.WithValue(ctx, true)
for _, r := range o.r.DestinationEmailLogs {
if r.o.alreadyPersisted {
m.R.DestinationEmailLogs = append(m.R.DestinationEmailLogs, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachDestinationEmailLogs(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
return err
}
// Create builds a commsEmail and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsEmailTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsEmail, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsEmail(opt)
m, err := models.CommsEmails.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a commsEmail and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsEmailTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsEmail {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsEmail and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *CommsEmailTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsEmail {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsEmails and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsEmailTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsEmailSlice, error) {
var err error
m := make(models.CommsEmailSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsEmails and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsEmailTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsEmailSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsEmails and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o CommsEmailTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsEmailSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsEmail has methods that act as mods for the CommsEmailTemplate
var CommsEmailMods commsEmailMods
type commsEmailMods struct{}
func (m commsEmailMods) RandomizeAllColumns(f *faker.Faker) CommsEmailMod {
return CommsEmailModSlice{
CommsEmailMods.RandomAddress(f),
CommsEmailMods.RandomConfirmed(f),
CommsEmailMods.RandomIsSubscribed(f),
}
}
// Set the model columns to this value
func (m commsEmailMods) Address(val string) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Address = func() string { return val }
})
}
// Set the Column from the function
func (m commsEmailMods) AddressFunc(f func() string) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Address = f
})
}
// Clear any values for the column
func (m commsEmailMods) UnsetAddress() CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Address = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailMods) RandomAddress(f *faker.Faker) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Address = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsEmailMods) Confirmed(val bool) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Confirmed = func() bool { return val }
})
}
// Set the Column from the function
func (m commsEmailMods) ConfirmedFunc(f func() bool) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Confirmed = f
})
}
// Clear any values for the column
func (m commsEmailMods) UnsetConfirmed() CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Confirmed = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailMods) RandomConfirmed(f *faker.Faker) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.Confirmed = func() bool {
return random_bool(f)
}
})
}
// Set the model columns to this value
func (m commsEmailMods) IsSubscribed(val bool) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.IsSubscribed = func() bool { return val }
})
}
// Set the Column from the function
func (m commsEmailMods) IsSubscribedFunc(f func() bool) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.IsSubscribed = f
})
}
// Clear any values for the column
func (m commsEmailMods) UnsetIsSubscribed() CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.IsSubscribed = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailMods) RandomIsSubscribed(f *faker.Faker) CommsEmailMod {
return CommsEmailModFunc(func(_ context.Context, o *CommsEmailTemplate) {
o.IsSubscribed = func() bool {
return random_bool(f)
}
})
}
func (m commsEmailMods) WithParentsCascading() CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
if isDone, _ := commsEmailWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsEmailWithParentsCascadingCtx.WithValue(ctx, true)
})
}
func (m commsEmailMods) WithDestinationEmailLogs(number int, related *CommsEmailLogTemplate) CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
o.r.DestinationEmailLogs = []*commsEmailRDestinationEmailLogsR{{
number: number,
o: related,
}}
})
}
func (m commsEmailMods) WithNewDestinationEmailLogs(number int, mods ...CommsEmailLogMod) CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
m.WithDestinationEmailLogs(number, related).Apply(ctx, o)
})
}
func (m commsEmailMods) AddDestinationEmailLogs(number int, related *CommsEmailLogTemplate) CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
o.r.DestinationEmailLogs = append(o.r.DestinationEmailLogs, &commsEmailRDestinationEmailLogsR{
number: number,
o: related,
})
})
}
func (m commsEmailMods) AddNewDestinationEmailLogs(number int, mods ...CommsEmailLogMod) CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
m.AddDestinationEmailLogs(number, related).Apply(ctx, o)
})
}
func (m commsEmailMods) AddExistingDestinationEmailLogs(existingModels ...*models.CommsEmailLog) CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
for _, em := range existingModels {
o.r.DestinationEmailLogs = append(o.r.DestinationEmailLogs, &commsEmailRDestinationEmailLogsR{
o: o.f.FromExistingCommsEmailLog(em),
})
}
})
}
func (m commsEmailMods) WithoutDestinationEmailLogs() CommsEmailMod {
return CommsEmailModFunc(func(ctx context.Context, o *CommsEmailTemplate) {
o.r.DestinationEmailLogs = nil
})
}

View file

@ -0,0 +1,523 @@
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type CommsEmailLogMod interface {
Apply(context.Context, *CommsEmailLogTemplate)
}
type CommsEmailLogModFunc func(context.Context, *CommsEmailLogTemplate)
func (f CommsEmailLogModFunc) Apply(ctx context.Context, n *CommsEmailLogTemplate) {
f(ctx, n)
}
type CommsEmailLogModSlice []CommsEmailLogMod
func (mods CommsEmailLogModSlice) Apply(ctx context.Context, n *CommsEmailLogTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsEmailLogTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsEmailLogTemplate struct {
Created func() time.Time
Destination func() string
Source func() string
Type func() enums.CommsEmailmessagetype
r commsEmailLogR
f *Factory
alreadyPersisted bool
}
type commsEmailLogR struct {
DestinationEmail *commsEmailLogRDestinationEmailR
SourcePhone *commsEmailLogRSourcePhoneR
}
type commsEmailLogRDestinationEmailR struct {
o *CommsEmailTemplate
}
type commsEmailLogRSourcePhoneR struct {
o *CommsPhoneTemplate
}
// Apply mods to the CommsEmailLogTemplate
func (o *CommsEmailLogTemplate) Apply(ctx context.Context, mods ...CommsEmailLogMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsEmailLog
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsEmailLogTemplate) setModelRels(o *models.CommsEmailLog) {
if t.r.DestinationEmail != nil {
rel := t.r.DestinationEmail.o.Build()
rel.R.DestinationEmailLogs = append(rel.R.DestinationEmailLogs, o)
o.Destination = rel.Address // h2
o.R.DestinationEmail = rel
}
if t.r.SourcePhone != nil {
rel := t.r.SourcePhone.o.Build()
rel.R.SourceEmailLogs = append(rel.R.SourceEmailLogs, o)
o.Source = rel.E164 // h2
o.R.SourcePhone = rel
}
}
// BuildSetter returns an *models.CommsEmailLogSetter
// this does nothing with the relationship templates
func (o CommsEmailLogTemplate) BuildSetter() *models.CommsEmailLogSetter {
m := &models.CommsEmailLogSetter{}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Destination != nil {
val := o.Destination()
m.Destination = omit.From(val)
}
if o.Source != nil {
val := o.Source()
m.Source = omit.From(val)
}
if o.Type != nil {
val := o.Type()
m.Type = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsEmailLogSetter
// this does nothing with the relationship templates
func (o CommsEmailLogTemplate) BuildManySetter(number int) []*models.CommsEmailLogSetter {
m := make([]*models.CommsEmailLogSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsEmailLog
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailLogTemplate.Create
func (o CommsEmailLogTemplate) Build() *models.CommsEmailLog {
m := &models.CommsEmailLog{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Destination != nil {
m.Destination = o.Destination()
}
if o.Source != nil {
m.Source = o.Source()
}
if o.Type != nil {
m.Type = o.Type()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsEmailLogSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsEmailLogTemplate.CreateMany
func (o CommsEmailLogTemplate) BuildMany(number int) models.CommsEmailLogSlice {
m := make(models.CommsEmailLogSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsEmailLog(m *models.CommsEmailLogSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Destination.IsValue()) {
val := random_string(nil)
m.Destination = omit.From(val)
}
if !(m.Source.IsValue()) {
val := random_string(nil)
m.Source = omit.From(val)
}
if !(m.Type.IsValue()) {
val := random_enums_CommsEmailmessagetype(nil)
m.Type = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsEmailLog
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsEmailLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsEmailLog) error {
var err error
return err
}
// Create builds a commsEmailLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsEmailLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsEmailLog, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsEmailLog(opt)
if o.r.DestinationEmail == nil {
CommsEmailLogMods.WithNewDestinationEmail().Apply(ctx, o)
}
var rel0 *models.CommsEmail
if o.r.DestinationEmail.o.alreadyPersisted {
rel0 = o.r.DestinationEmail.o.Build()
} else {
rel0, err = o.r.DestinationEmail.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Destination = omit.From(rel0.Address)
if o.r.SourcePhone == nil {
CommsEmailLogMods.WithNewSourcePhone().Apply(ctx, o)
}
var rel1 *models.CommsPhone
if o.r.SourcePhone.o.alreadyPersisted {
rel1 = o.r.SourcePhone.o.Build()
} else {
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Source = omit.From(rel1.E164)
m, err := models.CommsEmailLogs.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.DestinationEmail = rel0
m.R.SourcePhone = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a commsEmailLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsEmailLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsEmailLog {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsEmailLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *CommsEmailLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsEmailLog {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsEmailLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsEmailLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsEmailLogSlice, error) {
var err error
m := make(models.CommsEmailLogSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsEmailLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsEmailLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsEmailLogSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsEmailLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o CommsEmailLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsEmailLogSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsEmailLog has methods that act as mods for the CommsEmailLogTemplate
var CommsEmailLogMods commsEmailLogMods
type commsEmailLogMods struct{}
func (m commsEmailLogMods) RandomizeAllColumns(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModSlice{
CommsEmailLogMods.RandomCreated(f),
CommsEmailLogMods.RandomDestination(f),
CommsEmailLogMods.RandomSource(f),
CommsEmailLogMods.RandomType(f),
}
}
// Set the model columns to this value
func (m commsEmailLogMods) Created(val time.Time) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) CreatedFunc(f func() time.Time) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetCreated() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomCreated(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Destination(val string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = func() string { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) DestinationFunc(f func() string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetDestination() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomDestination(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Destination = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Source(val string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = func() string { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) SourceFunc(f func() string) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetSource() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomSource(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Source = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsEmailLogMods) Type(val enums.CommsEmailmessagetype) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = func() enums.CommsEmailmessagetype { return val }
})
}
// Set the Column from the function
func (m commsEmailLogMods) TypeFunc(f func() enums.CommsEmailmessagetype) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = f
})
}
// Clear any values for the column
func (m commsEmailLogMods) UnsetType() CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsEmailLogMods) RandomType(f *faker.Faker) CommsEmailLogMod {
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
o.Type = func() enums.CommsEmailmessagetype {
return random_enums_CommsEmailmessagetype(f)
}
})
}
func (m commsEmailLogMods) WithParentsCascading() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
if isDone, _ := commsEmailLogWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsEmailLogWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsEmailWithContext(ctx, CommsEmailMods.WithParentsCascading())
m.WithDestinationEmail(related).Apply(ctx, o)
}
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithSourcePhone(related).Apply(ctx, o)
}
})
}
func (m commsEmailLogMods) WithDestinationEmail(rel *CommsEmailTemplate) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = &commsEmailLogRDestinationEmailR{
o: rel,
}
})
}
func (m commsEmailLogMods) WithNewDestinationEmail(mods ...CommsEmailMod) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
related := o.f.NewCommsEmailWithContext(ctx, mods...)
m.WithDestinationEmail(related).Apply(ctx, o)
})
}
func (m commsEmailLogMods) WithExistingDestinationEmail(em *models.CommsEmail) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = &commsEmailLogRDestinationEmailR{
o: o.f.FromExistingCommsEmail(em),
}
})
}
func (m commsEmailLogMods) WithoutDestinationEmail() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.DestinationEmail = nil
})
}
func (m commsEmailLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = &commsEmailLogRSourcePhoneR{
o: rel,
}
})
}
func (m commsEmailLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithSourcePhone(related).Apply(ctx, o)
})
}
func (m commsEmailLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = &commsEmailLogRSourcePhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m commsEmailLogMods) WithoutSourcePhone() CommsEmailLogMod {
return CommsEmailLogModFunc(func(ctx context.Context, o *CommsEmailLogTemplate) {
o.r.SourcePhone = nil
})
}

View file

@ -0,0 +1,562 @@
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type CommsPhoneMod interface {
Apply(context.Context, *CommsPhoneTemplate)
}
type CommsPhoneModFunc func(context.Context, *CommsPhoneTemplate)
func (f CommsPhoneModFunc) Apply(ctx context.Context, n *CommsPhoneTemplate) {
f(ctx, n)
}
type CommsPhoneModSlice []CommsPhoneMod
func (mods CommsPhoneModSlice) Apply(ctx context.Context, n *CommsPhoneTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsPhoneTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsPhoneTemplate struct {
E164 func() string
IsSubscribed func() bool
r commsPhoneR
f *Factory
alreadyPersisted bool
}
type commsPhoneR struct {
SourceEmailLogs []*commsPhoneRSourceEmailLogsR
DestinationSMSLogs []*commsPhoneRDestinationSMSLogsR
SourceSMSLogs []*commsPhoneRSourceSMSLogsR
}
type commsPhoneRSourceEmailLogsR struct {
number int
o *CommsEmailLogTemplate
}
type commsPhoneRDestinationSMSLogsR struct {
number int
o *CommsSMSLogTemplate
}
type commsPhoneRSourceSMSLogsR struct {
number int
o *CommsSMSLogTemplate
}
// Apply mods to the CommsPhoneTemplate
func (o *CommsPhoneTemplate) Apply(ctx context.Context, mods ...CommsPhoneMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsPhone
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
if t.r.SourceEmailLogs != nil {
rel := models.CommsEmailLogSlice{}
for _, r := range t.r.SourceEmailLogs {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Source = o.E164 // h2
rel.R.SourcePhone = o
}
rel = append(rel, related...)
}
o.R.SourceEmailLogs = rel
}
if t.r.DestinationSMSLogs != nil {
rel := models.CommsSMSLogSlice{}
for _, r := range t.r.DestinationSMSLogs {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Destination = o.E164 // h2
rel.R.DestinationPhone = o
}
rel = append(rel, related...)
}
o.R.DestinationSMSLogs = rel
}
if t.r.SourceSMSLogs != nil {
rel := models.CommsSMSLogSlice{}
for _, r := range t.r.SourceSMSLogs {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.Source = o.E164 // h2
rel.R.SourcePhone = o
}
rel = append(rel, related...)
}
o.R.SourceSMSLogs = rel
}
}
// BuildSetter returns an *models.CommsPhoneSetter
// this does nothing with the relationship templates
func (o CommsPhoneTemplate) BuildSetter() *models.CommsPhoneSetter {
m := &models.CommsPhoneSetter{}
if o.E164 != nil {
val := o.E164()
m.E164 = omit.From(val)
}
if o.IsSubscribed != nil {
val := o.IsSubscribed()
m.IsSubscribed = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsPhoneSetter
// this does nothing with the relationship templates
func (o CommsPhoneTemplate) BuildManySetter(number int) []*models.CommsPhoneSetter {
m := make([]*models.CommsPhoneSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsPhone
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsPhoneTemplate.Create
func (o CommsPhoneTemplate) Build() *models.CommsPhone {
m := &models.CommsPhone{}
if o.E164 != nil {
m.E164 = o.E164()
}
if o.IsSubscribed != nil {
m.IsSubscribed = o.IsSubscribed()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsPhoneSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsPhoneTemplate.CreateMany
func (o CommsPhoneTemplate) BuildMany(number int) models.CommsPhoneSlice {
m := make(models.CommsPhoneSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsPhone(m *models.CommsPhoneSetter) {
if !(m.E164.IsValue()) {
val := random_string(nil)
m.E164 = omit.From(val)
}
if !(m.IsSubscribed.IsValue()) {
val := random_bool(nil)
m.IsSubscribed = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsPhone
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsPhone) error {
var err error
isSourceEmailLogsDone, _ := commsPhoneRelSourceEmailLogsCtx.Value(ctx)
if !isSourceEmailLogsDone && o.r.SourceEmailLogs != nil {
ctx = commsPhoneRelSourceEmailLogsCtx.WithValue(ctx, true)
for _, r := range o.r.SourceEmailLogs {
if r.o.alreadyPersisted {
m.R.SourceEmailLogs = append(m.R.SourceEmailLogs, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachSourceEmailLogs(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isDestinationSMSLogsDone, _ := commsPhoneRelDestinationSMSLogsCtx.Value(ctx)
if !isDestinationSMSLogsDone && o.r.DestinationSMSLogs != nil {
ctx = commsPhoneRelDestinationSMSLogsCtx.WithValue(ctx, true)
for _, r := range o.r.DestinationSMSLogs {
if r.o.alreadyPersisted {
m.R.DestinationSMSLogs = append(m.R.DestinationSMSLogs, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachDestinationSMSLogs(ctx, exec, rel1...)
if err != nil {
return err
}
}
}
}
isSourceSMSLogsDone, _ := commsPhoneRelSourceSMSLogsCtx.Value(ctx)
if !isSourceSMSLogsDone && o.r.SourceSMSLogs != nil {
ctx = commsPhoneRelSourceSMSLogsCtx.WithValue(ctx, true)
for _, r := range o.r.SourceSMSLogs {
if r.o.alreadyPersisted {
m.R.SourceSMSLogs = append(m.R.SourceSMSLogs, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachSourceSMSLogs(ctx, exec, rel2...)
if err != nil {
return err
}
}
}
}
return err
}
// Create builds a commsPhone and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsPhoneTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsPhone, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsPhone(opt)
m, err := models.CommsPhones.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a commsPhone and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsPhoneTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsPhone {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsPhone and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *CommsPhoneTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsPhone {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsPhones and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsPhoneTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsPhoneSlice, error) {
var err error
m := make(models.CommsPhoneSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsPhones and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsPhoneTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsPhoneSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsPhones and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o CommsPhoneTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsPhoneSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsPhone has methods that act as mods for the CommsPhoneTemplate
var CommsPhoneMods commsPhoneMods
type commsPhoneMods struct{}
func (m commsPhoneMods) RandomizeAllColumns(f *faker.Faker) CommsPhoneMod {
return CommsPhoneModSlice{
CommsPhoneMods.RandomE164(f),
CommsPhoneMods.RandomIsSubscribed(f),
}
}
// Set the model columns to this value
func (m commsPhoneMods) E164(val string) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.E164 = func() string { return val }
})
}
// Set the Column from the function
func (m commsPhoneMods) E164Func(f func() string) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.E164 = f
})
}
// Clear any values for the column
func (m commsPhoneMods) UnsetE164() CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.E164 = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsPhoneMods) RandomE164(f *faker.Faker) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.E164 = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsPhoneMods) IsSubscribed(val bool) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.IsSubscribed = func() bool { return val }
})
}
// Set the Column from the function
func (m commsPhoneMods) IsSubscribedFunc(f func() bool) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.IsSubscribed = f
})
}
// Clear any values for the column
func (m commsPhoneMods) UnsetIsSubscribed() CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.IsSubscribed = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsPhoneMods) RandomIsSubscribed(f *faker.Faker) CommsPhoneMod {
return CommsPhoneModFunc(func(_ context.Context, o *CommsPhoneTemplate) {
o.IsSubscribed = func() bool {
return random_bool(f)
}
})
}
func (m commsPhoneMods) WithParentsCascading() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
if isDone, _ := commsPhoneWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsPhoneWithParentsCascadingCtx.WithValue(ctx, true)
})
}
func (m commsPhoneMods) WithSourceEmailLogs(number int, related *CommsEmailLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceEmailLogs = []*commsPhoneRSourceEmailLogsR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewSourceEmailLogs(number int, mods ...CommsEmailLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
m.WithSourceEmailLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddSourceEmailLogs(number int, related *CommsEmailLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceEmailLogs = append(o.r.SourceEmailLogs, &commsPhoneRSourceEmailLogsR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewSourceEmailLogs(number int, mods ...CommsEmailLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsEmailLogWithContext(ctx, mods...)
m.AddSourceEmailLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingSourceEmailLogs(existingModels ...*models.CommsEmailLog) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.SourceEmailLogs = append(o.r.SourceEmailLogs, &commsPhoneRSourceEmailLogsR{
o: o.f.FromExistingCommsEmailLog(em),
})
}
})
}
func (m commsPhoneMods) WithoutSourceEmailLogs() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceEmailLogs = nil
})
}
func (m commsPhoneMods) WithDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.DestinationSMSLogs = []*commsPhoneRDestinationSMSLogsR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
m.WithDestinationSMSLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.DestinationSMSLogs = append(o.r.DestinationSMSLogs, &commsPhoneRDestinationSMSLogsR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
m.AddDestinationSMSLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingDestinationSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.DestinationSMSLogs = append(o.r.DestinationSMSLogs, &commsPhoneRDestinationSMSLogsR{
o: o.f.FromExistingCommsSMSLog(em),
})
}
})
}
func (m commsPhoneMods) WithoutDestinationSMSLogs() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.DestinationSMSLogs = nil
})
}
func (m commsPhoneMods) WithSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceSMSLogs = []*commsPhoneRSourceSMSLogsR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
m.WithSourceSMSLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceSMSLogs = append(o.r.SourceSMSLogs, &commsPhoneRSourceSMSLogsR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
m.AddSourceSMSLogs(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingSourceSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.SourceSMSLogs = append(o.r.SourceSMSLogs, &commsPhoneRSourceSMSLogsR{
o: o.f.FromExistingCommsSMSLog(em),
})
}
})
}
func (m commsPhoneMods) WithoutSourceSMSLogs() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.SourceSMSLogs = nil
})
}

View file

@ -0,0 +1,523 @@
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type CommsSMSLogMod interface {
Apply(context.Context, *CommsSMSLogTemplate)
}
type CommsSMSLogModFunc func(context.Context, *CommsSMSLogTemplate)
func (f CommsSMSLogModFunc) Apply(ctx context.Context, n *CommsSMSLogTemplate) {
f(ctx, n)
}
type CommsSMSLogModSlice []CommsSMSLogMod
func (mods CommsSMSLogModSlice) Apply(ctx context.Context, n *CommsSMSLogTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// CommsSMSLogTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type CommsSMSLogTemplate struct {
Created func() time.Time
Destination func() string
Source func() string
Type func() enums.CommsSmsmessagetype
r commsSMSLogR
f *Factory
alreadyPersisted bool
}
type commsSMSLogR struct {
DestinationPhone *commsSMSLogRDestinationPhoneR
SourcePhone *commsSMSLogRSourcePhoneR
}
type commsSMSLogRDestinationPhoneR struct {
o *CommsPhoneTemplate
}
type commsSMSLogRSourcePhoneR struct {
o *CommsPhoneTemplate
}
// Apply mods to the CommsSMSLogTemplate
func (o *CommsSMSLogTemplate) Apply(ctx context.Context, mods ...CommsSMSLogMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.CommsSMSLog
// according to the relationships in the template. Nothing is inserted into the db
func (t CommsSMSLogTemplate) setModelRels(o *models.CommsSMSLog) {
if t.r.DestinationPhone != nil {
rel := t.r.DestinationPhone.o.Build()
rel.R.DestinationSMSLogs = append(rel.R.DestinationSMSLogs, o)
o.Destination = rel.E164 // h2
o.R.DestinationPhone = rel
}
if t.r.SourcePhone != nil {
rel := t.r.SourcePhone.o.Build()
rel.R.SourceSMSLogs = append(rel.R.SourceSMSLogs, o)
o.Source = rel.E164 // h2
o.R.SourcePhone = rel
}
}
// BuildSetter returns an *models.CommsSMSLogSetter
// this does nothing with the relationship templates
func (o CommsSMSLogTemplate) BuildSetter() *models.CommsSMSLogSetter {
m := &models.CommsSMSLogSetter{}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.Destination != nil {
val := o.Destination()
m.Destination = omit.From(val)
}
if o.Source != nil {
val := o.Source()
m.Source = omit.From(val)
}
if o.Type != nil {
val := o.Type()
m.Type = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.CommsSMSLogSetter
// this does nothing with the relationship templates
func (o CommsSMSLogTemplate) BuildManySetter(number int) []*models.CommsSMSLogSetter {
m := make([]*models.CommsSMSLogSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.CommsSMSLog
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsSMSLogTemplate.Create
func (o CommsSMSLogTemplate) Build() *models.CommsSMSLog {
m := &models.CommsSMSLog{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Destination != nil {
m.Destination = o.Destination()
}
if o.Source != nil {
m.Source = o.Source()
}
if o.Type != nil {
m.Type = o.Type()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.CommsSMSLogSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use CommsSMSLogTemplate.CreateMany
func (o CommsSMSLogTemplate) BuildMany(number int) models.CommsSMSLogSlice {
m := make(models.CommsSMSLogSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableCommsSMSLog(m *models.CommsSMSLogSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.Destination.IsValue()) {
val := random_string(nil)
m.Destination = omit.From(val)
}
if !(m.Source.IsValue()) {
val := random_string(nil)
m.Source = omit.From(val)
}
if !(m.Type.IsValue()) {
val := random_enums_CommsSmsmessagetype(nil)
m.Type = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.CommsSMSLog
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *CommsSMSLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsSMSLog) error {
var err error
return err
}
// Create builds a commsSMSLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *CommsSMSLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsSMSLog, error) {
var err error
opt := o.BuildSetter()
ensureCreatableCommsSMSLog(opt)
if o.r.DestinationPhone == nil {
CommsSMSLogMods.WithNewDestinationPhone().Apply(ctx, o)
}
var rel0 *models.CommsPhone
if o.r.DestinationPhone.o.alreadyPersisted {
rel0 = o.r.DestinationPhone.o.Build()
} else {
rel0, err = o.r.DestinationPhone.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Destination = omit.From(rel0.E164)
if o.r.SourcePhone == nil {
CommsSMSLogMods.WithNewSourcePhone().Apply(ctx, o)
}
var rel1 *models.CommsPhone
if o.r.SourcePhone.o.alreadyPersisted {
rel1 = o.r.SourcePhone.o.Build()
} else {
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.Source = omit.From(rel1.E164)
m, err := models.CommsSMSLogs.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.DestinationPhone = rel0
m.R.SourcePhone = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a commsSMSLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *CommsSMSLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsSMSLog {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a commsSMSLog and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *CommsSMSLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsSMSLog {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple commsSMSLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o CommsSMSLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsSMSLogSlice, error) {
var err error
m := make(models.CommsSMSLogSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple commsSMSLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o CommsSMSLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsSMSLogSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple commsSMSLogs and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o CommsSMSLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsSMSLogSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CommsSMSLog has methods that act as mods for the CommsSMSLogTemplate
var CommsSMSLogMods commsSMSLogMods
type commsSMSLogMods struct{}
func (m commsSMSLogMods) RandomizeAllColumns(f *faker.Faker) CommsSMSLogMod {
return CommsSMSLogModSlice{
CommsSMSLogMods.RandomCreated(f),
CommsSMSLogMods.RandomDestination(f),
CommsSMSLogMods.RandomSource(f),
CommsSMSLogMods.RandomType(f),
}
}
// Set the model columns to this value
func (m commsSMSLogMods) Created(val time.Time) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m commsSMSLogMods) CreatedFunc(f func() time.Time) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m commsSMSLogMods) UnsetCreated() CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsSMSLogMods) RandomCreated(f *faker.Faker) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m commsSMSLogMods) Destination(val string) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Destination = func() string { return val }
})
}
// Set the Column from the function
func (m commsSMSLogMods) DestinationFunc(f func() string) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Destination = f
})
}
// Clear any values for the column
func (m commsSMSLogMods) UnsetDestination() CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Destination = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsSMSLogMods) RandomDestination(f *faker.Faker) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Destination = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsSMSLogMods) Source(val string) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Source = func() string { return val }
})
}
// Set the Column from the function
func (m commsSMSLogMods) SourceFunc(f func() string) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Source = f
})
}
// Clear any values for the column
func (m commsSMSLogMods) UnsetSource() CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Source = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsSMSLogMods) RandomSource(f *faker.Faker) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Source = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m commsSMSLogMods) Type(val enums.CommsSmsmessagetype) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Type = func() enums.CommsSmsmessagetype { return val }
})
}
// Set the Column from the function
func (m commsSMSLogMods) TypeFunc(f func() enums.CommsSmsmessagetype) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Type = f
})
}
// Clear any values for the column
func (m commsSMSLogMods) UnsetType() CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Type = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m commsSMSLogMods) RandomType(f *faker.Faker) CommsSMSLogMod {
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
o.Type = func() enums.CommsSmsmessagetype {
return random_enums_CommsSmsmessagetype(f)
}
})
}
func (m commsSMSLogMods) WithParentsCascading() CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
if isDone, _ := commsSMSLogWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = commsSMSLogWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithDestinationPhone(related).Apply(ctx, o)
}
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithSourcePhone(related).Apply(ctx, o)
}
})
}
func (m commsSMSLogMods) WithDestinationPhone(rel *CommsPhoneTemplate) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.DestinationPhone = &commsSMSLogRDestinationPhoneR{
o: rel,
}
})
}
func (m commsSMSLogMods) WithNewDestinationPhone(mods ...CommsPhoneMod) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithDestinationPhone(related).Apply(ctx, o)
})
}
func (m commsSMSLogMods) WithExistingDestinationPhone(em *models.CommsPhone) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.DestinationPhone = &commsSMSLogRDestinationPhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m commsSMSLogMods) WithoutDestinationPhone() CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.DestinationPhone = nil
})
}
func (m commsSMSLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.SourcePhone = &commsSMSLogRSourcePhoneR{
o: rel,
}
})
}
func (m commsSMSLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithSourcePhone(related).Apply(ctx, o)
})
}
func (m commsSMSLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.SourcePhone = &commsSMSLogRSourcePhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m commsSMSLogMods) WithoutSourcePhone() CommsSMSLogMod {
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
o.r.SourcePhone = nil
})
}

View file

@ -9,7 +9,9 @@ import (
"time"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/google/uuid"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
@ -39,6 +41,7 @@ type PublicreportImageTemplate struct {
ID func() int32
ContentType func() string
Created func() time.Time
Location func() null.Val[string]
ResolutionX func() int32
ResolutionY func() int32
StorageUUID func() uuid.UUID
@ -135,6 +138,10 @@ func (o PublicreportImageTemplate) BuildSetter() *models.PublicreportImageSetter
val := o.Created()
m.Created = omit.From(val)
}
if o.Location != nil {
val := o.Location()
m.Location = omitnull.FromNull(val)
}
if o.ResolutionX != nil {
val := o.ResolutionX()
m.ResolutionX = omit.From(val)
@ -186,6 +193,9 @@ func (o PublicreportImageTemplate) Build() *models.PublicreportImage {
if o.Created != nil {
m.Created = o.Created()
}
if o.Location != nil {
m.Location = o.Location()
}
if o.ResolutionX != nil {
m.ResolutionX = o.ResolutionX()
}
@ -412,6 +422,7 @@ func (m publicreportImageMods) RandomizeAllColumns(f *faker.Faker) PublicreportI
PublicreportImageMods.RandomID(f),
PublicreportImageMods.RandomContentType(f),
PublicreportImageMods.RandomCreated(f),
PublicreportImageMods.RandomLocation(f),
PublicreportImageMods.RandomResolutionX(f),
PublicreportImageMods.RandomResolutionY(f),
PublicreportImageMods.RandomStorageUUID(f),
@ -513,6 +524,59 @@ func (m publicreportImageMods) RandomCreated(f *faker.Faker) PublicreportImageMo
})
}
// Set the model columns to this value
func (m publicreportImageMods) Location(val null.Val[string]) PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
o.Location = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m publicreportImageMods) LocationFunc(f func() null.Val[string]) PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
o.Location = f
})
}
// Clear any values for the column
func (m publicreportImageMods) UnsetLocation() PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
o.Location = nil
})
}
// 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 publicreportImageMods) RandomLocation(f *faker.Faker) PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
o.Location = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(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 publicreportImageMods) RandomLocationNotNull(f *faker.Faker) PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {
o.Location = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m publicreportImageMods) ResolutionX(val int32) PublicreportImageMod {
return PublicreportImageModFunc(func(_ context.Context, o *PublicreportImageTemplate) {