Add contacts, rework comms schema
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.
This commit is contained in:
parent
085935fa66
commit
f1fe8b4d2b
46 changed files with 1127 additions and 633 deletions
|
|
@ -9,18 +9,42 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
|
||||
)
|
||||
|
||||
func TextLogFromID(ctx context.Context, id int64) (model.TextLog, error) {
|
||||
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.ExecuteOne[model.TextLog](ctx, statement)
|
||||
return db.ExecuteOneTx[model.TextLog](ctx, txn, statement)
|
||||
}
|
||||
func TextLogsFromPhoneNumber(ctx context.Context, number string) ([]model.TextLog, error) {
|
||||
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.ExecuteMany[model.TextLog](ctx, statement)
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue