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
|
|
@ -3,7 +3,6 @@ package public
|
|||
import (
|
||||
"context"
|
||||
|
||||
//"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/enum"
|
||||
"github.com/Gleipnir-Technology/jet/postgres"
|
||||
|
|
@ -11,28 +10,28 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
)
|
||||
|
||||
func CommunicationInsert(ctx context.Context, txn db.Tx, m model.Communication) (model.Communication, error) {
|
||||
func CommunicationInsert(ctx context.Context, txn db.Ex, m model.Communication) (model.Communication, error) {
|
||||
statement := table.Communication.INSERT(table.Communication.MutableColumns).
|
||||
MODEL(m).
|
||||
RETURNING(table.Communication.AllColumns)
|
||||
return db.ExecuteOneTx[model.Communication](ctx, txn, statement)
|
||||
}
|
||||
func CommunicationFromID(ctx context.Context, comm_id int64) (model.Communication, error) {
|
||||
func CommunicationFromID(ctx context.Context, txn db.Ex, comm_id int64) (model.Communication, error) {
|
||||
statement := table.Communication.SELECT(
|
||||
table.Communication.AllColumns,
|
||||
).FROM(table.Communication).
|
||||
WHERE(table.Communication.ID.EQ(postgres.Int(comm_id)))
|
||||
return db.ExecuteOne[model.Communication](ctx, statement)
|
||||
return db.ExecuteOneTx[model.Communication](ctx, txn, statement)
|
||||
}
|
||||
func CommunicationsFromOrganization(ctx context.Context, org_id int64) ([]model.Communication, error) {
|
||||
func CommunicationsFromOrganization(ctx context.Context, txn db.Ex, org_id int64) ([]model.Communication, error) {
|
||||
statement := table.Communication.SELECT(
|
||||
table.Communication.AllColumns,
|
||||
).FROM(table.Communication).
|
||||
WHERE(table.Communication.OrganizationID.EQ(postgres.Int(org_id))).
|
||||
ORDER_BY(table.Communication.Created.DESC())
|
||||
return db.ExecuteMany[model.Communication](ctx, statement)
|
||||
return db.ExecuteManyTx[model.Communication](ctx, txn, statement)
|
||||
}
|
||||
func CommunicationSetStatus(ctx context.Context, txn db.Tx, org_id int64, comm_id int64, status model.Communicationstatus) error {
|
||||
func CommunicationSetStatus(ctx context.Context, txn db.Ex, org_id int64, comm_id int64, status model.Communicationstatus) error {
|
||||
statement := table.Communication.UPDATE().
|
||||
SET(
|
||||
table.Communication.Status.SET(postgres.NewEnumValue(status.String())),
|
||||
|
|
|
|||
36
db/query/public/organization.go
Normal file
36
db/query/public/organization.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package public
|
||||
|
||||
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/public/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
)
|
||||
|
||||
func OrganizationInsert(ctx context.Context, txn db.Ex, m model.Organization) (model.Organization, error) {
|
||||
statement := table.Organization.INSERT(table.Organization.MutableColumns).
|
||||
MODEL(m).
|
||||
RETURNING(table.Organization.AllColumns)
|
||||
return db.ExecuteOneTx[model.Organization](ctx, txn, statement)
|
||||
}
|
||||
func OrganizationFromID(ctx context.Context, txn db.Ex, org_id int64) (model.Organization, error) {
|
||||
statement := table.Organization.SELECT(
|
||||
table.Organization.AllColumns,
|
||||
).FROM(table.Organization).
|
||||
WHERE(table.Organization.ID.EQ(postgres.Int(org_id)))
|
||||
return db.ExecuteOne[model.Organization](ctx, statement)
|
||||
}
|
||||
|
||||
/*
|
||||
func OrganizationSetStatus(ctx context.Context, txn db.Tx, org_id int64, org_id int64, status model.Organizationstatus) error {
|
||||
statement := table.Organization.UPDATE().
|
||||
SET(
|
||||
table.Organization.Status.SET(postgres.NewEnumValue(status.String())),
|
||||
).
|
||||
WHERE(table.Organization.OrganizationID.EQ(postgres.Int(org_id)).AND(
|
||||
table.Organization.ID.EQ(postgres.Int(org_id))))
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
*/
|
||||
18
db/query/public/report_text.go
Normal file
18
db/query/public/report_text.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package public
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/enum"
|
||||
//"github.com/Gleipnir-Technology/jet/postgres"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
)
|
||||
|
||||
func ReportTextInsert(ctx context.Context, txn db.Tx, m model.ReportText) (model.ReportText, error) {
|
||||
statement := table.ReportText.INSERT(table.ReportText.MutableColumns).
|
||||
MODEL(m).
|
||||
RETURNING(table.ReportText.AllColumns)
|
||||
return db.ExecuteOneTx[model.ReportText](ctx, txn, statement)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue