This in a pretty huge change. At a high level we're adding the concept of a 'contact' which is a person or organization that has zero or more contact methods (email, phone). This ended up cascading a number of changes, including critically to the publicreprt schema. In the end it seemed safer to get to the point where I'm confident we aren't using any of the old fields for storing reporter information (though I haven't deleted the columns yet) so I removed the code for defining those columns. At this point I think it's not possible for me to regenerate the bob schema due to the interdependencies between my various schemas, so the migration is well-and-truly happening.
50 lines
2 KiB
Go
50 lines
2 KiB
Go
package comms
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Gleipnir-Technology/jet/postgres"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
|
|
)
|
|
|
|
func TextLogInsert(ctx context.Context, txn db.Ex, m model.TextLog) (model.TextLog, error) {
|
|
statement := table.TextLog.INSERT(
|
|
table.TextLog.MutableColumns,
|
|
).MODEL(m)
|
|
return db.ExecuteOneTx[model.TextLog](ctx, txn, statement)
|
|
}
|
|
func TextLogFromID(ctx context.Context, txn db.Ex, id int64) (model.TextLog, error) {
|
|
statement := table.TextLog.SELECT(
|
|
table.TextLog.AllColumns,
|
|
).FROM(table.TextLog).
|
|
WHERE(table.TextLog.ID.EQ(postgres.Int(id)))
|
|
return db.ExecuteOneTx[model.TextLog](ctx, txn, statement)
|
|
}
|
|
func TextLogsFromPhoneNumber(ctx context.Context, txn db.Ex, number string) ([]model.TextLog, error) {
|
|
statement := table.TextLog.SELECT(
|
|
table.TextLog.AllColumns,
|
|
).FROM(table.TextLog).
|
|
WHERE(table.TextLog.Source.EQ(postgres.String(number)).OR(
|
|
table.TextLog.Destination.EQ(postgres.String(number))))
|
|
return db.ExecuteManyTx[model.TextLog](ctx, txn, statement)
|
|
}
|
|
func TextLogWelcomeFromDestination(ctx context.Context, txn db.Ex, destination string) ([]model.TextLog, error) {
|
|
statement := table.TextLog.SELECT(
|
|
table.TextLog.AllColumns,
|
|
).FROM(table.TextLog).
|
|
WHERE(table.TextLog.Destination.EQ(postgres.String(destination)).AND(
|
|
table.TextLog.IsWelcome.EQ(postgres.Bool(true))))
|
|
return db.ExecuteManyTx[model.TextLog](ctx, txn, statement)
|
|
}
|
|
func TextLogUpdate(ctx context.Context, txn db.Ex, id int64, twilio_sid string, twilio_status string) error {
|
|
statement := table.TextLog.UPDATE(
|
|
table.TextLog.TwilioSid,
|
|
table.TextLog.TwilioStatus,
|
|
).SET(
|
|
table.TextLog.TwilioSid.SET(postgres.String(twilio_sid)),
|
|
table.TextLog.TwilioStatus.SET(postgres.String(twilio_status)),
|
|
).WHERE(table.TextLog.ID.EQ(postgres.Int(id)))
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
|
}
|