Migrate contact_email and contact_phone to allow dupes
The key item here is that comms.phone and comms.email are meant to represent a real global namespace, but comms.contact is meant to represent an organization-specific namespace. This means the mapping, comms.contact_phone and comms.contact_email can't key off the global namespace. Otherwise the contact namespace would implicitly be global.
This commit is contained in:
parent
a72f228e4e
commit
f957dc6982
14 changed files with 250 additions and 44 deletions
|
|
@ -2,12 +2,9 @@ package text
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db/enums"
|
||||
modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
|
||||
querycomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/comms"
|
||||
"source.gleipnir.technology/Gleipnir/nidus-sync/platform/types"
|
||||
//"github.com/rs/zerolog/log"
|
||||
|
|
@ -28,10 +25,11 @@ func ensureInDB(ctx context.Context, txn db.Ex, contact modelcomms.Contact, dest
|
|||
_, err = querycomms.ContactPhoneInsert(ctx, txn, contact_phone)
|
||||
return err
|
||||
}
|
||||
func phoneStatus(ctx context.Context, src types.E164) (enums.CommsPhonestatustype, error) {
|
||||
phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString())
|
||||
if err != nil {
|
||||
return enums.CommsPhonestatustypeUnconfirmed, fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src.PhoneString(), err)
|
||||
}
|
||||
return phone.Status, nil
|
||||
func ensurePhoneInDB(ctx context.Context, txn db.Ex, number *types.E164) (modelcomms.Phone, error) {
|
||||
return querycomms.PhoneInsertIfNotExists(ctx, txn, modelcomms.Phone{
|
||||
CanSms: false,
|
||||
E164: number.PhoneString(),
|
||||
IsSubscribed: false,
|
||||
Status: modelcomms.Phonestatustype_Unconfirmed,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue