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:
Eli Ribble 2026-05-15 16:58:28 +00:00
parent 085935fa66
commit f1fe8b4d2b
No known key found for this signature in database
46 changed files with 1127 additions and 633 deletions

View file

@ -9,6 +9,7 @@ import (
//"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/jet/postgres"
"github.com/Gleipnir-Technology/nidus-sync/db"
tablecomms "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/table"
)
@ -36,12 +37,12 @@ func ReportsFromAddressID(ctx context.Context, txn db.Ex, org_id int64, address_
table.Report.OrganizationID.EQ(postgres.Int(org_id))))
return db.ExecuteManyTx[model.Report](ctx, txn, statement)
}
func ReportFromID(ctx context.Context, report_id int64) (model.Report, error) {
func ReportFromID(ctx context.Context, txn db.Ex, report_id int64) (model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,
).FROM(table.Report).
WHERE(table.Report.ID.EQ(postgres.Int(report_id)))
return db.ExecuteOne[model.Report](ctx, statement)
return db.ExecuteOneTx[model.Report](ctx, txn, statement)
}
func ReportsFromIDs(ctx context.Context, report_ids []int64) ([]model.Report, error) {
sql_ids := make([]postgres.Expression, len(report_ids))
@ -111,3 +112,17 @@ func ReportsUnreviewedForOrganization(ctx context.Context, txn db.Ex, org_id int
table.Report.OrganizationID.EQ(postgres.Int(org_id))))
return db.ExecuteManyTx[model.Report](ctx, txn, statement)
}
func ReportsFromReporterPhone(ctx context.Context, txn db.Ex, destination string) ([]model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,
).FROM(table.Report).
FROM(table.Report.INNER_JOIN(
tablecomms.TextJob,
tablecomms.TextJob.ReportID.EQ(table.Report.ID),
)).WHERE(
tablecomms.TextJob.ReportID.IS_NOT_NULL().AND(
tablecomms.TextJob.Destination.EQ(postgres.String(destination))).AND(
table.Report.Status.EQ(postgres.NewEnumValue(model.Reportstatustype_Reported.String()))),
)
return db.ExecuteManyTx[model.Report](ctx, txn, statement)
}