From f4a88623afa8e357586e051943da9bb4749c2782 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 21 Jan 2026 03:30:03 +0000 Subject: [PATCH] Overhaul system for handling text messaging Move away from "SMS" as the operative word - we're going RCS. Move all comms processing to a separate goroutine Rename the DB tables --- api/api.go | 4 +- api/endpoint.go | 3 + api/twilio.go | 49 ++ background/arcgis.go | 6 +- background/audio.go | 30 +- background/background.go | 44 ++ background/comms.go | 86 ++- {queue => background}/label_studio.go | 16 +- comms/text.go | 62 +++ comms/{ => voipms}/sms.go | 0 config/config.go | 44 +- ...s.sms_log.bob.go => comms.text_log.bob.go} | 12 +- db/dbinfo/comms.email_log.bob.go | 2 +- ...s.sms_log.bob.go => comms.text_log.bob.go} | 66 +-- db/enums/enums.bob.go | 114 ++-- db/factory/bobfactory_context.bob.go | 16 +- db/factory/bobfactory_main.bob.go | 42 +- db/factory/bobfactory_random.bob.go | 8 +- db/factory/comms.email_log.bob.go | 14 +- db/factory/comms.phone.bob.go | 114 ++-- db/factory/comms.sms_log.bob.go | 523 ------------------ db/factory/comms.text_log.bob.go | 523 ++++++++++++++++++ db/migrations/00036_comms.sql | 20 +- db/models/bob_joins.bob.go | 4 +- db/models/bob_loaders.bob.go | 8 +- db/models/bob_where.bob.go | 6 +- db/models/comms.email_log.bob.go | 12 +- db/models/comms.phone.bob.go | 310 +++++------ ...s.sms_log.bob.go => comms.text_log.bob.go} | 346 ++++++------ go.mod | 9 +- go.sum | 25 + main.go | 36 +- public-report/quick.go | 23 +- queue/audio_processing.go | 23 - queue/comms.go | 38 -- 35 files changed, 1426 insertions(+), 1212 deletions(-) create mode 100644 api/twilio.go create mode 100644 background/background.go rename {queue => background}/label_studio.go (94%) create mode 100644 comms/text.go rename comms/{ => voipms}/sms.go (100%) rename db/dberrors/{comms.sms_log.bob.go => comms.text_log.bob.go} (51%) rename db/dbinfo/{comms.sms_log.bob.go => comms.text_log.bob.go} (64%) delete mode 100644 db/factory/comms.sms_log.bob.go create mode 100644 db/factory/comms.text_log.bob.go rename db/models/{comms.sms_log.bob.go => comms.text_log.bob.go} (51%) delete mode 100644 queue/audio_processing.go delete mode 100644 queue/comms.go diff --git a/api/api.go b/api/api.go index 3e58db81..60226a1a 100644 --- a/api/api.go +++ b/api/api.go @@ -11,10 +11,10 @@ import ( "strconv" "time" + "github.com/Gleipnir-Technology/nidus-sync/background" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/platform" - "github.com/Gleipnir-Technology/nidus-sync/queue" "github.com/Gleipnir-Technology/nidus-sync/userfile" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" @@ -74,7 +74,7 @@ func apiAudioContentPost(w http.ResponseWriter, r *http.Request, u *models.User) http.Error(w, "failed to write content file", http.StatusInternalServerError) } - queue.EnqueueAudioJob(queue.JobAudio{AudioUUID: audioUUID}) + background.AudioTranscode(audioUUID) w.WriteHeader(http.StatusOK) } diff --git a/api/endpoint.go b/api/endpoint.go index fd86109f..14d59cb1 100644 --- a/api/endpoint.go +++ b/api/endpoint.go @@ -21,6 +21,9 @@ func AddRoutes(r chi.Router) { // Unauthenticated endpoints r.Get("/district", apiGetDistrict) + r.Post("/twilio/message", twilioMessagePost) + r.Post("/twilio/status", twilioStatusPost) + r.Post("/twilio/text", twilioTextPost) r.Get("/webhook/fieldseeker", webhookFieldseeker) r.Post("/webhook/fieldseeker", webhookFieldseeker) } diff --git a/api/twilio.go b/api/twilio.go new file mode 100644 index 00000000..7323eb69 --- /dev/null +++ b/api/twilio.go @@ -0,0 +1,49 @@ +package api + +import ( + "fmt" + "net/http" + + "github.com/rs/zerolog/log" + "github.com/twilio/twilio-go/twiml" +) + +func twilioMessagePost(w http.ResponseWriter, r *http.Request) { + message_sid := r.PostFormValue("MessageSid") + log.Info().Str("sid", message_sid).Msg("Twilio Message POST") + fmt.Fprintf(w, "") +} +func twilioStatusPost(w http.ResponseWriter, r *http.Request) { + message_sid := r.PostFormValue("MessageSid") + message_status := r.PostFormValue("MessageStatus") + log.Info().Str("sid", message_sid).Str("status", message_status).Msg("Updated message status") + fmt.Fprintf(w, "") +} +func twilioTextPost(w http.ResponseWriter, r *http.Request) { + message_sid := r.PostFormValue("MessageSid") + account_sid := r.PostFormValue("AccountSid") + messaging_service_sid := r.PostFormValue("MessagingServiceSid") + from := r.PostFormValue("From") + to_ := r.PostFormValue("To") + body := r.PostFormValue("Body") + num_media := r.PostFormValue("NumMedia") + num_segments := r.PostFormValue("NumSegments") + media_content_type0 := r.PostFormValue("MediaContentType0") + media_url0 := r.PostFormValue("MediaUrl0") + from_city := r.PostFormValue("FromCity") + from_state := r.PostFormValue("FromState") + from_zip := r.PostFormValue("FromZip") + from_country := r.PostFormValue("FromCountry") + to_city := r.PostFormValue("ToCity") + to_state := r.PostFormValue("ToState") + to_zip := r.PostFormValue("ToZip") + to_country := r.PostFormValue("ToCountry") + log.Info().Str("message_sid", message_sid).Str("account_sid", account_sid).Str("messaging_service_sid", messaging_service_sid).Str("from", from).Str("to_", to_).Str("body", body).Str("num_media", num_media).Str("num_segments", num_segments).Str("media_content_type0", media_content_type0).Str("media_url0", media_url0).Str("from_city", from_city).Str("from_state", from_state).Str("from_zip", from_zip).Str("from_country", from_country).Str("to_city", to_city).Str("to_state", to_state).Str("to_zip", to_zip).Str("to_country", to_country).Msg("got text") + twiml, _ := twiml.Messages([]twiml.Element{ + &twiml.MessagingMessage{ + Body: "Hey there.", + }, + }) + w.Header().Set("Content-Type", "text/xml") + fmt.Fprintf(w, "%s", twiml) +} diff --git a/background/arcgis.go b/background/arcgis.go index d53177da..94aae8ca 100644 --- a/background/arcgis.go +++ b/background/arcgis.go @@ -51,7 +51,7 @@ type NoOAuthForOrg struct{} func (e NoOAuthForOrg) Error() string { return "No oauth available for organization" } -var NewOAuthTokenChannel chan struct{} +var newOAuthTokenChannel chan struct{} var CodeVerifier string = "random_secure_string_min_43_chars_long_should_be_stored_in_session" type OAuthTokenResponse struct { @@ -118,7 +118,7 @@ func IsSyncOngoing(org_id int32) bool { } // This is a goroutine that is in charge of getting Fieldseeker data and keeping it fresh. -func RefreshFieldseekerData(ctx context.Context, newOauthCh <-chan struct{}) { +func refreshFieldseekerData(ctx context.Context, newOauthCh <-chan struct{}) { syncStatusByOrg = make(map[int32]bool, 0) for { workerCtx, cancel := context.WithCancel(context.Background()) @@ -328,7 +328,7 @@ func updateArcgisUserData(ctx context.Context, user *models.User, access_token s maybeCreateWebhook(ctx, fieldseekerClient) downloadFieldseekerSchema(ctx, fieldseekerClient, arcgis_id) notification.ClearOauth(ctx, user) - NewOAuthTokenChannel <- struct{}{} + newOAuthTokenChannel <- struct{}{} } func updatePortalData(ctx context.Context, client *arcgis.ArcGIS, user_id int32) (*arcgis.PortalsResponse, error) { diff --git a/background/audio.go b/background/audio.go index b61a0546..ddd2b4e6 100644 --- a/background/audio.go +++ b/background/audio.go @@ -8,14 +8,26 @@ import ( "os/exec" "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/queue" "github.com/Gleipnir-Technology/nidus-sync/userfile" "github.com/google/uuid" "github.com/rs/zerolog/log" ) -// StartAudioWorker initializes the audio job channel and starts the worker goroutine. -func StartWorkerAudio(ctx context.Context, audioJobChannel chan queue.JobAudio) { +// AudioJob represents a job to process an audio file. +type jobAudio struct { + AudioUUID uuid.UUID +} + +var channelJobAudio chan jobAudio + +func AudioTranscode(audio_uuid uuid.UUID) { + enqueueAudioJob(jobAudio{ + AudioUUID: audio_uuid, + }) +} + +// startAudioWorker initializes the audio job channel and starts the worker goroutine. +func startWorkerAudio(ctx context.Context, audioJobChannel chan jobAudio) { go func() { for { select { @@ -33,6 +45,16 @@ func StartWorkerAudio(ctx context.Context, audioJobChannel chan queue.JobAudio) }() } +// EnqueueAudioJob sends an audio processing job to the worker. +func enqueueAudioJob(job jobAudio) { + select { + case channelJobAudio <- job: + log.Info().Str("uuid", job.AudioUUID.String()).Msg("Enqueued audio job") + default: + log.Warn().Str("uuid", job.AudioUUID.String()).Msg("Audio job channel is full, dropping job") + } +} + func normalizeAudio(audioUUID uuid.UUID) error { source := userfile.AudioFileContentPathRaw(audioUUID.String()) _, err := os.Stat(source) @@ -70,7 +92,7 @@ func processAudioFile(audioUUID uuid.UUID) error { return fmt.Errorf("failed to transcode audio %s to OGG: %v", audioUUID, err) } - queue.EnqueueLabelStudioJob(queue.LabelStudioJob{ + enqueueLabelStudioJob(jobLabelStudio{ UUID: audioUUID, }) return nil diff --git a/background/background.go b/background/background.go new file mode 100644 index 00000000..b800ac83 --- /dev/null +++ b/background/background.go @@ -0,0 +1,44 @@ +package background + +import ( + "context" + "sync" +) + +var waitGroup sync.WaitGroup + +func Start(ctx context.Context) { + newOAuthTokenChannel = make(chan struct{}, 10) + + channelJobAudio = make(chan jobAudio, 100) // Buffered channel to prevent blocking + channelJobEmail = make(chan jobEmail, 100) // Buffered channel to prevent blocking + channelJobText = make(chan jobText, 100) // Buffered channel to prevent blocking + + waitGroup.Add(1) + go func() { + defer waitGroup.Done() + refreshFieldseekerData(ctx, newOAuthTokenChannel) + }() + + waitGroup.Add(1) + go func() { + defer waitGroup.Done() + startWorkerAudio(ctx, channelJobAudio) + }() + + waitGroup.Add(1) + go func() { + defer waitGroup.Done() + startWorkerEmail(ctx, channelJobEmail) + }() + + waitGroup.Add(1) + go func() { + defer waitGroup.Done() + startWorkerText(ctx, channelJobText) + }() +} +func WaitForExit() { + + waitGroup.Wait() +} diff --git a/background/comms.go b/background/comms.go index fd1c6af4..2992a1fd 100644 --- a/background/comms.go +++ b/background/comms.go @@ -2,12 +2,67 @@ package background import ( "context" + "errors" + "fmt" - "github.com/Gleipnir-Technology/nidus-sync/queue" + "github.com/Gleipnir-Technology/nidus-sync/comms" + "github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/rs/zerolog/log" ) -func StartWorkerEmail(ctx context.Context, channel chan queue.JobEmail) { +var channelJobEmail chan jobEmail +var channelJobText chan jobText + +func ReportSubscriptionConfirmationEmail(destination string) { + enqueueJobEmail(jobEmail{ + Destination: destination, + Source: config.ForwardEmailReportAddress, + Type: enums.CommsMessagetypeemailReportSubscriptionConfirmation, + }) +} + +func ReportSubscriptionConfirmationText(destination comms.E164, report_id string) { + enqueueJobText(jobText{ + Destination: destination, + ReportID: report_id, + Source: config.RMOPhoneNumber, + Type: enums.CommsMessagetypetextReportSubscriptionConfirmation, + }) +} + +type jobEmail struct { + Destination string + ReportID string + Source string + Type enums.CommsMessagetypeemail +} +type jobText struct { + Destination comms.E164 + ReportID string + Source comms.E164 + Type enums.CommsMessagetypetext +} + +func enqueueJobEmail(job jobEmail) { + select { + case channelJobEmail <- job: + log.Info().Str("destination", job.Destination).Msg("Enqueued email job") + default: + log.Warn().Msg("email job channel is full, dropping job") + } +} + +func enqueueJobText(job jobText) { + select { + case channelJobText <- job: + log.Info().Msg("Enqueued text job") + default: + log.Warn().Msg("sms job channel is full, dropping job") + } +} + +func startWorkerEmail(ctx context.Context, channel chan jobEmail) { go func() { for { select { @@ -15,7 +70,7 @@ func StartWorkerEmail(ctx context.Context, channel chan queue.JobEmail) { log.Info().Msg("Email worker shutting down.") return case job := <-channel: - err := processJobEmail(job) + err := jobProcessEmail(job) if err != nil { log.Error().Err(err).Str("dest", job.Destination).Str("type", string(job.Type)).Msg("Error processing audio file") } @@ -24,7 +79,7 @@ func StartWorkerEmail(ctx context.Context, channel chan queue.JobEmail) { }() } -func StartWorkerSMS(ctx context.Context, channel chan queue.JobSMS) { +func startWorkerText(ctx context.Context, channel chan jobText) { go func() { for { select { @@ -32,21 +87,34 @@ func StartWorkerSMS(ctx context.Context, channel chan queue.JobSMS) { log.Info().Msg("Email worker shutting down.") return case job := <-channel: - err := processJobSMS(job) + err := jobProcessText(job) if err != nil { - log.Error().Err(err).Str("dest", job.Destination).Str("type", string(job.Type)).Msg("Error processing audio file") + log.Error().Err(err).Str("type", string(job.Type)).Msg("Error processing text message job") } } } }() } -func processJobEmail(job queue.JobEmail) error { +func jobProcessEmail(job jobEmail) error { log.Info().Str("dest", job.Destination).Str("type", string(job.Type)).Msg("Pretend doing email job") return nil } -func processJobSMS(job queue.JobSMS) error { - log.Info().Str("dest", job.Destination).Str("type", string(job.Type)).Msg("Pretend doing email job") +func jobProcessText(job jobText) error { + var message string + switch job.Type { + case enums.CommsMessagetypetextInitialContact: + message = "This is Report Mosquitoes Online. We just got your number. Text \"YES\" to get texts, or \"STOP\" to stap." + case enums.CommsMessagetypetextReportSubscriptionConfirmation: + message = "Thanks for submitting a mosquito report. Text for any questions. We'll send you updates as we get them." + default: + return errors.New("No idea what message to send") + } + err := comms.SendText(job.Source, job.Destination, message) + if err != nil { + log.Error().Err(err).Msg("Failed to send text message") + return fmt.Errorf("Failed to send message '%s' to '%s'", job.Type, job.Destination) + } return nil } diff --git a/queue/label_studio.go b/background/label_studio.go similarity index 94% rename from queue/label_studio.go rename to background/label_studio.go index 1cf1a1d2..fa8c34f5 100644 --- a/queue/label_studio.go +++ b/background/label_studio.go @@ -1,4 +1,4 @@ -package queue +package background import ( "context" @@ -16,15 +16,15 @@ import ( "github.com/google/uuid" ) -type LabelStudioJob struct { +type jobLabelStudio struct { UUID uuid.UUID } -var labelJobChannel chan LabelStudioJob +var channelJobLabelStudio chan jobLabelStudio -func EnqueueLabelStudioJob(job LabelStudioJob) { +func enqueueLabelStudioJob(job jobLabelStudio) { select { - case labelJobChannel <- job: + case channelJobLabelStudio <- job: log.Printf("Enqueued label job for UUID: %s", job.UUID) default: log.Printf("Label job channel is full, dropping job for UUID: %s", job.UUID) @@ -49,7 +49,7 @@ func StartLabelStudioWorker(ctx context.Context) error { return fmt.Errorf("Failed to create minio client: %v", err) } buffer := 100 - labelJobChannel = make(chan LabelStudioJob, buffer) // Buffered channel to prevent blocking + channelJobLabelStudio = make(chan jobLabelStudio, buffer) // Buffered channel to prevent blocking log.Printf("Started label studio worker with buffer depth %d", buffer) go func() { for { @@ -57,7 +57,7 @@ func StartLabelStudioWorker(ctx context.Context) error { case <-ctx.Done(): log.Println("Audio worker shutting down.") return - case job := <-labelJobChannel: + case job := <-channelJobLabelStudio: log.Printf("Processing label job for UUID: %s", job.UUID) err := processLabelTask(ctx, minioClient, minioBucket, labelStudioClient, project, job) if err != nil { @@ -99,7 +99,7 @@ func createLabelStudioClient() (*labelstudio.Client, error) { return labelStudioClient, nil } -func processLabelTask(ctx context.Context, minioClient *minio.Client, minioBucket string, labelStudioClient *labelstudio.Client, project *labelstudio.Project, job LabelStudioJob) error { +func processLabelTask(ctx context.Context, minioClient *minio.Client, minioBucket string, labelStudioClient *labelstudio.Client, project *labelstudio.Project, job jobLabelStudio) error { customer := os.Getenv("CUSTOMER") if customer == "" { return errors.New("You must specify a CUSTOMER env var") diff --git a/comms/text.go b/comms/text.go new file mode 100644 index 00000000..5dfce308 --- /dev/null +++ b/comms/text.go @@ -0,0 +1,62 @@ +package comms + +import ( + "encoding/json" + "fmt" + + "github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/nyaruka/phonenumbers" + "github.com/rs/zerolog/log" + "github.com/twilio/twilio-go" + twilioApi "github.com/twilio/twilio-go/rest/api/v2010" +) + +type E164 = phonenumbers.PhoneNumber + +func ParsePhoneNumber(input string) (*E164, error) { + return phonenumbers.Parse(input, "US") +} + +func SendText(source E164, destination E164, message string) error { + log.Info().Msg("Sending text message...") + // Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment + client := twilio.NewRestClient() + + params := &twilioApi.CreateMessageParams{} + params.SetMessagingServiceSid(config.TwilioMessagingServiceSID) + + params.SetBody(message) + dest := phonenumbers.Format(&destination, phonenumbers.E164) + params.SetTo(dest) + resp, err := client.Api.CreateMessage(params) + + if err != nil { + return fmt.Errorf("Failed to create message to %s: %w", dest, err) + } else { + if resp.Body != nil { + log.Info().Str("dest", dest).Str("body", *resp.Body).Msg("Text message response") + } else { + log.Info().Str("dest", dest).Msg("Text message response is nil") + } + } + return nil +} + +func sendSMS(destination, source, message string) error { + client := twilio.NewRestClientWithParams(twilio.ClientParams{ + Username: config.TwilioAccountSID, + Password: config.TwilioAuthToken, + }) + params := &twilioApi.CreateMessageParams{} + params.SetTo("+15558675309") + params.SetFrom("+15017250604") + params.SetBody("Hello from Go!") + + resp, err := client.Api.CreateMessage(params) + if err != nil { + return fmt.Errorf("Error sending SMS message: %w", err) + } + response, _ := json.Marshal(*resp) + log.Debug().Str("response", string(response)).Msg("Send SMS") + return nil +} diff --git a/comms/sms.go b/comms/voipms/sms.go similarity index 100% rename from comms/sms.go rename to comms/voipms/sms.go diff --git a/config/config.go b/config/config.go index 1bd04286..e82e04ea 100644 --- a/config/config.go +++ b/config/config.go @@ -5,6 +5,8 @@ import ( "net/url" "os" "strconv" + + "github.com/nyaruka/phonenumbers" ) var ( @@ -21,12 +23,14 @@ var ( ForwardEmailReportUsername string MapboxToken string PGDSN string + RMODomain string + RMOPhoneNumber phonenumbers.PhoneNumber URLReport string URLSync string URLTegola string - VoipMSPassword string - VoipMSNumber string - VoipMSUsername string + TwilioAuthToken string + TwilioAccountSID string + TwilioMessagingServiceSID string ) // Build the ArcGIS authorization URL with PKCE @@ -62,7 +66,7 @@ func MakeURLSync(path string) string { return fmt.Sprintf("https://%s%s", URLSync, path) } -func Parse() error { +func Parse() (err error) { Bind = os.Getenv("BIND") if Bind == "" { Bind = ":9001" @@ -118,6 +122,20 @@ func Parse() error { if PGDSN == "" { return fmt.Errorf("You must specify a non-empty POSTGRES_DSN") } + RMODomain = os.Getenv("RMO_DOMAIN") + if RMODomain == "" { + return fmt.Errorf("You must specify a non-empty RMO_DOMAIN") + } + rmo_phone_number := os.Getenv("RMO_PHONE_NUMBER") + if rmo_phone_number == "" { + return fmt.Errorf("You must specify a non-empty RMO_PHONE_NUMBER") + } + p, err := phonenumbers.Parse(rmo_phone_number, "US") + if err != nil { + return fmt.Errorf("Failed to parse '%s' as a valid phone number: %w", rmo_phone_number, err) + } + RMOPhoneNumber = *p + URLReport = os.Getenv("URL_REPORT") if URLReport == "" { return fmt.Errorf("You must specify a non-empty URL_REPORT") @@ -130,17 +148,17 @@ func Parse() error { if URLTegola == "" { return fmt.Errorf("You must specify a non-empty URL_TEGOLA") } - VoipMSNumber = os.Getenv("VOIPMS_NUMBER") - if VoipMSNumber == "" { - return fmt.Errorf("You must specify a non-empty VOIPMS_NUMBER") + TwilioAccountSID = os.Getenv("TWILIO_ACCOUNT_SID") + if TwilioAccountSID == "" { + return fmt.Errorf("You must specify a non-empty TWILIO_ACCOUNT_SID") } - VoipMSPassword = os.Getenv("VOIPMS_PASSWORD") - if VoipMSPassword == "" { - return fmt.Errorf("You must specify a non-empty VOIPMS_PASSWORD") + TwilioAuthToken = os.Getenv("TWILIO_AUTH_TOKEN") + if TwilioAuthToken == "" { + return fmt.Errorf("You must specify a non-empty TWILIO_AUTH_TOKEN") } - VoipMSUsername = os.Getenv("VOIPMS_USERNAME") - if VoipMSUsername == "" { - return fmt.Errorf("You must specify a non-empty VOIPMS_USERNAME") + TwilioMessagingServiceSID = os.Getenv("TWILIO_MESSAGING_SERVICE_SID") + if TwilioMessagingServiceSID == "" { + return fmt.Errorf("You must specify a non-empty TWILIO_MESSAGING_SERVICE_SID") } return nil } diff --git a/db/dberrors/comms.sms_log.bob.go b/db/dberrors/comms.text_log.bob.go similarity index 51% rename from db/dberrors/comms.sms_log.bob.go rename to db/dberrors/comms.text_log.bob.go index e4d154a4..4611eb7a 100644 --- a/db/dberrors/comms.sms_log.bob.go +++ b/db/dberrors/comms.text_log.bob.go @@ -3,15 +3,15 @@ package dberrors -var CommsSMSLogErrors = &commsSMSLogErrors{ - ErrUniqueSmsLogPkey: &UniqueConstraintError{ +var CommsTextLogErrors = &commsTextLogErrors{ + ErrUniqueTextLogPkey: &UniqueConstraintError{ schema: "comms", - table: "sms_log", + table: "text_log", columns: []string{"destination", "source", "type"}, - s: "sms_log_pkey", + s: "text_log_pkey", }, } -type commsSMSLogErrors struct { - ErrUniqueSmsLogPkey *UniqueConstraintError +type commsTextLogErrors struct { + ErrUniqueTextLogPkey *UniqueConstraintError } diff --git a/db/dbinfo/comms.email_log.bob.go b/db/dbinfo/comms.email_log.bob.go index 055042bf..5fd8a244 100644 --- a/db/dbinfo/comms.email_log.bob.go +++ b/db/dbinfo/comms.email_log.bob.go @@ -44,7 +44,7 @@ var CommsEmailLogs = Table[ }, Type: column{ Name: "type", - DBType: "comms.emailmessagetype", + DBType: "comms.messagetypeemail", Default: "", Comment: "", Nullable: false, diff --git a/db/dbinfo/comms.sms_log.bob.go b/db/dbinfo/comms.text_log.bob.go similarity index 64% rename from db/dbinfo/comms.sms_log.bob.go rename to db/dbinfo/comms.text_log.bob.go index 7f21a59a..308ca842 100644 --- a/db/dbinfo/comms.sms_log.bob.go +++ b/db/dbinfo/comms.text_log.bob.go @@ -5,16 +5,16 @@ package dbinfo import "github.com/aarondl/opt/null" -var CommsSMSLogs = Table[ - commsSMSLogColumns, - commsSMSLogIndexes, - commsSMSLogForeignKeys, - commsSMSLogUniques, - commsSMSLogChecks, +var CommsTextLogs = Table[ + commsTextLogColumns, + commsTextLogIndexes, + commsTextLogForeignKeys, + commsTextLogUniques, + commsTextLogChecks, ]{ Schema: "comms", - Name: "sms_log", - Columns: commsSMSLogColumns{ + Name: "text_log", + Columns: commsTextLogColumns{ Created: column{ Name: "created", DBType: "timestamp without time zone", @@ -44,7 +44,7 @@ var CommsSMSLogs = Table[ }, Type: column{ Name: "type", - DBType: "comms.smsmessagetype", + DBType: "comms.messagetypetext", Default: "", Comment: "", Nullable: false, @@ -52,10 +52,10 @@ var CommsSMSLogs = Table[ AutoIncr: false, }, }, - Indexes: commsSMSLogIndexes{ - SMSLogPkey: index{ + Indexes: commsTextLogIndexes{ + TextLogPkey: index{ Type: "btree", - Name: "sms_log_pkey", + Name: "text_log_pkey", Columns: []indexColumn{ { Name: "destination", @@ -82,23 +82,23 @@ var CommsSMSLogs = Table[ }, }, PrimaryKey: &constraint{ - Name: "sms_log_pkey", + Name: "text_log_pkey", Columns: []string{"destination", "source", "type"}, Comment: "", }, - ForeignKeys: commsSMSLogForeignKeys{ - CommsSMSLogSMSLogDestinationFkey: foreignKey{ + ForeignKeys: commsTextLogForeignKeys{ + CommsTextLogTextLogDestinationFkey: foreignKey{ constraint: constraint{ - Name: "comms.sms_log.sms_log_destination_fkey", + Name: "comms.text_log.text_log_destination_fkey", Columns: []string{"destination"}, Comment: "", }, ForeignTable: "comms.phone", ForeignColumns: []string{"e164"}, }, - CommsSMSLogSMSLogSourceFkey: foreignKey{ + CommsTextLogTextLogSourceFkey: foreignKey{ constraint: constraint{ - Name: "comms.sms_log.sms_log_source_fkey", + Name: "comms.text_log.text_log_source_fkey", Columns: []string{"source"}, Comment: "", }, @@ -110,48 +110,48 @@ var CommsSMSLogs = Table[ Comment: "", } -type commsSMSLogColumns struct { +type commsTextLogColumns struct { Created column Destination column Source column Type column } -func (c commsSMSLogColumns) AsSlice() []column { +func (c commsTextLogColumns) AsSlice() []column { return []column{ c.Created, c.Destination, c.Source, c.Type, } } -type commsSMSLogIndexes struct { - SMSLogPkey index +type commsTextLogIndexes struct { + TextLogPkey index } -func (i commsSMSLogIndexes) AsSlice() []index { +func (i commsTextLogIndexes) AsSlice() []index { return []index{ - i.SMSLogPkey, + i.TextLogPkey, } } -type commsSMSLogForeignKeys struct { - CommsSMSLogSMSLogDestinationFkey foreignKey - CommsSMSLogSMSLogSourceFkey foreignKey +type commsTextLogForeignKeys struct { + CommsTextLogTextLogDestinationFkey foreignKey + CommsTextLogTextLogSourceFkey foreignKey } -func (f commsSMSLogForeignKeys) AsSlice() []foreignKey { +func (f commsTextLogForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.CommsSMSLogSMSLogDestinationFkey, f.CommsSMSLogSMSLogSourceFkey, + f.CommsTextLogTextLogDestinationFkey, f.CommsTextLogTextLogSourceFkey, } } -type commsSMSLogUniques struct{} +type commsTextLogUniques struct{} -func (u commsSMSLogUniques) AsSlice() []constraint { +func (u commsTextLogUniques) AsSlice() []constraint { return []constraint{} } -type commsSMSLogChecks struct{} +type commsTextLogChecks struct{} -func (c commsSMSLogChecks) AsSlice() []check { +func (c commsTextLogChecks) AsSlice() []check { return []check{} } diff --git a/db/enums/enums.bob.go b/db/enums/enums.bob.go index 22fde9b7..373cd454 100644 --- a/db/enums/enums.bob.go +++ b/db/enums/enums.bob.go @@ -193,32 +193,35 @@ func (e *Audiodatatype) Scan(value any) error { return nil } -// Enum values for CommsEmailmessagetype +// Enum values for CommsMessagetypeemail const ( - CommsEmailmessagetypeReportSubscriptionConfirmation CommsEmailmessagetype = "report-subscription-confirmation" - CommsEmailmessagetypeReportStatusScheduled CommsEmailmessagetype = "report-status-scheduled" - CommsEmailmessagetypeReportStatusComplete CommsEmailmessagetype = "report-status-complete" + CommsMessagetypeemailInitialContact CommsMessagetypeemail = "initial-contact" + CommsMessagetypeemailReportSubscriptionConfirmation CommsMessagetypeemail = "report-subscription-confirmation" + CommsMessagetypeemailReportStatusScheduled CommsMessagetypeemail = "report-status-scheduled" + CommsMessagetypeemailReportStatusComplete CommsMessagetypeemail = "report-status-complete" ) -func AllCommsEmailmessagetype() []CommsEmailmessagetype { - return []CommsEmailmessagetype{ - CommsEmailmessagetypeReportSubscriptionConfirmation, - CommsEmailmessagetypeReportStatusScheduled, - CommsEmailmessagetypeReportStatusComplete, +func AllCommsMessagetypeemail() []CommsMessagetypeemail { + return []CommsMessagetypeemail{ + CommsMessagetypeemailInitialContact, + CommsMessagetypeemailReportSubscriptionConfirmation, + CommsMessagetypeemailReportStatusScheduled, + CommsMessagetypeemailReportStatusComplete, } } -type CommsEmailmessagetype string +type CommsMessagetypeemail string -func (e CommsEmailmessagetype) String() string { +func (e CommsMessagetypeemail) String() string { return string(e) } -func (e CommsEmailmessagetype) Valid() bool { +func (e CommsMessagetypeemail) Valid() bool { switch e { - case CommsEmailmessagetypeReportSubscriptionConfirmation, - CommsEmailmessagetypeReportStatusScheduled, - CommsEmailmessagetypeReportStatusComplete: + case CommsMessagetypeemailInitialContact, + CommsMessagetypeemailReportSubscriptionConfirmation, + CommsMessagetypeemailReportStatusScheduled, + CommsMessagetypeemailReportStatusComplete: return true default: return false @@ -226,75 +229,78 @@ func (e CommsEmailmessagetype) Valid() bool { } // useful when testing in other packages -func (e CommsEmailmessagetype) All() []CommsEmailmessagetype { - return AllCommsEmailmessagetype() +func (e CommsMessagetypeemail) All() []CommsMessagetypeemail { + return AllCommsMessagetypeemail() } -func (e CommsEmailmessagetype) MarshalText() ([]byte, error) { +func (e CommsMessagetypeemail) MarshalText() ([]byte, error) { return []byte(e), nil } -func (e *CommsEmailmessagetype) UnmarshalText(text []byte) error { +func (e *CommsMessagetypeemail) UnmarshalText(text []byte) error { return e.Scan(text) } -func (e CommsEmailmessagetype) MarshalBinary() ([]byte, error) { +func (e CommsMessagetypeemail) MarshalBinary() ([]byte, error) { return []byte(e), nil } -func (e *CommsEmailmessagetype) UnmarshalBinary(data []byte) error { +func (e *CommsMessagetypeemail) UnmarshalBinary(data []byte) error { return e.Scan(data) } -func (e CommsEmailmessagetype) Value() (driver.Value, error) { +func (e CommsMessagetypeemail) Value() (driver.Value, error) { return string(e), nil } -func (e *CommsEmailmessagetype) Scan(value any) error { +func (e *CommsMessagetypeemail) Scan(value any) error { switch x := value.(type) { case string: - *e = CommsEmailmessagetype(x) + *e = CommsMessagetypeemail(x) case []byte: - *e = CommsEmailmessagetype(x) + *e = CommsMessagetypeemail(x) case nil: - return fmt.Errorf("cannot nil into CommsEmailmessagetype") + return fmt.Errorf("cannot nil into CommsMessagetypeemail") default: return fmt.Errorf("cannot scan type %T: %v", value, value) } if !e.Valid() { - return fmt.Errorf("invalid CommsEmailmessagetype value: %s", *e) + return fmt.Errorf("invalid CommsMessagetypeemail value: %s", *e) } return nil } -// Enum values for CommsSmsmessagetype +// Enum values for CommsMessagetypetext const ( - CommsSmsmessagetypeReportSubscriptionConfirmation CommsSmsmessagetype = "report-subscription-confirmation" - CommsSmsmessagetypeReportStatusScheduled CommsSmsmessagetype = "report-status-scheduled" - CommsSmsmessagetypeReportStatusComplete CommsSmsmessagetype = "report-status-complete" + CommsMessagetypetextInitialContact CommsMessagetypetext = "initial-contact" + CommsMessagetypetextReportSubscriptionConfirmation CommsMessagetypetext = "report-subscription-confirmation" + CommsMessagetypetextReportStatusScheduled CommsMessagetypetext = "report-status-scheduled" + CommsMessagetypetextReportStatusComplete CommsMessagetypetext = "report-status-complete" ) -func AllCommsSmsmessagetype() []CommsSmsmessagetype { - return []CommsSmsmessagetype{ - CommsSmsmessagetypeReportSubscriptionConfirmation, - CommsSmsmessagetypeReportStatusScheduled, - CommsSmsmessagetypeReportStatusComplete, +func AllCommsMessagetypetext() []CommsMessagetypetext { + return []CommsMessagetypetext{ + CommsMessagetypetextInitialContact, + CommsMessagetypetextReportSubscriptionConfirmation, + CommsMessagetypetextReportStatusScheduled, + CommsMessagetypetextReportStatusComplete, } } -type CommsSmsmessagetype string +type CommsMessagetypetext string -func (e CommsSmsmessagetype) String() string { +func (e CommsMessagetypetext) String() string { return string(e) } -func (e CommsSmsmessagetype) Valid() bool { +func (e CommsMessagetypetext) Valid() bool { switch e { - case CommsSmsmessagetypeReportSubscriptionConfirmation, - CommsSmsmessagetypeReportStatusScheduled, - CommsSmsmessagetypeReportStatusComplete: + case CommsMessagetypetextInitialContact, + CommsMessagetypetextReportSubscriptionConfirmation, + CommsMessagetypetextReportStatusScheduled, + CommsMessagetypetextReportStatusComplete: return true default: return false @@ -302,44 +308,44 @@ func (e CommsSmsmessagetype) Valid() bool { } // useful when testing in other packages -func (e CommsSmsmessagetype) All() []CommsSmsmessagetype { - return AllCommsSmsmessagetype() +func (e CommsMessagetypetext) All() []CommsMessagetypetext { + return AllCommsMessagetypetext() } -func (e CommsSmsmessagetype) MarshalText() ([]byte, error) { +func (e CommsMessagetypetext) MarshalText() ([]byte, error) { return []byte(e), nil } -func (e *CommsSmsmessagetype) UnmarshalText(text []byte) error { +func (e *CommsMessagetypetext) UnmarshalText(text []byte) error { return e.Scan(text) } -func (e CommsSmsmessagetype) MarshalBinary() ([]byte, error) { +func (e CommsMessagetypetext) MarshalBinary() ([]byte, error) { return []byte(e), nil } -func (e *CommsSmsmessagetype) UnmarshalBinary(data []byte) error { +func (e *CommsMessagetypetext) UnmarshalBinary(data []byte) error { return e.Scan(data) } -func (e CommsSmsmessagetype) Value() (driver.Value, error) { +func (e CommsMessagetypetext) Value() (driver.Value, error) { return string(e), nil } -func (e *CommsSmsmessagetype) Scan(value any) error { +func (e *CommsMessagetypetext) Scan(value any) error { switch x := value.(type) { case string: - *e = CommsSmsmessagetype(x) + *e = CommsMessagetypetext(x) case []byte: - *e = CommsSmsmessagetype(x) + *e = CommsMessagetypetext(x) case nil: - return fmt.Errorf("cannot nil into CommsSmsmessagetype") + return fmt.Errorf("cannot nil into CommsMessagetypetext") default: return fmt.Errorf("cannot scan type %T: %v", value, value) } if !e.Valid() { - return fmt.Errorf("invalid CommsSmsmessagetype value: %s", *e) + return fmt.Errorf("invalid CommsMessagetypetext value: %s", *e) } return nil diff --git a/db/factory/bobfactory_context.bob.go b/db/factory/bobfactory_context.bob.go index ae8248ec..ac0e7e05 100644 --- a/db/factory/bobfactory_context.bob.go +++ b/db/factory/bobfactory_context.bob.go @@ -27,15 +27,15 @@ var ( 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") + commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading") + commsPhoneRelSourceEmailLogsCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey") + commsPhoneRelDestinationTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey") + commsPhoneRelSourceTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_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 comms.text_log + commsTextLogWithParentsCascadingCtx = newContextual[bool]("commsTextLogWithParentsCascading") + commsTextLogRelDestinationPhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey") + commsTextLogRelSourcePhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey") // Relationship Contexts for fieldseeker.containerrelate fieldseekerContainerrelateWithParentsCascadingCtx = newContextual[bool]("fieldseekerContainerrelateWithParentsCascading") diff --git a/db/factory/bobfactory_main.bob.go b/db/factory/bobfactory_main.bob.go index e74cd371..e49d9b54 100644 --- a/db/factory/bobfactory_main.bob.go +++ b/db/factory/bobfactory_main.bob.go @@ -23,7 +23,7 @@ type Factory struct { baseCommsEmailMods CommsEmailModSlice baseCommsEmailLogMods CommsEmailLogModSlice baseCommsPhoneMods CommsPhoneModSlice - baseCommsSMSLogMods CommsSMSLogModSlice + baseCommsTextLogMods CommsTextLogModSlice baseFieldseekerContainerrelateMods FieldseekerContainerrelateModSlice baseFieldseekerFieldscoutinglogMods FieldseekerFieldscoutinglogModSlice baseFieldseekerHabitatrelateMods FieldseekerHabitatrelateModSlice @@ -213,7 +213,7 @@ func (f *Factory) FromExistingCommsEmailLog(m *models.CommsEmailLog) *CommsEmail 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 } + o.Type = func() enums.CommsMessagetypeemail { return m.Type } ctx := context.Background() if m.R.DestinationEmail != nil { @@ -252,46 +252,46 @@ func (f *Factory) FromExistingCommsPhone(m *models.CommsPhone) *CommsPhoneTempla 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.DestinationTextLogs) > 0 { + CommsPhoneMods.AddExistingDestinationTextLogs(m.R.DestinationTextLogs...).Apply(ctx, o) } - if len(m.R.SourceSMSLogs) > 0 { - CommsPhoneMods.AddExistingSourceSMSLogs(m.R.SourceSMSLogs...).Apply(ctx, o) + if len(m.R.SourceTextLogs) > 0 { + CommsPhoneMods.AddExistingSourceTextLogs(m.R.SourceTextLogs...).Apply(ctx, o) } return o } -func (f *Factory) NewCommsSMSLog(mods ...CommsSMSLogMod) *CommsSMSLogTemplate { - return f.NewCommsSMSLogWithContext(context.Background(), mods...) +func (f *Factory) NewCommsTextLog(mods ...CommsTextLogMod) *CommsTextLogTemplate { + return f.NewCommsTextLogWithContext(context.Background(), mods...) } -func (f *Factory) NewCommsSMSLogWithContext(ctx context.Context, mods ...CommsSMSLogMod) *CommsSMSLogTemplate { - o := &CommsSMSLogTemplate{f: f} +func (f *Factory) NewCommsTextLogWithContext(ctx context.Context, mods ...CommsTextLogMod) *CommsTextLogTemplate { + o := &CommsTextLogTemplate{f: f} if f != nil { - f.baseCommsSMSLogMods.Apply(ctx, o) + f.baseCommsTextLogMods.Apply(ctx, o) } - CommsSMSLogModSlice(mods).Apply(ctx, o) + CommsTextLogModSlice(mods).Apply(ctx, o) return o } -func (f *Factory) FromExistingCommsSMSLog(m *models.CommsSMSLog) *CommsSMSLogTemplate { - o := &CommsSMSLogTemplate{f: f, alreadyPersisted: true} +func (f *Factory) FromExistingCommsTextLog(m *models.CommsTextLog) *CommsTextLogTemplate { + o := &CommsTextLogTemplate{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 } + o.Type = func() enums.CommsMessagetypetext { return m.Type } ctx := context.Background() if m.R.DestinationPhone != nil { - CommsSMSLogMods.WithExistingDestinationPhone(m.R.DestinationPhone).Apply(ctx, o) + CommsTextLogMods.WithExistingDestinationPhone(m.R.DestinationPhone).Apply(ctx, o) } if m.R.SourcePhone != nil { - CommsSMSLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o) + CommsTextLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o) } return o @@ -3198,12 +3198,12 @@ func (f *Factory) AddBaseCommsPhoneMod(mods ...CommsPhoneMod) { f.baseCommsPhoneMods = append(f.baseCommsPhoneMods, mods...) } -func (f *Factory) ClearBaseCommsSMSLogMods() { - f.baseCommsSMSLogMods = nil +func (f *Factory) ClearBaseCommsTextLogMods() { + f.baseCommsTextLogMods = nil } -func (f *Factory) AddBaseCommsSMSLogMod(mods ...CommsSMSLogMod) { - f.baseCommsSMSLogMods = append(f.baseCommsSMSLogMods, mods...) +func (f *Factory) AddBaseCommsTextLogMod(mods ...CommsTextLogMod) { + f.baseCommsTextLogMods = append(f.baseCommsTextLogMods, mods...) } func (f *Factory) ClearBaseFieldseekerContainerrelateMods() { diff --git a/db/factory/bobfactory_random.bob.go b/db/factory/bobfactory_random.bob.go index 38bd82d3..120f1c21 100644 --- a/db/factory/bobfactory_random.bob.go +++ b/db/factory/bobfactory_random.bob.go @@ -89,22 +89,22 @@ 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 { +func random_enums_CommsMessagetypeemail(f *faker.Faker, limits ...string) enums.CommsMessagetypeemail { if f == nil { f = &defaultFaker } - var e enums.CommsEmailmessagetype + var e enums.CommsMessagetypeemail all := e.All() return all[f.IntBetween(0, len(all)-1)] } -func random_enums_CommsSmsmessagetype(f *faker.Faker, limits ...string) enums.CommsSmsmessagetype { +func random_enums_CommsMessagetypetext(f *faker.Faker, limits ...string) enums.CommsMessagetypetext { if f == nil { f = &defaultFaker } - var e enums.CommsSmsmessagetype + var e enums.CommsMessagetypetext all := e.All() return all[f.IntBetween(0, len(all)-1)] } diff --git a/db/factory/comms.email_log.bob.go b/db/factory/comms.email_log.bob.go index 1a643a2b..07f72bdb 100644 --- a/db/factory/comms.email_log.bob.go +++ b/db/factory/comms.email_log.bob.go @@ -39,7 +39,7 @@ type CommsEmailLogTemplate struct { Created func() time.Time Destination func() string Source func() string - Type func() enums.CommsEmailmessagetype + Type func() enums.CommsMessagetypeemail r commsEmailLogR f *Factory @@ -172,7 +172,7 @@ func ensureCreatableCommsEmailLog(m *models.CommsEmailLogSetter) { m.Source = omit.From(val) } if !(m.Type.IsValue()) { - val := random_enums_CommsEmailmessagetype(nil) + val := random_enums_CommsMessagetypeemail(nil) m.Type = omit.From(val) } } @@ -413,14 +413,14 @@ func (m commsEmailLogMods) RandomSource(f *faker.Faker) CommsEmailLogMod { } // Set the model columns to this value -func (m commsEmailLogMods) Type(val enums.CommsEmailmessagetype) CommsEmailLogMod { +func (m commsEmailLogMods) Type(val enums.CommsMessagetypeemail) CommsEmailLogMod { return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) { - o.Type = func() enums.CommsEmailmessagetype { return val } + o.Type = func() enums.CommsMessagetypeemail { return val } }) } // Set the Column from the function -func (m commsEmailLogMods) TypeFunc(f func() enums.CommsEmailmessagetype) CommsEmailLogMod { +func (m commsEmailLogMods) TypeFunc(f func() enums.CommsMessagetypeemail) CommsEmailLogMod { return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) { o.Type = f }) @@ -437,8 +437,8 @@ func (m commsEmailLogMods) UnsetType() CommsEmailLogMod { // 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) + o.Type = func() enums.CommsMessagetypeemail { + return random_enums_CommsMessagetypeemail(f) } }) } diff --git a/db/factory/comms.phone.bob.go b/db/factory/comms.phone.bob.go index bc823c95..26b8eabf 100644 --- a/db/factory/comms.phone.bob.go +++ b/db/factory/comms.phone.bob.go @@ -44,22 +44,22 @@ type CommsPhoneTemplate struct { } type commsPhoneR struct { - SourceEmailLogs []*commsPhoneRSourceEmailLogsR - DestinationSMSLogs []*commsPhoneRDestinationSMSLogsR - SourceSMSLogs []*commsPhoneRSourceSMSLogsR + SourceEmailLogs []*commsPhoneRSourceEmailLogsR + DestinationTextLogs []*commsPhoneRDestinationTextLogsR + SourceTextLogs []*commsPhoneRSourceTextLogsR } type commsPhoneRSourceEmailLogsR struct { number int o *CommsEmailLogTemplate } -type commsPhoneRDestinationSMSLogsR struct { +type commsPhoneRDestinationTextLogsR struct { number int - o *CommsSMSLogTemplate + o *CommsTextLogTemplate } -type commsPhoneRSourceSMSLogsR struct { +type commsPhoneRSourceTextLogsR struct { number int - o *CommsSMSLogTemplate + o *CommsTextLogTemplate } // Apply mods to the CommsPhoneTemplate @@ -85,9 +85,9 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) { o.R.SourceEmailLogs = rel } - if t.r.DestinationSMSLogs != nil { - rel := models.CommsSMSLogSlice{} - for _, r := range t.r.DestinationSMSLogs { + if t.r.DestinationTextLogs != nil { + rel := models.CommsTextLogSlice{} + for _, r := range t.r.DestinationTextLogs { related := r.o.BuildMany(r.number) for _, rel := range related { rel.Destination = o.E164 // h2 @@ -95,12 +95,12 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) { } rel = append(rel, related...) } - o.R.DestinationSMSLogs = rel + o.R.DestinationTextLogs = rel } - if t.r.SourceSMSLogs != nil { - rel := models.CommsSMSLogSlice{} - for _, r := range t.r.SourceSMSLogs { + if t.r.SourceTextLogs != nil { + rel := models.CommsTextLogSlice{} + for _, r := range t.r.SourceTextLogs { related := r.o.BuildMany(r.number) for _, rel := range related { rel.Source = o.E164 // h2 @@ -108,7 +108,7 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) { } rel = append(rel, related...) } - o.R.SourceSMSLogs = rel + o.R.SourceTextLogs = rel } } @@ -209,19 +209,19 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo } } - isDestinationSMSLogsDone, _ := commsPhoneRelDestinationSMSLogsCtx.Value(ctx) - if !isDestinationSMSLogsDone && o.r.DestinationSMSLogs != nil { - ctx = commsPhoneRelDestinationSMSLogsCtx.WithValue(ctx, true) - for _, r := range o.r.DestinationSMSLogs { + isDestinationTextLogsDone, _ := commsPhoneRelDestinationTextLogsCtx.Value(ctx) + if !isDestinationTextLogsDone && o.r.DestinationTextLogs != nil { + ctx = commsPhoneRelDestinationTextLogsCtx.WithValue(ctx, true) + for _, r := range o.r.DestinationTextLogs { if r.o.alreadyPersisted { - m.R.DestinationSMSLogs = append(m.R.DestinationSMSLogs, r.o.Build()) + m.R.DestinationTextLogs = append(m.R.DestinationTextLogs, r.o.Build()) } else { rel1, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachDestinationSMSLogs(ctx, exec, rel1...) + err = m.AttachDestinationTextLogs(ctx, exec, rel1...) if err != nil { return err } @@ -229,19 +229,19 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo } } - isSourceSMSLogsDone, _ := commsPhoneRelSourceSMSLogsCtx.Value(ctx) - if !isSourceSMSLogsDone && o.r.SourceSMSLogs != nil { - ctx = commsPhoneRelSourceSMSLogsCtx.WithValue(ctx, true) - for _, r := range o.r.SourceSMSLogs { + isSourceTextLogsDone, _ := commsPhoneRelSourceTextLogsCtx.Value(ctx) + if !isSourceTextLogsDone && o.r.SourceTextLogs != nil { + ctx = commsPhoneRelSourceTextLogsCtx.WithValue(ctx, true) + for _, r := range o.r.SourceTextLogs { if r.o.alreadyPersisted { - m.R.SourceSMSLogs = append(m.R.SourceSMSLogs, r.o.Build()) + m.R.SourceTextLogs = append(m.R.SourceTextLogs, r.o.Build()) } else { rel2, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachSourceSMSLogs(ctx, exec, rel2...) + err = m.AttachSourceTextLogs(ctx, exec, rel2...) if err != nil { return err } @@ -465,98 +465,98 @@ func (m commsPhoneMods) WithoutSourceEmailLogs() CommsPhoneMod { }) } -func (m commsPhoneMods) WithDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod { +func (m commsPhoneMods) WithDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.DestinationSMSLogs = []*commsPhoneRDestinationSMSLogsR{{ + o.r.DestinationTextLogs = []*commsPhoneRDestinationTextLogsR{{ number: number, o: related, }} }) } -func (m commsPhoneMods) WithNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod { +func (m commsPhoneMods) WithNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - related := o.f.NewCommsSMSLogWithContext(ctx, mods...) - m.WithDestinationSMSLogs(number, related).Apply(ctx, o) + related := o.f.NewCommsTextLogWithContext(ctx, mods...) + m.WithDestinationTextLogs(number, related).Apply(ctx, o) }) } -func (m commsPhoneMods) AddDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod { +func (m commsPhoneMods) AddDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.DestinationSMSLogs = append(o.r.DestinationSMSLogs, &commsPhoneRDestinationSMSLogsR{ + o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{ number: number, o: related, }) }) } -func (m commsPhoneMods) AddNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod { +func (m commsPhoneMods) AddNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - related := o.f.NewCommsSMSLogWithContext(ctx, mods...) - m.AddDestinationSMSLogs(number, related).Apply(ctx, o) + related := o.f.NewCommsTextLogWithContext(ctx, mods...) + m.AddDestinationTextLogs(number, related).Apply(ctx, o) }) } -func (m commsPhoneMods) AddExistingDestinationSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod { +func (m commsPhoneMods) AddExistingDestinationTextLogs(existingModels ...*models.CommsTextLog) 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), + o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{ + o: o.f.FromExistingCommsTextLog(em), }) } }) } -func (m commsPhoneMods) WithoutDestinationSMSLogs() CommsPhoneMod { +func (m commsPhoneMods) WithoutDestinationTextLogs() CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.DestinationSMSLogs = nil + o.r.DestinationTextLogs = nil }) } -func (m commsPhoneMods) WithSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod { +func (m commsPhoneMods) WithSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.SourceSMSLogs = []*commsPhoneRSourceSMSLogsR{{ + o.r.SourceTextLogs = []*commsPhoneRSourceTextLogsR{{ number: number, o: related, }} }) } -func (m commsPhoneMods) WithNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod { +func (m commsPhoneMods) WithNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - related := o.f.NewCommsSMSLogWithContext(ctx, mods...) - m.WithSourceSMSLogs(number, related).Apply(ctx, o) + related := o.f.NewCommsTextLogWithContext(ctx, mods...) + m.WithSourceTextLogs(number, related).Apply(ctx, o) }) } -func (m commsPhoneMods) AddSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod { +func (m commsPhoneMods) AddSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.SourceSMSLogs = append(o.r.SourceSMSLogs, &commsPhoneRSourceSMSLogsR{ + o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{ number: number, o: related, }) }) } -func (m commsPhoneMods) AddNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod { +func (m commsPhoneMods) AddNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - related := o.f.NewCommsSMSLogWithContext(ctx, mods...) - m.AddSourceSMSLogs(number, related).Apply(ctx, o) + related := o.f.NewCommsTextLogWithContext(ctx, mods...) + m.AddSourceTextLogs(number, related).Apply(ctx, o) }) } -func (m commsPhoneMods) AddExistingSourceSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod { +func (m commsPhoneMods) AddExistingSourceTextLogs(existingModels ...*models.CommsTextLog) 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), + o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{ + o: o.f.FromExistingCommsTextLog(em), }) } }) } -func (m commsPhoneMods) WithoutSourceSMSLogs() CommsPhoneMod { +func (m commsPhoneMods) WithoutSourceTextLogs() CommsPhoneMod { return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) { - o.r.SourceSMSLogs = nil + o.r.SourceTextLogs = nil }) } diff --git a/db/factory/comms.sms_log.bob.go b/db/factory/comms.sms_log.bob.go deleted file mode 100644 index 516fe9ff..00000000 --- a/db/factory/comms.sms_log.bob.go +++ /dev/null @@ -1,523 +0,0 @@ -// 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 - }) -} diff --git a/db/factory/comms.text_log.bob.go b/db/factory/comms.text_log.bob.go new file mode 100644 index 00000000..91d5a2f3 --- /dev/null +++ b/db/factory/comms.text_log.bob.go @@ -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 CommsTextLogMod interface { + Apply(context.Context, *CommsTextLogTemplate) +} + +type CommsTextLogModFunc func(context.Context, *CommsTextLogTemplate) + +func (f CommsTextLogModFunc) Apply(ctx context.Context, n *CommsTextLogTemplate) { + f(ctx, n) +} + +type CommsTextLogModSlice []CommsTextLogMod + +func (mods CommsTextLogModSlice) Apply(ctx context.Context, n *CommsTextLogTemplate) { + for _, f := range mods { + f.Apply(ctx, n) + } +} + +// CommsTextLogTemplate is an object representing the database table. +// all columns are optional and should be set by mods +type CommsTextLogTemplate struct { + Created func() time.Time + Destination func() string + Source func() string + Type func() enums.CommsMessagetypetext + + r commsTextLogR + f *Factory + + alreadyPersisted bool +} + +type commsTextLogR struct { + DestinationPhone *commsTextLogRDestinationPhoneR + SourcePhone *commsTextLogRSourcePhoneR +} + +type commsTextLogRDestinationPhoneR struct { + o *CommsPhoneTemplate +} +type commsTextLogRSourcePhoneR struct { + o *CommsPhoneTemplate +} + +// Apply mods to the CommsTextLogTemplate +func (o *CommsTextLogTemplate) Apply(ctx context.Context, mods ...CommsTextLogMod) { + for _, mod := range mods { + mod.Apply(ctx, o) + } +} + +// setModelRels creates and sets the relationships on *models.CommsTextLog +// according to the relationships in the template. Nothing is inserted into the db +func (t CommsTextLogTemplate) setModelRels(o *models.CommsTextLog) { + if t.r.DestinationPhone != nil { + rel := t.r.DestinationPhone.o.Build() + rel.R.DestinationTextLogs = append(rel.R.DestinationTextLogs, o) + o.Destination = rel.E164 // h2 + o.R.DestinationPhone = rel + } + + if t.r.SourcePhone != nil { + rel := t.r.SourcePhone.o.Build() + rel.R.SourceTextLogs = append(rel.R.SourceTextLogs, o) + o.Source = rel.E164 // h2 + o.R.SourcePhone = rel + } +} + +// BuildSetter returns an *models.CommsTextLogSetter +// this does nothing with the relationship templates +func (o CommsTextLogTemplate) BuildSetter() *models.CommsTextLogSetter { + m := &models.CommsTextLogSetter{} + + 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.CommsTextLogSetter +// this does nothing with the relationship templates +func (o CommsTextLogTemplate) BuildManySetter(number int) []*models.CommsTextLogSetter { + m := make([]*models.CommsTextLogSetter, number) + + for i := range m { + m[i] = o.BuildSetter() + } + + return m +} + +// Build returns an *models.CommsTextLog +// Related objects are also created and placed in the .R field +// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.Create +func (o CommsTextLogTemplate) Build() *models.CommsTextLog { + m := &models.CommsTextLog{} + + 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.CommsTextLogSlice +// Related objects are also created and placed in the .R field +// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.CreateMany +func (o CommsTextLogTemplate) BuildMany(number int) models.CommsTextLogSlice { + m := make(models.CommsTextLogSlice, number) + + for i := range m { + m[i] = o.Build() + } + + return m +} + +func ensureCreatableCommsTextLog(m *models.CommsTextLogSetter) { + 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_CommsMessagetypetext(nil) + m.Type = omit.From(val) + } +} + +// insertOptRels creates and inserts any optional the relationships on *models.CommsTextLog +// according to the relationships in the template. +// any required relationship should have already exist on the model +func (o *CommsTextLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsTextLog) error { + var err error + + return err +} + +// Create builds a commsTextLog and inserts it into the database +// Relations objects are also inserted and placed in the .R field +func (o *CommsTextLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsTextLog, error) { + var err error + opt := o.BuildSetter() + ensureCreatableCommsTextLog(opt) + + if o.r.DestinationPhone == nil { + CommsTextLogMods.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 { + CommsTextLogMods.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.CommsTextLogs.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 commsTextLog and inserts it into the database +// Relations objects are also inserted and placed in the .R field +// panics if an error occurs +func (o *CommsTextLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsTextLog { + m, err := o.Create(ctx, exec) + if err != nil { + panic(err) + } + return m +} + +// CreateOrFail builds a commsTextLog 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 *CommsTextLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsTextLog { + tb.Helper() + m, err := o.Create(ctx, exec) + if err != nil { + tb.Fatal(err) + return nil + } + return m +} + +// CreateMany builds multiple commsTextLogs and inserts them into the database +// Relations objects are also inserted and placed in the .R field +func (o CommsTextLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsTextLogSlice, error) { + var err error + m := make(models.CommsTextLogSlice, number) + + for i := range m { + m[i], err = o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + return m, nil +} + +// MustCreateMany builds multiple commsTextLogs and inserts them into the database +// Relations objects are also inserted and placed in the .R field +// panics if an error occurs +func (o CommsTextLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsTextLogSlice { + m, err := o.CreateMany(ctx, exec, number) + if err != nil { + panic(err) + } + return m +} + +// CreateManyOrFail builds multiple commsTextLogs 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 CommsTextLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsTextLogSlice { + tb.Helper() + m, err := o.CreateMany(ctx, exec, number) + if err != nil { + tb.Fatal(err) + return nil + } + return m +} + +// CommsTextLog has methods that act as mods for the CommsTextLogTemplate +var CommsTextLogMods commsTextLogMods + +type commsTextLogMods struct{} + +func (m commsTextLogMods) RandomizeAllColumns(f *faker.Faker) CommsTextLogMod { + return CommsTextLogModSlice{ + CommsTextLogMods.RandomCreated(f), + CommsTextLogMods.RandomDestination(f), + CommsTextLogMods.RandomSource(f), + CommsTextLogMods.RandomType(f), + } +} + +// Set the model columns to this value +func (m commsTextLogMods) Created(val time.Time) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Created = func() time.Time { return val } + }) +} + +// Set the Column from the function +func (m commsTextLogMods) CreatedFunc(f func() time.Time) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Created = f + }) +} + +// Clear any values for the column +func (m commsTextLogMods) UnsetCreated() CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + 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 commsTextLogMods) RandomCreated(f *faker.Faker) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Created = func() time.Time { + return random_time_Time(f) + } + }) +} + +// Set the model columns to this value +func (m commsTextLogMods) Destination(val string) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Destination = func() string { return val } + }) +} + +// Set the Column from the function +func (m commsTextLogMods) DestinationFunc(f func() string) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Destination = f + }) +} + +// Clear any values for the column +func (m commsTextLogMods) UnsetDestination() CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + 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 commsTextLogMods) RandomDestination(f *faker.Faker) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Destination = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m commsTextLogMods) Source(val string) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Source = func() string { return val } + }) +} + +// Set the Column from the function +func (m commsTextLogMods) SourceFunc(f func() string) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Source = f + }) +} + +// Clear any values for the column +func (m commsTextLogMods) UnsetSource() CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + 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 commsTextLogMods) RandomSource(f *faker.Faker) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Source = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m commsTextLogMods) Type(val enums.CommsMessagetypetext) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Type = func() enums.CommsMessagetypetext { return val } + }) +} + +// Set the Column from the function +func (m commsTextLogMods) TypeFunc(f func() enums.CommsMessagetypetext) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Type = f + }) +} + +// Clear any values for the column +func (m commsTextLogMods) UnsetType() CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + 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 commsTextLogMods) RandomType(f *faker.Faker) CommsTextLogMod { + return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) { + o.Type = func() enums.CommsMessagetypetext { + return random_enums_CommsMessagetypetext(f) + } + }) +} + +func (m commsTextLogMods) WithParentsCascading() CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + if isDone, _ := commsTextLogWithParentsCascadingCtx.Value(ctx); isDone { + return + } + ctx = commsTextLogWithParentsCascadingCtx.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 commsTextLogMods) WithDestinationPhone(rel *CommsPhoneTemplate) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{ + o: rel, + } + }) +} + +func (m commsTextLogMods) WithNewDestinationPhone(mods ...CommsPhoneMod) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + related := o.f.NewCommsPhoneWithContext(ctx, mods...) + + m.WithDestinationPhone(related).Apply(ctx, o) + }) +} + +func (m commsTextLogMods) WithExistingDestinationPhone(em *models.CommsPhone) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{ + o: o.f.FromExistingCommsPhone(em), + } + }) +} + +func (m commsTextLogMods) WithoutDestinationPhone() CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.DestinationPhone = nil + }) +} + +func (m commsTextLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.SourcePhone = &commsTextLogRSourcePhoneR{ + o: rel, + } + }) +} + +func (m commsTextLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + related := o.f.NewCommsPhoneWithContext(ctx, mods...) + + m.WithSourcePhone(related).Apply(ctx, o) + }) +} + +func (m commsTextLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.SourcePhone = &commsTextLogRSourcePhoneR{ + o: o.f.FromExistingCommsPhone(em), + } + }) +} + +func (m commsTextLogMods) WithoutSourcePhone() CommsTextLogMod { + return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) { + o.r.SourcePhone = nil + }) +} diff --git a/db/migrations/00036_comms.sql b/db/migrations/00036_comms.sql index 1ab2697a..4c4b3740 100644 --- a/db/migrations/00036_comms.sql +++ b/db/migrations/00036_comms.sql @@ -1,11 +1,13 @@ -- +goose Up CREATE SCHEMA comms; -CREATE TYPE comms.SMSMessageType AS ENUM ( +CREATE TYPE comms.MessageTypeText AS ENUM ( + 'initial-contact', 'report-subscription-confirmation', 'report-status-scheduled', 'report-status-complete' ); -CREATE TYPE comms.EmailMessageType AS ENUM ( +CREATE TYPE comms.MessageTypeEmail AS ENUM ( + 'initial-contact', 'report-subscription-confirmation', 'report-status-scheduled', 'report-status-complete' @@ -15,11 +17,11 @@ CREATE TABLE comms.phone ( is_subscribed BOOLEAN NOT NULL, PRIMARY KEY (e164) ); -CREATE TABLE comms.sms_log ( +CREATE TABLE comms.text_log ( created TIMESTAMP WITHOUT TIME ZONE NOT NULL, destination TEXT NOT NULL REFERENCES comms.phone(e164), source TEXT NOT NULL REFERENCES comms.phone(e164), - type comms.SMSMessageType NOT NULL, + type comms.MessageTypeText NOT NULL, PRIMARY KEY (destination, source, type) ); CREATE TABLE comms.email ( @@ -32,6 +34,14 @@ CREATE TABLE comms.email_log ( created TIMESTAMP WITHOUT TIME ZONE NOT NULL, destination TEXT NOT NULL REFERENCES comms.email(address), source TEXT NOT NULL REFERENCES comms.phone(e164), - type comms.EmailMessageType NOT NULL, + type comms.MessageTypeEmail NOT NULL, PRIMARY KEY(destination, source, type) ); +-- +goose Down +DROP TABLE comms.email_log; +DROP TABLE comms.email; +DROP TABLE comms.text_log; +DROP TABLE comms.phone; +DROP TYPE comms.MessageTypeEmail; +DROP TYPE comms.MessageTypeText; +DROP SCHEMA comms; diff --git a/db/models/bob_joins.bob.go b/db/models/bob_joins.bob.go index 8df782cc..e3a3c0af 100644 --- a/db/models/bob_joins.bob.go +++ b/db/models/bob_joins.bob.go @@ -37,7 +37,7 @@ type joins[Q dialect.Joinable] struct { CommsEmails joinSet[commsEmailJoins[Q]] CommsEmailLogs joinSet[commsEmailLogJoins[Q]] CommsPhones joinSet[commsPhoneJoins[Q]] - CommsSMSLogs joinSet[commsSMSLogJoins[Q]] + CommsTextLogs joinSet[commsTextLogJoins[Q]] FieldseekerContainerrelates joinSet[fieldseekerContainerrelateJoins[Q]] FieldseekerFieldscoutinglogs joinSet[fieldseekerFieldscoutinglogJoins[Q]] FieldseekerHabitatrelates joinSet[fieldseekerHabitatrelateJoins[Q]] @@ -101,7 +101,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] { CommsEmails: buildJoinSet[commsEmailJoins[Q]](CommsEmails.Columns, buildCommsEmailJoins), CommsEmailLogs: buildJoinSet[commsEmailLogJoins[Q]](CommsEmailLogs.Columns, buildCommsEmailLogJoins), CommsPhones: buildJoinSet[commsPhoneJoins[Q]](CommsPhones.Columns, buildCommsPhoneJoins), - CommsSMSLogs: buildJoinSet[commsSMSLogJoins[Q]](CommsSMSLogs.Columns, buildCommsSMSLogJoins), + CommsTextLogs: buildJoinSet[commsTextLogJoins[Q]](CommsTextLogs.Columns, buildCommsTextLogJoins), FieldseekerContainerrelates: buildJoinSet[fieldseekerContainerrelateJoins[Q]](FieldseekerContainerrelates.Columns, buildFieldseekerContainerrelateJoins), FieldseekerFieldscoutinglogs: buildJoinSet[fieldseekerFieldscoutinglogJoins[Q]](FieldseekerFieldscoutinglogs.Columns, buildFieldseekerFieldscoutinglogJoins), FieldseekerHabitatrelates: buildJoinSet[fieldseekerHabitatrelateJoins[Q]](FieldseekerHabitatrelates.Columns, buildFieldseekerHabitatrelateJoins), diff --git a/db/models/bob_loaders.bob.go b/db/models/bob_loaders.bob.go index 7d058f99..405ee6d6 100644 --- a/db/models/bob_loaders.bob.go +++ b/db/models/bob_loaders.bob.go @@ -22,7 +22,7 @@ type preloaders struct { CommsEmail commsEmailPreloader CommsEmailLog commsEmailLogPreloader CommsPhone commsPhonePreloader - CommsSMSLog commsSMSLogPreloader + CommsTextLog commsTextLogPreloader FieldseekerContainerrelate fieldseekerContainerrelatePreloader FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogPreloader FieldseekerHabitatrelate fieldseekerHabitatrelatePreloader @@ -78,7 +78,7 @@ func getPreloaders() preloaders { CommsEmail: buildCommsEmailPreloader(), CommsEmailLog: buildCommsEmailLogPreloader(), CommsPhone: buildCommsPhonePreloader(), - CommsSMSLog: buildCommsSMSLogPreloader(), + CommsTextLog: buildCommsTextLogPreloader(), FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(), FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogPreloader(), FieldseekerHabitatrelate: buildFieldseekerHabitatrelatePreloader(), @@ -140,7 +140,7 @@ type thenLoaders[Q orm.Loadable] struct { CommsEmail commsEmailThenLoader[Q] CommsEmailLog commsEmailLogThenLoader[Q] CommsPhone commsPhoneThenLoader[Q] - CommsSMSLog commsSMSLogThenLoader[Q] + CommsTextLog commsTextLogThenLoader[Q] FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q] FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogThenLoader[Q] FieldseekerHabitatrelate fieldseekerHabitatrelateThenLoader[Q] @@ -196,7 +196,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { CommsEmail: buildCommsEmailThenLoader[Q](), CommsEmailLog: buildCommsEmailLogThenLoader[Q](), CommsPhone: buildCommsPhoneThenLoader[Q](), - CommsSMSLog: buildCommsSMSLogThenLoader[Q](), + CommsTextLog: buildCommsTextLogThenLoader[Q](), FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](), FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogThenLoader[Q](), FieldseekerHabitatrelate: buildFieldseekerHabitatrelateThenLoader[Q](), diff --git a/db/models/bob_where.bob.go b/db/models/bob_where.bob.go index 69ddc8f4..9ce4788e 100644 --- a/db/models/bob_where.bob.go +++ b/db/models/bob_where.bob.go @@ -22,7 +22,7 @@ func Where[Q psql.Filterable]() struct { CommsEmails commsEmailWhere[Q] CommsEmailLogs commsEmailLogWhere[Q] CommsPhones commsPhoneWhere[Q] - CommsSMSLogs commsSMSLogWhere[Q] + CommsTextLogs commsTextLogWhere[Q] FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q] FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q] FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q] @@ -85,7 +85,7 @@ func Where[Q psql.Filterable]() struct { CommsEmails commsEmailWhere[Q] CommsEmailLogs commsEmailLogWhere[Q] CommsPhones commsPhoneWhere[Q] - CommsSMSLogs commsSMSLogWhere[Q] + CommsTextLogs commsTextLogWhere[Q] FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q] FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q] FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q] @@ -147,7 +147,7 @@ func Where[Q psql.Filterable]() struct { CommsEmails: buildCommsEmailWhere[Q](CommsEmails.Columns), CommsEmailLogs: buildCommsEmailLogWhere[Q](CommsEmailLogs.Columns), CommsPhones: buildCommsPhoneWhere[Q](CommsPhones.Columns), - CommsSMSLogs: buildCommsSMSLogWhere[Q](CommsSMSLogs.Columns), + CommsTextLogs: buildCommsTextLogWhere[Q](CommsTextLogs.Columns), FieldseekerContainerrelates: buildFieldseekerContainerrelateWhere[Q](FieldseekerContainerrelates.Columns), FieldseekerFieldscoutinglogs: buildFieldseekerFieldscoutinglogWhere[Q](FieldseekerFieldscoutinglogs.Columns), FieldseekerHabitatrelates: buildFieldseekerHabitatrelateWhere[Q](FieldseekerHabitatrelates.Columns), diff --git a/db/models/comms.email_log.bob.go b/db/models/comms.email_log.bob.go index 74cec9a0..fb8edb87 100644 --- a/db/models/comms.email_log.bob.go +++ b/db/models/comms.email_log.bob.go @@ -28,7 +28,7 @@ type CommsEmailLog struct { Created time.Time `db:"created" ` Destination string `db:"destination,pk" ` Source string `db:"source,pk" ` - Type enums.CommsEmailmessagetype `db:"type,pk" ` + Type enums.CommsMessagetypeemail `db:"type,pk" ` R commsEmailLogR `db:"-" ` } @@ -86,7 +86,7 @@ type CommsEmailLogSetter struct { Created omit.Val[time.Time] `db:"created" ` Destination omit.Val[string] `db:"destination,pk" ` Source omit.Val[string] `db:"source,pk" ` - Type omit.Val[enums.CommsEmailmessagetype] `db:"type,pk" ` + Type omit.Val[enums.CommsMessagetypeemail] `db:"type,pk" ` } func (s CommsEmailLogSetter) SetColumns() []string { @@ -196,7 +196,7 @@ func (s CommsEmailLogSetter) Expressions(prefix ...string) []bob.Expression { // FindCommsEmailLog retrieves a single record by primary key // If cols is empty Find will return all columns. -func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsEmailmessagetype, cols ...string) (*CommsEmailLog, error) { +func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypeemail, cols ...string) (*CommsEmailLog, error) { if len(cols) == 0 { return CommsEmailLogs.Query( sm.Where(CommsEmailLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), @@ -214,7 +214,7 @@ func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK str } // CommsEmailLogExists checks the presence of a single record by primary key -func CommsEmailLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsEmailmessagetype) (bool, error) { +func CommsEmailLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypeemail) (bool, error) { return CommsEmailLogs.Query( sm.Where(CommsEmailLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), sm.Where(CommsEmailLogs.Columns.Source.EQ(psql.Arg(SourcePK))), @@ -583,7 +583,7 @@ type commsEmailLogWhere[Q psql.Filterable] struct { Created psql.WhereMod[Q, time.Time] Destination psql.WhereMod[Q, string] Source psql.WhereMod[Q, string] - Type psql.WhereMod[Q, enums.CommsEmailmessagetype] + Type psql.WhereMod[Q, enums.CommsMessagetypeemail] } func (commsEmailLogWhere[Q]) AliasedAs(alias string) commsEmailLogWhere[Q] { @@ -595,7 +595,7 @@ func buildCommsEmailLogWhere[Q psql.Filterable](cols commsEmailLogColumns) comms Created: psql.Where[Q, time.Time](cols.Created), Destination: psql.Where[Q, string](cols.Destination), Source: psql.Where[Q, string](cols.Source), - Type: psql.Where[Q, enums.CommsEmailmessagetype](cols.Type), + Type: psql.Where[Q, enums.CommsMessagetypeemail](cols.Type), } } diff --git a/db/models/comms.phone.bob.go b/db/models/comms.phone.bob.go index ece6bcf3..185a680c 100644 --- a/db/models/comms.phone.bob.go +++ b/db/models/comms.phone.bob.go @@ -43,9 +43,9 @@ type CommsPhonesQuery = *psql.ViewQuery[*CommsPhone, CommsPhoneSlice] // commsPhoneR is where relationships are stored. type commsPhoneR struct { - SourceEmailLogs CommsEmailLogSlice // comms.email_log.email_log_source_fkey - DestinationSMSLogs CommsSMSLogSlice // comms.sms_log.sms_log_destination_fkey - SourceSMSLogs CommsSMSLogSlice // comms.sms_log.sms_log_source_fkey + SourceEmailLogs CommsEmailLogSlice // comms.email_log.email_log_source_fkey + DestinationTextLogs CommsTextLogSlice // comms.text_log.text_log_destination_fkey + SourceTextLogs CommsTextLogSlice // comms.text_log.text_log_source_fkey } func buildCommsPhoneColumns(alias string) commsPhoneColumns { @@ -396,14 +396,14 @@ func (os CommsPhoneSlice) SourceEmailLogs(mods ...bob.Mod[*dialect.SelectQuery]) )...) } -// DestinationSMSLogs starts a query for related objects on comms.sms_log -func (o *CommsPhone) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery { - return CommsSMSLogs.Query(append(mods, - sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(o.E164))), +// DestinationTextLogs starts a query for related objects on comms.text_log +func (o *CommsPhone) DestinationTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery { + return CommsTextLogs.Query(append(mods, + sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(o.E164))), )...) } -func (os CommsPhoneSlice) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery { +func (os CommsPhoneSlice) DestinationTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery { pkE164 := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -415,19 +415,19 @@ func (os CommsPhoneSlice) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuer psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")), )) - return CommsSMSLogs.Query(append(mods, - sm.Where(psql.Group(CommsSMSLogs.Columns.Destination).OP("IN", PKArgExpr)), + return CommsTextLogs.Query(append(mods, + sm.Where(psql.Group(CommsTextLogs.Columns.Destination).OP("IN", PKArgExpr)), )...) } -// SourceSMSLogs starts a query for related objects on comms.sms_log -func (o *CommsPhone) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery { - return CommsSMSLogs.Query(append(mods, - sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(o.E164))), +// SourceTextLogs starts a query for related objects on comms.text_log +func (o *CommsPhone) SourceTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery { + return CommsTextLogs.Query(append(mods, + sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(o.E164))), )...) } -func (os CommsPhoneSlice) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery { +func (os CommsPhoneSlice) SourceTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery { pkE164 := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -439,8 +439,8 @@ func (os CommsPhoneSlice) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) C psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")), )) - return CommsSMSLogs.Query(append(mods, - sm.Where(psql.Group(CommsSMSLogs.Columns.Source).OP("IN", PKArgExpr)), + return CommsTextLogs.Query(append(mods, + sm.Where(psql.Group(CommsTextLogs.Columns.Source).OP("IN", PKArgExpr)), )...) } @@ -512,66 +512,66 @@ func (commsPhone0 *CommsPhone) AttachSourceEmailLogs(ctx context.Context, exec b return nil } -func insertCommsPhoneDestinationSMSLogs0(ctx context.Context, exec bob.Executor, commsSMSLogs1 []*CommsSMSLogSetter, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) { - for i := range commsSMSLogs1 { - commsSMSLogs1[i].Destination = omit.From(commsPhone0.E164) +func insertCommsPhoneDestinationTextLogs0(ctx context.Context, exec bob.Executor, commsTextLogs1 []*CommsTextLogSetter, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) { + for i := range commsTextLogs1 { + commsTextLogs1[i].Destination = omit.From(commsPhone0.E164) } - ret, err := CommsSMSLogs.Insert(bob.ToMods(commsSMSLogs1...)).All(ctx, exec) + ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertCommsPhoneDestinationSMSLogs0: %w", err) + return ret, fmt.Errorf("insertCommsPhoneDestinationTextLogs0: %w", err) } return ret, nil } -func attachCommsPhoneDestinationSMSLogs0(ctx context.Context, exec bob.Executor, count int, commsSMSLogs1 CommsSMSLogSlice, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) { - setter := &CommsSMSLogSetter{ +func attachCommsPhoneDestinationTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) { + setter := &CommsTextLogSetter{ Destination: omit.From(commsPhone0.E164), } - err := commsSMSLogs1.UpdateAll(ctx, exec, *setter) + err := commsTextLogs1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachCommsPhoneDestinationSMSLogs0: %w", err) + return nil, fmt.Errorf("attachCommsPhoneDestinationTextLogs0: %w", err) } - return commsSMSLogs1, nil + return commsTextLogs1, nil } -func (commsPhone0 *CommsPhone) InsertDestinationSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLogSetter) error { +func (commsPhone0 *CommsPhone) InsertDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error { if len(related) == 0 { return nil } var err error - commsSMSLogs1, err := insertCommsPhoneDestinationSMSLogs0(ctx, exec, related, commsPhone0) + commsTextLogs1, err := insertCommsPhoneDestinationTextLogs0(ctx, exec, related, commsPhone0) if err != nil { return err } - commsPhone0.R.DestinationSMSLogs = append(commsPhone0.R.DestinationSMSLogs, commsSMSLogs1...) + commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...) - for _, rel := range commsSMSLogs1 { + for _, rel := range commsTextLogs1 { rel.R.DestinationPhone = commsPhone0 } return nil } -func (commsPhone0 *CommsPhone) AttachDestinationSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLog) error { +func (commsPhone0 *CommsPhone) AttachDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error { if len(related) == 0 { return nil } var err error - commsSMSLogs1 := CommsSMSLogSlice(related) + commsTextLogs1 := CommsTextLogSlice(related) - _, err = attachCommsPhoneDestinationSMSLogs0(ctx, exec, len(related), commsSMSLogs1, commsPhone0) + _, err = attachCommsPhoneDestinationTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0) if err != nil { return err } - commsPhone0.R.DestinationSMSLogs = append(commsPhone0.R.DestinationSMSLogs, commsSMSLogs1...) + commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...) for _, rel := range related { rel.R.DestinationPhone = commsPhone0 @@ -580,66 +580,66 @@ func (commsPhone0 *CommsPhone) AttachDestinationSMSLogs(ctx context.Context, exe return nil } -func insertCommsPhoneSourceSMSLogs0(ctx context.Context, exec bob.Executor, commsSMSLogs1 []*CommsSMSLogSetter, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) { - for i := range commsSMSLogs1 { - commsSMSLogs1[i].Source = omit.From(commsPhone0.E164) +func insertCommsPhoneSourceTextLogs0(ctx context.Context, exec bob.Executor, commsTextLogs1 []*CommsTextLogSetter, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) { + for i := range commsTextLogs1 { + commsTextLogs1[i].Source = omit.From(commsPhone0.E164) } - ret, err := CommsSMSLogs.Insert(bob.ToMods(commsSMSLogs1...)).All(ctx, exec) + ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertCommsPhoneSourceSMSLogs0: %w", err) + return ret, fmt.Errorf("insertCommsPhoneSourceTextLogs0: %w", err) } return ret, nil } -func attachCommsPhoneSourceSMSLogs0(ctx context.Context, exec bob.Executor, count int, commsSMSLogs1 CommsSMSLogSlice, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) { - setter := &CommsSMSLogSetter{ +func attachCommsPhoneSourceTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) { + setter := &CommsTextLogSetter{ Source: omit.From(commsPhone0.E164), } - err := commsSMSLogs1.UpdateAll(ctx, exec, *setter) + err := commsTextLogs1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachCommsPhoneSourceSMSLogs0: %w", err) + return nil, fmt.Errorf("attachCommsPhoneSourceTextLogs0: %w", err) } - return commsSMSLogs1, nil + return commsTextLogs1, nil } -func (commsPhone0 *CommsPhone) InsertSourceSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLogSetter) error { +func (commsPhone0 *CommsPhone) InsertSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error { if len(related) == 0 { return nil } var err error - commsSMSLogs1, err := insertCommsPhoneSourceSMSLogs0(ctx, exec, related, commsPhone0) + commsTextLogs1, err := insertCommsPhoneSourceTextLogs0(ctx, exec, related, commsPhone0) if err != nil { return err } - commsPhone0.R.SourceSMSLogs = append(commsPhone0.R.SourceSMSLogs, commsSMSLogs1...) + commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...) - for _, rel := range commsSMSLogs1 { + for _, rel := range commsTextLogs1 { rel.R.SourcePhone = commsPhone0 } return nil } -func (commsPhone0 *CommsPhone) AttachSourceSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLog) error { +func (commsPhone0 *CommsPhone) AttachSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error { if len(related) == 0 { return nil } var err error - commsSMSLogs1 := CommsSMSLogSlice(related) + commsTextLogs1 := CommsTextLogSlice(related) - _, err = attachCommsPhoneSourceSMSLogs0(ctx, exec, len(related), commsSMSLogs1, commsPhone0) + _, err = attachCommsPhoneSourceTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0) if err != nil { return err } - commsPhone0.R.SourceSMSLogs = append(commsPhone0.R.SourceSMSLogs, commsSMSLogs1...) + commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...) for _, rel := range related { rel.R.SourcePhone = commsPhone0 @@ -684,13 +684,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error { } } return nil - case "DestinationSMSLogs": - rels, ok := retrieved.(CommsSMSLogSlice) + case "DestinationTextLogs": + rels, ok := retrieved.(CommsTextLogSlice) if !ok { return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name) } - o.R.DestinationSMSLogs = rels + o.R.DestinationTextLogs = rels for _, rel := range rels { if rel != nil { @@ -698,13 +698,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error { } } return nil - case "SourceSMSLogs": - rels, ok := retrieved.(CommsSMSLogSlice) + case "SourceTextLogs": + rels, ok := retrieved.(CommsTextLogSlice) if !ok { return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name) } - o.R.SourceSMSLogs = rels + o.R.SourceTextLogs = rels for _, rel := range rels { if rel != nil { @@ -724,20 +724,20 @@ func buildCommsPhonePreloader() commsPhonePreloader { } type commsPhoneThenLoader[Q orm.Loadable] struct { - SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] { type SourceEmailLogsLoadInterface interface { LoadSourceEmailLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type DestinationSMSLogsLoadInterface interface { - LoadDestinationSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type DestinationTextLogsLoadInterface interface { + LoadDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type SourceSMSLogsLoadInterface interface { - LoadSourceSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type SourceTextLogsLoadInterface interface { + LoadSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } return commsPhoneThenLoader[Q]{ @@ -747,16 +747,16 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] { return retrieved.LoadSourceEmailLogs(ctx, exec, mods...) }, ), - DestinationSMSLogs: thenLoadBuilder[Q]( - "DestinationSMSLogs", - func(ctx context.Context, exec bob.Executor, retrieved DestinationSMSLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadDestinationSMSLogs(ctx, exec, mods...) + DestinationTextLogs: thenLoadBuilder[Q]( + "DestinationTextLogs", + func(ctx context.Context, exec bob.Executor, retrieved DestinationTextLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadDestinationTextLogs(ctx, exec, mods...) }, ), - SourceSMSLogs: thenLoadBuilder[Q]( - "SourceSMSLogs", - func(ctx context.Context, exec bob.Executor, retrieved SourceSMSLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadSourceSMSLogs(ctx, exec, mods...) + SourceTextLogs: thenLoadBuilder[Q]( + "SourceTextLogs", + func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSourceTextLogs(ctx, exec, mods...) }, ), } @@ -823,16 +823,16 @@ func (os CommsPhoneSlice) LoadSourceEmailLogs(ctx context.Context, exec bob.Exec return nil } -// LoadDestinationSMSLogs loads the commsPhone's DestinationSMSLogs into the .R struct -func (o *CommsPhone) LoadDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadDestinationTextLogs loads the commsPhone's DestinationTextLogs into the .R struct +func (o *CommsPhone) LoadDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.DestinationSMSLogs = nil + o.R.DestinationTextLogs = nil - related, err := o.DestinationSMSLogs(mods...).All(ctx, exec) + related, err := o.DestinationTextLogs(mods...).All(ctx, exec) if err != nil { return err } @@ -841,17 +841,17 @@ func (o *CommsPhone) LoadDestinationSMSLogs(ctx context.Context, exec bob.Execut rel.R.DestinationPhone = o } - o.R.DestinationSMSLogs = related + o.R.DestinationTextLogs = related return nil } -// LoadDestinationSMSLogs loads the commsPhone's DestinationSMSLogs into the .R struct -func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadDestinationTextLogs loads the commsPhone's DestinationTextLogs into the .R struct +func (os CommsPhoneSlice) LoadDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - commsSMSLogs, err := os.DestinationSMSLogs(mods...).All(ctx, exec) + commsTextLogs, err := os.DestinationTextLogs(mods...).All(ctx, exec) if err != nil { return err } @@ -861,7 +861,7 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E continue } - o.R.DestinationSMSLogs = nil + o.R.DestinationTextLogs = nil } for _, o := range os { @@ -869,7 +869,7 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E continue } - for _, rel := range commsSMSLogs { + for _, rel := range commsTextLogs { if !(o.E164 == rel.Destination) { continue @@ -877,23 +877,23 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E rel.R.DestinationPhone = o - o.R.DestinationSMSLogs = append(o.R.DestinationSMSLogs, rel) + o.R.DestinationTextLogs = append(o.R.DestinationTextLogs, rel) } } return nil } -// LoadSourceSMSLogs loads the commsPhone's SourceSMSLogs into the .R struct -func (o *CommsPhone) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadSourceTextLogs loads the commsPhone's SourceTextLogs into the .R struct +func (o *CommsPhone) LoadSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.SourceSMSLogs = nil + o.R.SourceTextLogs = nil - related, err := o.SourceSMSLogs(mods...).All(ctx, exec) + related, err := o.SourceTextLogs(mods...).All(ctx, exec) if err != nil { return err } @@ -902,17 +902,17 @@ func (o *CommsPhone) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, m rel.R.SourcePhone = o } - o.R.SourceSMSLogs = related + o.R.SourceTextLogs = related return nil } -// LoadSourceSMSLogs loads the commsPhone's SourceSMSLogs into the .R struct -func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadSourceTextLogs loads the commsPhone's SourceTextLogs into the .R struct +func (os CommsPhoneSlice) LoadSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - commsSMSLogs, err := os.SourceSMSLogs(mods...).All(ctx, exec) + commsTextLogs, err := os.SourceTextLogs(mods...).All(ctx, exec) if err != nil { return err } @@ -922,7 +922,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut continue } - o.R.SourceSMSLogs = nil + o.R.SourceTextLogs = nil } for _, o := range os { @@ -930,7 +930,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut continue } - for _, rel := range commsSMSLogs { + for _, rel := range commsTextLogs { if !(o.E164 == rel.Source) { continue @@ -938,7 +938,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut rel.R.SourcePhone = o - o.R.SourceSMSLogs = append(o.R.SourceSMSLogs, rel) + o.R.SourceTextLogs = append(o.R.SourceTextLogs, rel) } } @@ -947,9 +947,9 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut // commsPhoneC is where relationship counts are stored. type commsPhoneC struct { - SourceEmailLogs *int64 - DestinationSMSLogs *int64 - SourceSMSLogs *int64 + SourceEmailLogs *int64 + DestinationTextLogs *int64 + SourceTextLogs *int64 } // PreloadCount sets a count in the C struct by name @@ -961,18 +961,18 @@ func (o *CommsPhone) PreloadCount(name string, count int64) error { switch name { case "SourceEmailLogs": o.C.SourceEmailLogs = &count - case "DestinationSMSLogs": - o.C.DestinationSMSLogs = &count - case "SourceSMSLogs": - o.C.SourceSMSLogs = &count + case "DestinationTextLogs": + o.C.DestinationTextLogs = &count + case "SourceTextLogs": + o.C.SourceTextLogs = &count } return nil } type commsPhoneCountPreloader struct { - SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader - DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader - SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader } func buildCommsPhoneCountPreloader() commsPhoneCountPreloader { @@ -994,8 +994,8 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, - DestinationSMSLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { - return countPreloader[*CommsPhone]("DestinationSMSLogs", func(parent string) bob.Expression { + DestinationTextLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { + return countPreloader[*CommsPhone]("DestinationTextLogs", func(parent string) bob.Expression { // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) if parent == "" { parent = CommsPhones.Alias() @@ -1004,15 +1004,15 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader { subqueryMods := []bob.Mod[*dialect.SelectQuery]{ sm.Columns(psql.Raw("count(*)")), - sm.From(CommsSMSLogs.Name()), - sm.Where(psql.Quote(CommsSMSLogs.Alias(), "destination").EQ(psql.Quote(parent, "e164"))), + sm.From(CommsTextLogs.Name()), + sm.Where(psql.Quote(CommsTextLogs.Alias(), "destination").EQ(psql.Quote(parent, "e164"))), } subqueryMods = append(subqueryMods, mods...) return psql.Group(psql.Select(subqueryMods...).Expression) }) }, - SourceSMSLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { - return countPreloader[*CommsPhone]("SourceSMSLogs", func(parent string) bob.Expression { + SourceTextLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { + return countPreloader[*CommsPhone]("SourceTextLogs", func(parent string) bob.Expression { // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) if parent == "" { parent = CommsPhones.Alias() @@ -1021,8 +1021,8 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader { subqueryMods := []bob.Mod[*dialect.SelectQuery]{ sm.Columns(psql.Raw("count(*)")), - sm.From(CommsSMSLogs.Name()), - sm.Where(psql.Quote(CommsSMSLogs.Alias(), "source").EQ(psql.Quote(parent, "e164"))), + sm.From(CommsTextLogs.Name()), + sm.Where(psql.Quote(CommsTextLogs.Alias(), "source").EQ(psql.Quote(parent, "e164"))), } subqueryMods = append(subqueryMods, mods...) return psql.Group(psql.Select(subqueryMods...).Expression) @@ -1032,20 +1032,20 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader { } type commsPhoneCountThenLoader[Q orm.Loadable] struct { - SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] { type SourceEmailLogsCountInterface interface { LoadCountSourceEmailLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type DestinationSMSLogsCountInterface interface { - LoadCountDestinationSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type DestinationTextLogsCountInterface interface { + LoadCountDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type SourceSMSLogsCountInterface interface { - LoadCountSourceSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type SourceTextLogsCountInterface interface { + LoadCountSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } return commsPhoneCountThenLoader[Q]{ @@ -1055,16 +1055,16 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[ return retrieved.LoadCountSourceEmailLogs(ctx, exec, mods...) }, ), - DestinationSMSLogs: countThenLoadBuilder[Q]( - "DestinationSMSLogs", - func(ctx context.Context, exec bob.Executor, retrieved DestinationSMSLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCountDestinationSMSLogs(ctx, exec, mods...) + DestinationTextLogs: countThenLoadBuilder[Q]( + "DestinationTextLogs", + func(ctx context.Context, exec bob.Executor, retrieved DestinationTextLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCountDestinationTextLogs(ctx, exec, mods...) }, ), - SourceSMSLogs: countThenLoadBuilder[Q]( - "SourceSMSLogs", - func(ctx context.Context, exec bob.Executor, retrieved SourceSMSLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCountSourceSMSLogs(ctx, exec, mods...) + SourceTextLogs: countThenLoadBuilder[Q]( + "SourceTextLogs", + func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCountSourceTextLogs(ctx, exec, mods...) }, ), } @@ -1100,29 +1100,29 @@ func (os CommsPhoneSlice) LoadCountSourceEmailLogs(ctx context.Context, exec bob return nil } -// LoadCountDestinationSMSLogs loads the count of DestinationSMSLogs into the C struct -func (o *CommsPhone) LoadCountDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadCountDestinationTextLogs loads the count of DestinationTextLogs into the C struct +func (o *CommsPhone) LoadCountDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } - count, err := o.DestinationSMSLogs(mods...).Count(ctx, exec) + count, err := o.DestinationTextLogs(mods...).Count(ctx, exec) if err != nil { return err } - o.C.DestinationSMSLogs = &count + o.C.DestinationTextLogs = &count return nil } -// LoadCountDestinationSMSLogs loads the count of DestinationSMSLogs for a slice -func (os CommsPhoneSlice) LoadCountDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadCountDestinationTextLogs loads the count of DestinationTextLogs for a slice +func (os CommsPhoneSlice) LoadCountDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } for _, o := range os { - if err := o.LoadCountDestinationSMSLogs(ctx, exec, mods...); err != nil { + if err := o.LoadCountDestinationTextLogs(ctx, exec, mods...); err != nil { return err } } @@ -1130,29 +1130,29 @@ func (os CommsPhoneSlice) LoadCountDestinationSMSLogs(ctx context.Context, exec return nil } -// LoadCountSourceSMSLogs loads the count of SourceSMSLogs into the C struct -func (o *CommsPhone) LoadCountSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadCountSourceTextLogs loads the count of SourceTextLogs into the C struct +func (o *CommsPhone) LoadCountSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } - count, err := o.SourceSMSLogs(mods...).Count(ctx, exec) + count, err := o.SourceTextLogs(mods...).Count(ctx, exec) if err != nil { return err } - o.C.SourceSMSLogs = &count + o.C.SourceTextLogs = &count return nil } -// LoadCountSourceSMSLogs loads the count of SourceSMSLogs for a slice -func (os CommsPhoneSlice) LoadCountSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadCountSourceTextLogs loads the count of SourceTextLogs for a slice +func (os CommsPhoneSlice) LoadCountSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } for _, o := range os { - if err := o.LoadCountSourceSMSLogs(ctx, exec, mods...); err != nil { + if err := o.LoadCountSourceTextLogs(ctx, exec, mods...); err != nil { return err } } @@ -1161,10 +1161,10 @@ func (os CommsPhoneSlice) LoadCountSourceSMSLogs(ctx context.Context, exec bob.E } type commsPhoneJoins[Q dialect.Joinable] struct { - typ string - SourceEmailLogs modAs[Q, commsEmailLogColumns] - DestinationSMSLogs modAs[Q, commsSMSLogColumns] - SourceSMSLogs modAs[Q, commsSMSLogColumns] + typ string + SourceEmailLogs modAs[Q, commsEmailLogColumns] + DestinationTextLogs modAs[Q, commsTextLogColumns] + SourceTextLogs modAs[Q, commsTextLogColumns] } func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] { @@ -1188,13 +1188,13 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string return mods }, }, - DestinationSMSLogs: modAs[Q, commsSMSLogColumns]{ - c: CommsSMSLogs.Columns, - f: func(to commsSMSLogColumns) bob.Mod[Q] { + DestinationTextLogs: modAs[Q, commsTextLogColumns]{ + c: CommsTextLogs.Columns, + f: func(to commsTextLogColumns) bob.Mod[Q] { mods := make(mods.QueryMods[Q], 0, 1) { - mods = append(mods, dialect.Join[Q](typ, CommsSMSLogs.Name().As(to.Alias())).On( + mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On( to.Destination.EQ(cols.E164), )) } @@ -1202,13 +1202,13 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string return mods }, }, - SourceSMSLogs: modAs[Q, commsSMSLogColumns]{ - c: CommsSMSLogs.Columns, - f: func(to commsSMSLogColumns) bob.Mod[Q] { + SourceTextLogs: modAs[Q, commsTextLogColumns]{ + c: CommsTextLogs.Columns, + f: func(to commsTextLogColumns) bob.Mod[Q] { mods := make(mods.QueryMods[Q], 0, 1) { - mods = append(mods, dialect.Join[Q](typ, CommsSMSLogs.Name().As(to.Alias())).On( + mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On( to.Source.EQ(cols.E164), )) } diff --git a/db/models/comms.sms_log.bob.go b/db/models/comms.text_log.bob.go similarity index 51% rename from db/models/comms.sms_log.bob.go rename to db/models/comms.text_log.bob.go index fd54020e..d717c547 100644 --- a/db/models/comms.sms_log.bob.go +++ b/db/models/comms.text_log.bob.go @@ -23,37 +23,37 @@ import ( "github.com/stephenafamo/bob/types/pgtypes" ) -// CommsSMSLog is an object representing the database table. -type CommsSMSLog struct { - Created time.Time `db:"created" ` - Destination string `db:"destination,pk" ` - Source string `db:"source,pk" ` - Type enums.CommsSmsmessagetype `db:"type,pk" ` +// CommsTextLog is an object representing the database table. +type CommsTextLog struct { + Created time.Time `db:"created" ` + Destination string `db:"destination,pk" ` + Source string `db:"source,pk" ` + Type enums.CommsMessagetypetext `db:"type,pk" ` - R commsSMSLogR `db:"-" ` + R commsTextLogR `db:"-" ` } -// CommsSMSLogSlice is an alias for a slice of pointers to CommsSMSLog. -// This should almost always be used instead of []*CommsSMSLog. -type CommsSMSLogSlice []*CommsSMSLog +// CommsTextLogSlice is an alias for a slice of pointers to CommsTextLog. +// This should almost always be used instead of []*CommsTextLog. +type CommsTextLogSlice []*CommsTextLog -// CommsSMSLogs contains methods to work with the sms_log table -var CommsSMSLogs = psql.NewTablex[*CommsSMSLog, CommsSMSLogSlice, *CommsSMSLogSetter]("comms", "sms_log", buildCommsSMSLogColumns("comms.sms_log")) +// CommsTextLogs contains methods to work with the text_log table +var CommsTextLogs = psql.NewTablex[*CommsTextLog, CommsTextLogSlice, *CommsTextLogSetter]("comms", "text_log", buildCommsTextLogColumns("comms.text_log")) -// CommsSMSLogsQuery is a query on the sms_log table -type CommsSMSLogsQuery = *psql.ViewQuery[*CommsSMSLog, CommsSMSLogSlice] +// CommsTextLogsQuery is a query on the text_log table +type CommsTextLogsQuery = *psql.ViewQuery[*CommsTextLog, CommsTextLogSlice] -// commsSMSLogR is where relationships are stored. -type commsSMSLogR struct { - DestinationPhone *CommsPhone // comms.sms_log.sms_log_destination_fkey - SourcePhone *CommsPhone // comms.sms_log.sms_log_source_fkey +// commsTextLogR is where relationships are stored. +type commsTextLogR struct { + DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey + SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey } -func buildCommsSMSLogColumns(alias string) commsSMSLogColumns { - return commsSMSLogColumns{ +func buildCommsTextLogColumns(alias string) commsTextLogColumns { + return commsTextLogColumns{ ColumnsExpr: expr.NewColumnsExpr( "created", "destination", "source", "type", - ).WithParent("comms.sms_log"), + ).WithParent("comms.text_log"), tableAlias: alias, Created: psql.Quote(alias, "created"), Destination: psql.Quote(alias, "destination"), @@ -62,7 +62,7 @@ func buildCommsSMSLogColumns(alias string) commsSMSLogColumns { } } -type commsSMSLogColumns struct { +type commsTextLogColumns struct { expr.ColumnsExpr tableAlias string Created psql.Expression @@ -71,25 +71,25 @@ type commsSMSLogColumns struct { Type psql.Expression } -func (c commsSMSLogColumns) Alias() string { +func (c commsTextLogColumns) Alias() string { return c.tableAlias } -func (commsSMSLogColumns) AliasedAs(alias string) commsSMSLogColumns { - return buildCommsSMSLogColumns(alias) +func (commsTextLogColumns) AliasedAs(alias string) commsTextLogColumns { + return buildCommsTextLogColumns(alias) } -// CommsSMSLogSetter is used for insert/upsert/update operations +// CommsTextLogSetter is used for insert/upsert/update operations // All values are optional, and do not have to be set // Generated columns are not included -type CommsSMSLogSetter struct { - Created omit.Val[time.Time] `db:"created" ` - Destination omit.Val[string] `db:"destination,pk" ` - Source omit.Val[string] `db:"source,pk" ` - Type omit.Val[enums.CommsSmsmessagetype] `db:"type,pk" ` +type CommsTextLogSetter struct { + Created omit.Val[time.Time] `db:"created" ` + Destination omit.Val[string] `db:"destination,pk" ` + Source omit.Val[string] `db:"source,pk" ` + Type omit.Val[enums.CommsMessagetypetext] `db:"type,pk" ` } -func (s CommsSMSLogSetter) SetColumns() []string { +func (s CommsTextLogSetter) SetColumns() []string { vals := make([]string, 0, 4) if s.Created.IsValue() { vals = append(vals, "created") @@ -106,7 +106,7 @@ func (s CommsSMSLogSetter) SetColumns() []string { return vals } -func (s CommsSMSLogSetter) Overwrite(t *CommsSMSLog) { +func (s CommsTextLogSetter) Overwrite(t *CommsTextLog) { if s.Created.IsValue() { t.Created = s.Created.MustGet() } @@ -121,9 +121,9 @@ func (s CommsSMSLogSetter) Overwrite(t *CommsSMSLog) { } } -func (s *CommsSMSLogSetter) Apply(q *dialect.InsertQuery) { +func (s *CommsTextLogSetter) Apply(q *dialect.InsertQuery) { q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return CommsSMSLogs.BeforeInsertHooks.RunHooks(ctx, exec, s) + return CommsTextLogs.BeforeInsertHooks.RunHooks(ctx, exec, s) }) q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { @@ -156,11 +156,11 @@ func (s *CommsSMSLogSetter) Apply(q *dialect.InsertQuery) { })) } -func (s CommsSMSLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { +func (s CommsTextLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { return um.Set(s.Expressions()...) } -func (s CommsSMSLogSetter) Expressions(prefix ...string) []bob.Expression { +func (s CommsTextLogSetter) Expressions(prefix ...string) []bob.Expression { exprs := make([]bob.Expression, 0, 4) if s.Created.IsValue() { @@ -194,54 +194,54 @@ func (s CommsSMSLogSetter) Expressions(prefix ...string) []bob.Expression { return exprs } -// FindCommsSMSLog retrieves a single record by primary key +// FindCommsTextLog retrieves a single record by primary key // If cols is empty Find will return all columns. -func FindCommsSMSLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsSmsmessagetype, cols ...string) (*CommsSMSLog, error) { +func FindCommsTextLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypetext, cols ...string) (*CommsTextLog, error) { if len(cols) == 0 { - return CommsSMSLogs.Query( - sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), - sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))), - sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))), + return CommsTextLogs.Query( + sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), + sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))), + sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))), ).One(ctx, exec) } - return CommsSMSLogs.Query( - sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), - sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))), - sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))), - sm.Columns(CommsSMSLogs.Columns.Only(cols...)), + return CommsTextLogs.Query( + sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), + sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))), + sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))), + sm.Columns(CommsTextLogs.Columns.Only(cols...)), ).One(ctx, exec) } -// CommsSMSLogExists checks the presence of a single record by primary key -func CommsSMSLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsSmsmessagetype) (bool, error) { - return CommsSMSLogs.Query( - sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), - sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))), - sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))), +// CommsTextLogExists checks the presence of a single record by primary key +func CommsTextLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypetext) (bool, error) { + return CommsTextLogs.Query( + sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))), + sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))), + sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))), ).Exists(ctx, exec) } -// AfterQueryHook is called after CommsSMSLog is retrieved from the database -func (o *CommsSMSLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { +// AfterQueryHook is called after CommsTextLog is retrieved from the database +func (o *CommsTextLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { var err error switch queryType { case bob.QueryTypeSelect: - ctx, err = CommsSMSLogs.AfterSelectHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o}) + ctx, err = CommsTextLogs.AfterSelectHooks.RunHooks(ctx, exec, CommsTextLogSlice{o}) case bob.QueryTypeInsert: - ctx, err = CommsSMSLogs.AfterInsertHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o}) + ctx, err = CommsTextLogs.AfterInsertHooks.RunHooks(ctx, exec, CommsTextLogSlice{o}) case bob.QueryTypeUpdate: - ctx, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o}) + ctx, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, CommsTextLogSlice{o}) case bob.QueryTypeDelete: - ctx, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o}) + ctx, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, CommsTextLogSlice{o}) } return err } -// primaryKeyVals returns the primary key values of the CommsSMSLog -func (o *CommsSMSLog) primaryKeyVals() bob.Expression { +// primaryKeyVals returns the primary key values of the CommsTextLog +func (o *CommsTextLog) primaryKeyVals() bob.Expression { return psql.ArgGroup( o.Destination, o.Source, @@ -249,15 +249,15 @@ func (o *CommsSMSLog) primaryKeyVals() bob.Expression { ) } -func (o *CommsSMSLog) pkEQ() dialect.Expression { - return psql.Group(psql.Quote("comms.sms_log", "destination"), psql.Quote("comms.sms_log", "source"), psql.Quote("comms.sms_log", "type")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { +func (o *CommsTextLog) pkEQ() dialect.Expression { + return psql.Group(psql.Quote("comms.text_log", "destination"), psql.Quote("comms.text_log", "source"), psql.Quote("comms.text_log", "type")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { return o.primaryKeyVals().WriteSQL(ctx, w, d, start) })) } -// Update uses an executor to update the CommsSMSLog -func (o *CommsSMSLog) Update(ctx context.Context, exec bob.Executor, s *CommsSMSLogSetter) error { - v, err := CommsSMSLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) +// Update uses an executor to update the CommsTextLog +func (o *CommsTextLog) Update(ctx context.Context, exec bob.Executor, s *CommsTextLogSetter) error { + v, err := CommsTextLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) if err != nil { return err } @@ -268,18 +268,18 @@ func (o *CommsSMSLog) Update(ctx context.Context, exec bob.Executor, s *CommsSMS return nil } -// Delete deletes a single CommsSMSLog record with an executor -func (o *CommsSMSLog) Delete(ctx context.Context, exec bob.Executor) error { - _, err := CommsSMSLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) +// Delete deletes a single CommsTextLog record with an executor +func (o *CommsTextLog) Delete(ctx context.Context, exec bob.Executor) error { + _, err := CommsTextLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) return err } -// Reload refreshes the CommsSMSLog using the executor -func (o *CommsSMSLog) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := CommsSMSLogs.Query( - sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(o.Destination))), - sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(o.Source))), - sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(o.Type))), +// Reload refreshes the CommsTextLog using the executor +func (o *CommsTextLog) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := CommsTextLogs.Query( + sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(o.Destination))), + sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(o.Source))), + sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(o.Type))), ).One(ctx, exec) if err != nil { return err @@ -290,30 +290,30 @@ func (o *CommsSMSLog) Reload(ctx context.Context, exec bob.Executor) error { return nil } -// AfterQueryHook is called after CommsSMSLogSlice is retrieved from the database -func (o CommsSMSLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { +// AfterQueryHook is called after CommsTextLogSlice is retrieved from the database +func (o CommsTextLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { var err error switch queryType { case bob.QueryTypeSelect: - ctx, err = CommsSMSLogs.AfterSelectHooks.RunHooks(ctx, exec, o) + ctx, err = CommsTextLogs.AfterSelectHooks.RunHooks(ctx, exec, o) case bob.QueryTypeInsert: - ctx, err = CommsSMSLogs.AfterInsertHooks.RunHooks(ctx, exec, o) + ctx, err = CommsTextLogs.AfterInsertHooks.RunHooks(ctx, exec, o) case bob.QueryTypeUpdate: - ctx, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + ctx, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) case bob.QueryTypeDelete: - ctx, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + ctx, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) } return err } -func (o CommsSMSLogSlice) pkIN() dialect.Expression { +func (o CommsTextLogSlice) pkIN() dialect.Expression { if len(o) == 0 { return psql.Raw("NULL") } - return psql.Group(psql.Quote("comms.sms_log", "destination"), psql.Quote("comms.sms_log", "source"), psql.Quote("comms.sms_log", "type")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Group(psql.Quote("comms.text_log", "destination"), psql.Quote("comms.text_log", "source"), psql.Quote("comms.text_log", "type")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { pkPairs := make([]bob.Expression, len(o)) for i, row := range o { pkPairs[i] = row.primaryKeyVals() @@ -325,7 +325,7 @@ func (o CommsSMSLogSlice) pkIN() dialect.Expression { // copyMatchingRows finds models in the given slice that have the same primary key // then it first copies the existing relationships from the old model to the new model // and then replaces the old model in the slice with the new model -func (o CommsSMSLogSlice) copyMatchingRows(from ...*CommsSMSLog) { +func (o CommsTextLogSlice) copyMatchingRows(from ...*CommsTextLog) { for i, old := range o { for _, new := range from { if new.Destination != old.Destination { @@ -345,25 +345,25 @@ func (o CommsSMSLogSlice) copyMatchingRows(from ...*CommsSMSLog) { } // UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o CommsSMSLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { +func (o CommsTextLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return CommsSMSLogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + return CommsTextLogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) }) q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { var err error switch retrieved := retrieved.(type) { - case *CommsSMSLog: + case *CommsTextLog: o.copyMatchingRows(retrieved) - case []*CommsSMSLog: + case []*CommsTextLog: o.copyMatchingRows(retrieved...) - case CommsSMSLogSlice: + case CommsTextLogSlice: o.copyMatchingRows(retrieved...) default: - // If the retrieved value is not a CommsSMSLog or a slice of CommsSMSLog + // If the retrieved value is not a CommsTextLog or a slice of CommsTextLog // then run the AfterUpdateHooks on the slice - _, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + _, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) } return err @@ -374,25 +374,25 @@ func (o CommsSMSLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } // DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o CommsSMSLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { +func (o CommsTextLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return CommsSMSLogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + return CommsTextLogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) }) q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { var err error switch retrieved := retrieved.(type) { - case *CommsSMSLog: + case *CommsTextLog: o.copyMatchingRows(retrieved) - case []*CommsSMSLog: + case []*CommsTextLog: o.copyMatchingRows(retrieved...) - case CommsSMSLogSlice: + case CommsTextLogSlice: o.copyMatchingRows(retrieved...) default: - // If the retrieved value is not a CommsSMSLog or a slice of CommsSMSLog + // If the retrieved value is not a CommsTextLog or a slice of CommsTextLog // then run the AfterDeleteHooks on the slice - _, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + _, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) } return err @@ -402,30 +402,30 @@ func (o CommsSMSLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { }) } -func (o CommsSMSLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsSMSLogSetter) error { +func (o CommsTextLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsTextLogSetter) error { if len(o) == 0 { return nil } - _, err := CommsSMSLogs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + _, err := CommsTextLogs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) return err } -func (o CommsSMSLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { +func (o CommsTextLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { if len(o) == 0 { return nil } - _, err := CommsSMSLogs.Delete(o.DeleteMod()).Exec(ctx, exec) + _, err := CommsTextLogs.Delete(o.DeleteMod()).Exec(ctx, exec) return err } -func (o CommsSMSLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { +func (o CommsTextLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { if len(o) == 0 { return nil } - o2, err := CommsSMSLogs.Query(sm.Where(o.pkIN())).All(ctx, exec) + o2, err := CommsTextLogs.Query(sm.Where(o.pkIN())).All(ctx, exec) if err != nil { return err } @@ -436,13 +436,13 @@ func (o CommsSMSLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) erro } // DestinationPhone starts a query for related objects on comms.phone -func (o *CommsSMSLog) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { +func (o *CommsTextLog) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { return CommsPhones.Query(append(mods, sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.Destination))), )...) } -func (os CommsSMSLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { +func (os CommsTextLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { pkDestination := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -460,13 +460,13 @@ func (os CommsSMSLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery } // SourcePhone starts a query for related objects on comms.phone -func (o *CommsSMSLog) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { +func (o *CommsTextLog) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { return CommsPhones.Query(append(mods, sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.Source))), )...) } -func (os CommsSMSLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { +func (os CommsTextLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { pkSource := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -483,20 +483,20 @@ func (os CommsSMSLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) Co )...) } -func attachCommsSMSLogDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsSMSLog0 *CommsSMSLog, commsPhone1 *CommsPhone) (*CommsSMSLog, error) { - setter := &CommsSMSLogSetter{ +func attachCommsTextLogDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsTextLog0 *CommsTextLog, commsPhone1 *CommsPhone) (*CommsTextLog, error) { + setter := &CommsTextLogSetter{ Destination: omit.From(commsPhone1.E164), } - err := commsSMSLog0.Update(ctx, exec, setter) + err := commsTextLog0.Update(ctx, exec, setter) if err != nil { - return nil, fmt.Errorf("attachCommsSMSLogDestinationPhone0: %w", err) + return nil, fmt.Errorf("attachCommsTextLogDestinationPhone0: %w", err) } - return commsSMSLog0, nil + return commsTextLog0, nil } -func (commsSMSLog0 *CommsSMSLog) InsertDestinationPhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error { +func (commsTextLog0 *CommsTextLog) InsertDestinationPhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error { var err error commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec) @@ -504,47 +504,47 @@ func (commsSMSLog0 *CommsSMSLog) InsertDestinationPhone(ctx context.Context, exe return fmt.Errorf("inserting related objects: %w", err) } - _, err = attachCommsSMSLogDestinationPhone0(ctx, exec, 1, commsSMSLog0, commsPhone1) + _, err = attachCommsTextLogDestinationPhone0(ctx, exec, 1, commsTextLog0, commsPhone1) if err != nil { return err } - commsSMSLog0.R.DestinationPhone = commsPhone1 + commsTextLog0.R.DestinationPhone = commsPhone1 - commsPhone1.R.DestinationSMSLogs = append(commsPhone1.R.DestinationSMSLogs, commsSMSLog0) + commsPhone1.R.DestinationTextLogs = append(commsPhone1.R.DestinationTextLogs, commsTextLog0) return nil } -func (commsSMSLog0 *CommsSMSLog) AttachDestinationPhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error { +func (commsTextLog0 *CommsTextLog) AttachDestinationPhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error { var err error - _, err = attachCommsSMSLogDestinationPhone0(ctx, exec, 1, commsSMSLog0, commsPhone1) + _, err = attachCommsTextLogDestinationPhone0(ctx, exec, 1, commsTextLog0, commsPhone1) if err != nil { return err } - commsSMSLog0.R.DestinationPhone = commsPhone1 + commsTextLog0.R.DestinationPhone = commsPhone1 - commsPhone1.R.DestinationSMSLogs = append(commsPhone1.R.DestinationSMSLogs, commsSMSLog0) + commsPhone1.R.DestinationTextLogs = append(commsPhone1.R.DestinationTextLogs, commsTextLog0) return nil } -func attachCommsSMSLogSourcePhone0(ctx context.Context, exec bob.Executor, count int, commsSMSLog0 *CommsSMSLog, commsPhone1 *CommsPhone) (*CommsSMSLog, error) { - setter := &CommsSMSLogSetter{ +func attachCommsTextLogSourcePhone0(ctx context.Context, exec bob.Executor, count int, commsTextLog0 *CommsTextLog, commsPhone1 *CommsPhone) (*CommsTextLog, error) { + setter := &CommsTextLogSetter{ Source: omit.From(commsPhone1.E164), } - err := commsSMSLog0.Update(ctx, exec, setter) + err := commsTextLog0.Update(ctx, exec, setter) if err != nil { - return nil, fmt.Errorf("attachCommsSMSLogSourcePhone0: %w", err) + return nil, fmt.Errorf("attachCommsTextLogSourcePhone0: %w", err) } - return commsSMSLog0, nil + return commsTextLog0, nil } -func (commsSMSLog0 *CommsSMSLog) InsertSourcePhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error { +func (commsTextLog0 *CommsTextLog) InsertSourcePhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error { var err error commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec) @@ -552,54 +552,54 @@ func (commsSMSLog0 *CommsSMSLog) InsertSourcePhone(ctx context.Context, exec bob return fmt.Errorf("inserting related objects: %w", err) } - _, err = attachCommsSMSLogSourcePhone0(ctx, exec, 1, commsSMSLog0, commsPhone1) + _, err = attachCommsTextLogSourcePhone0(ctx, exec, 1, commsTextLog0, commsPhone1) if err != nil { return err } - commsSMSLog0.R.SourcePhone = commsPhone1 + commsTextLog0.R.SourcePhone = commsPhone1 - commsPhone1.R.SourceSMSLogs = append(commsPhone1.R.SourceSMSLogs, commsSMSLog0) + commsPhone1.R.SourceTextLogs = append(commsPhone1.R.SourceTextLogs, commsTextLog0) return nil } -func (commsSMSLog0 *CommsSMSLog) AttachSourcePhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error { +func (commsTextLog0 *CommsTextLog) AttachSourcePhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error { var err error - _, err = attachCommsSMSLogSourcePhone0(ctx, exec, 1, commsSMSLog0, commsPhone1) + _, err = attachCommsTextLogSourcePhone0(ctx, exec, 1, commsTextLog0, commsPhone1) if err != nil { return err } - commsSMSLog0.R.SourcePhone = commsPhone1 + commsTextLog0.R.SourcePhone = commsPhone1 - commsPhone1.R.SourceSMSLogs = append(commsPhone1.R.SourceSMSLogs, commsSMSLog0) + commsPhone1.R.SourceTextLogs = append(commsPhone1.R.SourceTextLogs, commsTextLog0) return nil } -type commsSMSLogWhere[Q psql.Filterable] struct { +type commsTextLogWhere[Q psql.Filterable] struct { Created psql.WhereMod[Q, time.Time] Destination psql.WhereMod[Q, string] Source psql.WhereMod[Q, string] - Type psql.WhereMod[Q, enums.CommsSmsmessagetype] + Type psql.WhereMod[Q, enums.CommsMessagetypetext] } -func (commsSMSLogWhere[Q]) AliasedAs(alias string) commsSMSLogWhere[Q] { - return buildCommsSMSLogWhere[Q](buildCommsSMSLogColumns(alias)) +func (commsTextLogWhere[Q]) AliasedAs(alias string) commsTextLogWhere[Q] { + return buildCommsTextLogWhere[Q](buildCommsTextLogColumns(alias)) } -func buildCommsSMSLogWhere[Q psql.Filterable](cols commsSMSLogColumns) commsSMSLogWhere[Q] { - return commsSMSLogWhere[Q]{ +func buildCommsTextLogWhere[Q psql.Filterable](cols commsTextLogColumns) commsTextLogWhere[Q] { + return commsTextLogWhere[Q]{ Created: psql.Where[Q, time.Time](cols.Created), Destination: psql.Where[Q, string](cols.Destination), Source: psql.Where[Q, string](cols.Source), - Type: psql.Where[Q, enums.CommsSmsmessagetype](cols.Type), + Type: psql.Where[Q, enums.CommsMessagetypetext](cols.Type), } } -func (o *CommsSMSLog) Preload(name string, retrieved any) error { +func (o *CommsTextLog) Preload(name string, retrieved any) error { if o == nil { return nil } @@ -608,45 +608,45 @@ func (o *CommsSMSLog) Preload(name string, retrieved any) error { case "DestinationPhone": rel, ok := retrieved.(*CommsPhone) if !ok { - return fmt.Errorf("commsSMSLog cannot load %T as %q", retrieved, name) + return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name) } o.R.DestinationPhone = rel if rel != nil { - rel.R.DestinationSMSLogs = CommsSMSLogSlice{o} + rel.R.DestinationTextLogs = CommsTextLogSlice{o} } return nil case "SourcePhone": rel, ok := retrieved.(*CommsPhone) if !ok { - return fmt.Errorf("commsSMSLog cannot load %T as %q", retrieved, name) + return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name) } o.R.SourcePhone = rel if rel != nil { - rel.R.SourceSMSLogs = CommsSMSLogSlice{o} + rel.R.SourceTextLogs = CommsTextLogSlice{o} } return nil default: - return fmt.Errorf("commsSMSLog has no relationship %q", name) + return fmt.Errorf("commsTextLog has no relationship %q", name) } } -type commsSMSLogPreloader struct { +type commsTextLogPreloader struct { DestinationPhone func(...psql.PreloadOption) psql.Preloader SourcePhone func(...psql.PreloadOption) psql.Preloader } -func buildCommsSMSLogPreloader() commsSMSLogPreloader { - return commsSMSLogPreloader{ +func buildCommsTextLogPreloader() commsTextLogPreloader { + return commsTextLogPreloader{ DestinationPhone: func(opts ...psql.PreloadOption) psql.Preloader { return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{ Name: "DestinationPhone", Sides: []psql.PreloadSide{ { - From: CommsSMSLogs, + From: CommsTextLogs, To: CommsPhones, FromColumns: []string{"destination"}, ToColumns: []string{"e164"}, @@ -659,7 +659,7 @@ func buildCommsSMSLogPreloader() commsSMSLogPreloader { Name: "SourcePhone", Sides: []psql.PreloadSide{ { - From: CommsSMSLogs, + From: CommsTextLogs, To: CommsPhones, FromColumns: []string{"source"}, ToColumns: []string{"e164"}, @@ -670,12 +670,12 @@ func buildCommsSMSLogPreloader() commsSMSLogPreloader { } } -type commsSMSLogThenLoader[Q orm.Loadable] struct { +type commsTextLogThenLoader[Q orm.Loadable] struct { DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] SourcePhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } -func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] { +func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] { type DestinationPhoneLoadInterface interface { LoadDestinationPhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -683,7 +683,7 @@ func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] { LoadSourcePhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - return commsSMSLogThenLoader[Q]{ + return commsTextLogThenLoader[Q]{ DestinationPhone: thenLoadBuilder[Q]( "DestinationPhone", func(ctx context.Context, exec bob.Executor, retrieved DestinationPhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -699,8 +699,8 @@ func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] { } } -// LoadDestinationPhone loads the commsSMSLog's DestinationPhone into the .R struct -func (o *CommsSMSLog) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadDestinationPhone loads the commsTextLog's DestinationPhone into the .R struct +func (o *CommsTextLog) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } @@ -713,14 +713,14 @@ func (o *CommsSMSLog) LoadDestinationPhone(ctx context.Context, exec bob.Executo return err } - related.R.DestinationSMSLogs = CommsSMSLogSlice{o} + related.R.DestinationTextLogs = CommsTextLogSlice{o} o.R.DestinationPhone = related return nil } -// LoadDestinationPhone loads the commsSMSLog's DestinationPhone into the .R struct -func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadDestinationPhone loads the commsTextLog's DestinationPhone into the .R struct +func (os CommsTextLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } @@ -741,7 +741,7 @@ func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Ex continue } - rel.R.DestinationSMSLogs = append(rel.R.DestinationSMSLogs, o) + rel.R.DestinationTextLogs = append(rel.R.DestinationTextLogs, o) o.R.DestinationPhone = rel break @@ -751,8 +751,8 @@ func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Ex return nil } -// LoadSourcePhone loads the commsSMSLog's SourcePhone into the .R struct -func (o *CommsSMSLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadSourcePhone loads the commsTextLog's SourcePhone into the .R struct +func (o *CommsTextLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } @@ -765,14 +765,14 @@ func (o *CommsSMSLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mo return err } - related.R.SourceSMSLogs = CommsSMSLogSlice{o} + related.R.SourceTextLogs = CommsTextLogSlice{o} o.R.SourcePhone = related return nil } -// LoadSourcePhone loads the commsSMSLog's SourcePhone into the .R struct -func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadSourcePhone loads the commsTextLog's SourcePhone into the .R struct +func (os CommsTextLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } @@ -793,7 +793,7 @@ func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executo continue } - rel.R.SourceSMSLogs = append(rel.R.SourceSMSLogs, o) + rel.R.SourceTextLogs = append(rel.R.SourceTextLogs, o) o.R.SourcePhone = rel break @@ -803,18 +803,18 @@ func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executo return nil } -type commsSMSLogJoins[Q dialect.Joinable] struct { +type commsTextLogJoins[Q dialect.Joinable] struct { typ string DestinationPhone modAs[Q, commsPhoneColumns] SourcePhone modAs[Q, commsPhoneColumns] } -func (j commsSMSLogJoins[Q]) aliasedAs(alias string) commsSMSLogJoins[Q] { - return buildCommsSMSLogJoins[Q](buildCommsSMSLogColumns(alias), j.typ) +func (j commsTextLogJoins[Q]) aliasedAs(alias string) commsTextLogJoins[Q] { + return buildCommsTextLogJoins[Q](buildCommsTextLogColumns(alias), j.typ) } -func buildCommsSMSLogJoins[Q dialect.Joinable](cols commsSMSLogColumns, typ string) commsSMSLogJoins[Q] { - return commsSMSLogJoins[Q]{ +func buildCommsTextLogJoins[Q dialect.Joinable](cols commsTextLogColumns, typ string) commsTextLogJoins[Q] { + return commsTextLogJoins[Q]{ typ: typ, DestinationPhone: modAs[Q, commsPhoneColumns]{ c: CommsPhones.Columns, diff --git a/go.mod b/go.mod index ef56dc10..cde54c4f 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( require ( github.com/ajg/form v1.5.1 // indirect + github.com/beevik/etree v1.1.0 // indirect github.com/dsoprea/go-exif/v3 v3.0.1 // indirect github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb // indirect github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102 // indirect @@ -43,7 +44,9 @@ require ( github.com/go-errors/errors v1.4.2 // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect + github.com/golang-jwt/jwt/v5 v5.2.2 // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect + github.com/golang/mock v1.6.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect @@ -55,8 +58,10 @@ require ( github.com/mfridman/interpolate v0.0.2 // indirect github.com/minio/crc64nvme v1.1.0 // indirect github.com/minio/md5-simd v1.1.2 // indirect + github.com/nyaruka/phonenumbers v1.6.8 // indirect github.com/pganalyze/pg_query_go/v6 v6.1.0 // indirect github.com/philhofer/fwd v1.2.0 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/qdm12/reprint v0.0.0-20200326205758-722754a53494 // indirect github.com/rs/xid v1.6.0 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect @@ -69,13 +74,15 @@ require ( github.com/tidwall/rtree v1.3.1 // indirect github.com/tidwall/sjson v1.2.4 // indirect github.com/tinylib/msgp v1.3.0 // indirect + github.com/twilio/twilio-go v1.29.1 // indirect github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect golang.org/x/net v0.43.0 // indirect golang.org/x/sync v0.17.0 // indirect golang.org/x/sys v0.36.0 // indirect golang.org/x/text v0.29.0 // indirect - google.golang.org/protobuf v1.36.5 // indirect + google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c6543560..41a400eb 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/alexedwards/scs/v2 v2.9.0 h1:xa05mVpwTBm1iLeTMNFfAWpKUm4fXAW7CeAViqBV github.com/alexedwards/scs/v2 v2.9.0/go.mod h1:ToaROZxyKukJKT/xLcVQAChi5k6+Pn1Gvmdl7h3RRj8= github.com/alitto/pond/v2 v2.5.0 h1:vPzS5GnvSDRhWQidmj2djHllOmjFExVFbDGCw1jdqDw= github.com/alitto/pond/v2 v2.5.0/go.mod h1:xkjYEgQ05RSpWdfSd1nM3OVv7TBhLdy7rMp3+2Nq+yE= +github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= +github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= @@ -101,10 +103,14 @@ github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0= github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/geo v0.0.0-20200319012246-673a6f80352d/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 h1:gtexQ/VGyN+VVFRXSFiguSNcXmS6rkKT+X7FdIrTtfo= github.com/golang/geo v0.0.0-20210211234256-740aa86cb551/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -143,6 +149,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275/go.mod h1:zt6UU74K6Z6oMOYJbJzYpYucqdcQwSMPBEdSvGiaUMw= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= @@ -179,6 +186,9 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nyaruka/phonenumbers v1.6.8 h1:k7HAJ/LeBkXE0vfbajITzTCZD0z0j+epdBNx43yTygk= +github.com/nyaruka/phonenumbers v1.6.8/go.mod h1:IUu45lj2bSeYXQuxDyyuzOrdV10tyRa1YSsfH8EKN5c= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= @@ -263,12 +273,15 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/twilio/twilio-go v1.29.1 h1:4dx1d9EhRUhL5ubzYrDROERAiw55s7mBE6/w3q2epVg= +github.com/twilio/twilio-go v1.29.1/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw= github.com/uber/h3-go/v4 v4.4.0 h1:sCHcZHvIKEbdt4rY5ZVs2HDNlCy2wXeJ98vAbz+iLok= github.com/uber/h3-go/v4 v4.4.0/go.mod h1:c94kwXZNHVWkZGIN+y9dV81YVEttypqJpOjsmXGr68Y= github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo= github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= @@ -285,6 +298,7 @@ go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXe go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= @@ -292,6 +306,7 @@ golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -302,6 +317,7 @@ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -309,6 +325,7 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= @@ -318,6 +335,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -346,16 +365,22 @@ golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/main.go b/main.go index 2f5d450d..f3c432e1 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "os" "os/signal" "runtime/debug" - "sync" "syscall" "time" @@ -16,7 +15,6 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/config" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/public-report" - "github.com/Gleipnir-Technology/nidus-sync/queue" nidussync "github.com/Gleipnir-Technology/nidus-sync/sync" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" @@ -64,36 +62,7 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - background.NewOAuthTokenChannel = make(chan struct{}, 10) - queue.ChannelJobAudio = make(chan queue.JobAudio, 100) // Buffered channel to prevent blocking - queue.ChannelJobEmail = make(chan queue.JobEmail, 100) // Buffered channel to prevent blocking - queue.ChannelJobSMS = make(chan queue.JobSMS, 100) // Buffered channel to prevent blocking - - var waitGroup sync.WaitGroup - - waitGroup.Add(1) - go func() { - defer waitGroup.Done() - background.RefreshFieldseekerData(ctx, background.NewOAuthTokenChannel) - }() - - waitGroup.Add(1) - go func() { - defer waitGroup.Done() - background.StartWorkerAudio(ctx, queue.ChannelJobAudio) - }() - - waitGroup.Add(1) - go func() { - defer waitGroup.Done() - background.StartWorkerEmail(ctx, queue.ChannelJobEmail) - }() - - waitGroup.Add(1) - go func() { - defer waitGroup.Done() - background.StartWorkerSMS(ctx, queue.ChannelJobSMS) - }() + background.Start(ctx) server := &http.Server{ Addr: config.Bind, Handler: r, @@ -119,8 +88,7 @@ func main() { } cancel() - - waitGroup.Wait() + background.WaitForExit() log.Info().Msg("Shutdown complete") } diff --git a/public-report/quick.go b/public-report/quick.go index 9a741a89..561ddaae 100644 --- a/public-report/quick.go +++ b/public-report/quick.go @@ -6,13 +6,13 @@ import ( "strconv" "time" - "github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/Gleipnir-Technology/nidus-sync/background" + "github.com/Gleipnir-Technology/nidus-sync/comms" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/h3utils" "github.com/Gleipnir-Technology/nidus-sync/htmlpage" - "github.com/Gleipnir-Technology/nidus-sync/queue" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" "github.com/rs/zerolog/log" @@ -157,16 +157,17 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) { } consent := r.PostFormValue("consent") email := r.PostFormValue("email") - phone := r.PostFormValue("phone") + phone_str := r.PostFormValue("phone") report_id := r.PostFormValue("report_id") if consent != "on" { respondError(w, "You must consent", nil, http.StatusBadRequest) return } - if email == "" && phone == "" { + if email == "" && phone_str == "" { http.Redirect(w, r, fmt.Sprintf("/quick-submit-complete?report=%s", report_id), http.StatusFound) return } + phone, err := comms.ParsePhoneNumber(phone_str) result, err := psql.Update( um.Table("publicreport.quick"), um.SetCol("reporter_email").ToArg(email), @@ -183,18 +184,10 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) { return } if email != "" { - queue.EnqueueJobEmail(queue.JobEmail{ - Destination: email, - Source: config.ForwardEmailReportAddress, - Type: enums.CommsEmailmessagetypeReportSubscriptionConfirmation, - }) + background.ReportSubscriptionConfirmationEmail(email) } - if phone != "" { - queue.EnqueueJobSMS(queue.JobSMS{ - Destination: phone, - Source: config.VoipMSNumber, - Type: enums.CommsSmsmessagetypeReportSubscriptionConfirmation, - }) + if phone_str != "" { + background.ReportSubscriptionConfirmationText(*phone, report_id) } if rowcount == 0 { http.Redirect(w, r, fmt.Sprintf("/error?code=no-rows-affected&report=%s", report_id), http.StatusFound) diff --git a/queue/audio_processing.go b/queue/audio_processing.go deleted file mode 100644 index 5664b3ee..00000000 --- a/queue/audio_processing.go +++ /dev/null @@ -1,23 +0,0 @@ -package queue - -import ( - "github.com/google/uuid" - "github.com/rs/zerolog/log" -) - -// AudioJob represents a job to process an audio file. -type JobAudio struct { - AudioUUID uuid.UUID -} - -var ChannelJobAudio chan JobAudio - -// EnqueueAudioJob sends an audio processing job to the worker. -func EnqueueAudioJob(job JobAudio) { - select { - case ChannelJobAudio <- job: - log.Info().Str("uuid", job.AudioUUID.String()).Msg("Enqueued audio job") - default: - log.Warn().Str("uuid", job.AudioUUID.String()).Msg("Audio job channel is full, dropping job") - } -} diff --git a/queue/comms.go b/queue/comms.go deleted file mode 100644 index d2dd624a..00000000 --- a/queue/comms.go +++ /dev/null @@ -1,38 +0,0 @@ -package queue - -import ( - "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/rs/zerolog/log" -) - -type JobEmail struct { - Destination string - Source string - Type enums.CommsEmailmessagetype -} -type JobSMS struct { - Destination string - Source string - Type enums.CommsSmsmessagetype -} - -var ChannelJobEmail chan JobEmail -var ChannelJobSMS chan JobSMS - -func EnqueueJobEmail(job JobEmail) { - select { - case ChannelJobEmail <- job: - log.Info().Str("destination", job.Destination).Msg("Enqueued email job") - default: - log.Warn().Msg("email job channel is full, dropping job") - } -} - -func EnqueueJobSMS(job JobSMS) { - select { - case ChannelJobSMS <- job: - log.Info().Str("destination", job.Destination).Msg("Enqueued sms job") - default: - log.Warn().Msg("sms job channel is full, dropping job") - } -}