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:
Eli Ribble 2026-05-22 15:13:03 +00:00
parent a72f228e4e
commit f957dc6982
No known key found for this signature in database
14 changed files with 250 additions and 44 deletions

View file

@ -8,8 +8,9 @@
package model
type ContactEmail struct {
Address string `sql:"primary_key"`
Address string
Confirmed bool
ContactID int32
IsSubscribed bool
ID int32 `sql:"primary_key"`
}

View file

@ -11,7 +11,8 @@ type ContactPhone struct {
CanSms bool
ConfirmedMessageID *int32
ContactID int32
E164 string `sql:"primary_key"`
E164 string
IsSubscribed bool
StopMessageID *int32
ID int32 `sql:"primary_key"`
}

View file

@ -0,0 +1,13 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
type Email struct {
Address string `sql:"primary_key"`
IsSubscribed bool
}

View file

@ -21,6 +21,7 @@ type contactEmailTable struct {
Confirmed postgres.ColumnBool
ContactID postgres.ColumnInteger
IsSubscribed postgres.ColumnBool
ID postgres.ColumnInteger
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
@ -66,9 +67,10 @@ func newContactEmailTableImpl(schemaName, tableName, alias string) contactEmailT
ConfirmedColumn = postgres.BoolColumn("confirmed")
ContactIDColumn = postgres.IntegerColumn("contact_id")
IsSubscribedColumn = postgres.BoolColumn("is_subscribed")
allColumns = postgres.ColumnList{AddressColumn, ConfirmedColumn, ContactIDColumn, IsSubscribedColumn}
mutableColumns = postgres.ColumnList{ConfirmedColumn, ContactIDColumn, IsSubscribedColumn}
defaultColumns = postgres.ColumnList{}
IDColumn = postgres.IntegerColumn("id")
allColumns = postgres.ColumnList{AddressColumn, ConfirmedColumn, ContactIDColumn, IsSubscribedColumn, IDColumn}
mutableColumns = postgres.ColumnList{AddressColumn, ConfirmedColumn, ContactIDColumn, IsSubscribedColumn}
defaultColumns = postgres.ColumnList{IDColumn}
)
return contactEmailTable{
@ -79,6 +81,7 @@ func newContactEmailTableImpl(schemaName, tableName, alias string) contactEmailT
Confirmed: ConfirmedColumn,
ContactID: ContactIDColumn,
IsSubscribed: IsSubscribedColumn,
ID: IDColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,

View file

@ -23,6 +23,7 @@ type contactPhoneTable struct {
E164 postgres.ColumnString
IsSubscribed postgres.ColumnBool
StopMessageID postgres.ColumnInteger
ID postgres.ColumnInteger
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
@ -70,9 +71,10 @@ func newContactPhoneTableImpl(schemaName, tableName, alias string) contactPhoneT
E164Column = postgres.StringColumn("e164")
IsSubscribedColumn = postgres.BoolColumn("is_subscribed")
StopMessageIDColumn = postgres.IntegerColumn("stop_message_id")
allColumns = postgres.ColumnList{CanSmsColumn, ConfirmedMessageIDColumn, ContactIDColumn, E164Column, IsSubscribedColumn, StopMessageIDColumn}
mutableColumns = postgres.ColumnList{CanSmsColumn, ConfirmedMessageIDColumn, ContactIDColumn, IsSubscribedColumn, StopMessageIDColumn}
defaultColumns = postgres.ColumnList{}
IDColumn = postgres.IntegerColumn("id")
allColumns = postgres.ColumnList{CanSmsColumn, ConfirmedMessageIDColumn, ContactIDColumn, E164Column, IsSubscribedColumn, StopMessageIDColumn, IDColumn}
mutableColumns = postgres.ColumnList{CanSmsColumn, ConfirmedMessageIDColumn, ContactIDColumn, E164Column, IsSubscribedColumn, StopMessageIDColumn}
defaultColumns = postgres.ColumnList{IDColumn}
)
return contactPhoneTable{
@ -85,6 +87,7 @@ func newContactPhoneTableImpl(schemaName, tableName, alias string) contactPhoneT
E164: E164Column,
IsSubscribed: IsSubscribedColumn,
StopMessageID: StopMessageIDColumn,
ID: IDColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,

View file

@ -0,0 +1,81 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/Gleipnir-Technology/jet/postgres"
)
var Email = newEmailTable("comms", "email", "")
type emailTable struct {
postgres.Table
// Columns
Address postgres.ColumnString
IsSubscribed postgres.ColumnBool
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
DefaultColumns postgres.ColumnList
}
type EmailTable struct {
emailTable
EXCLUDED emailTable
}
// AS creates new EmailTable with assigned alias
func (a EmailTable) AS(alias string) *EmailTable {
return newEmailTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new EmailTable with assigned schema name
func (a EmailTable) FromSchema(schemaName string) *EmailTable {
return newEmailTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new EmailTable with assigned table prefix
func (a EmailTable) WithPrefix(prefix string) *EmailTable {
return newEmailTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new EmailTable with assigned table suffix
func (a EmailTable) WithSuffix(suffix string) *EmailTable {
return newEmailTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newEmailTable(schemaName, tableName, alias string) *EmailTable {
return &EmailTable{
emailTable: newEmailTableImpl(schemaName, tableName, alias),
EXCLUDED: newEmailTableImpl("", "excluded", ""),
}
}
func newEmailTableImpl(schemaName, tableName, alias string) emailTable {
var (
AddressColumn = postgres.StringColumn("address")
IsSubscribedColumn = postgres.BoolColumn("is_subscribed")
allColumns = postgres.ColumnList{AddressColumn, IsSubscribedColumn}
mutableColumns = postgres.ColumnList{IsSubscribedColumn}
defaultColumns = postgres.ColumnList{}
)
return emailTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
Address: AddressColumn,
IsSubscribed: IsSubscribedColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
DefaultColumns: defaultColumns,
}
}

View file

@ -13,6 +13,7 @@ func UseSchema(schema string) {
Contact = Contact.FromSchema(schema)
ContactEmail = ContactEmail.FromSchema(schema)
ContactPhone = ContactPhone.FromSchema(schema)
Email = Email.FromSchema(schema)
EmailContact = EmailContact.FromSchema(schema)
EmailLog = EmailLog.FromSchema(schema)
EmailTemplate = EmailTemplate.FromSchema(schema)