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.
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package background
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/Gleipnir-Technology/bob"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
query "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
|
"github.com/aarondl/opt/omit"
|
|
//"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func NewAudioTranscode(ctx context.Context, txn bob.Executor, audio_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeAudioTranscode, audio_id)
|
|
}
|
|
func NewComplianceMailer(ctx context.Context, txn db.Ex, compliance_report_request_id int32) error {
|
|
return newJob2(ctx, txn, model.Jobtype_ComplianceMailerSend, compliance_report_request_id)
|
|
}
|
|
func NewCSVCommit(ctx context.Context, txn bob.Executor, csv_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeCSVCommit, csv_id)
|
|
}
|
|
func NewCSVImport(ctx context.Context, txn bob.Executor, csv_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeCSVImport, csv_id)
|
|
}
|
|
func NewEmailSend(ctx context.Context, txn bob.Executor, email_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeEmailSend, email_id)
|
|
}
|
|
func NewLabelStudioAudioCreate(ctx context.Context, txn bob.Executor, note_audio_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeLabelStudioAudioCreate, note_audio_id)
|
|
}
|
|
func NewTextRespond(ctx context.Context, txn bob.Executor, text_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeTextRespond, text_id)
|
|
}
|
|
func NewTextSend(ctx context.Context, txn db.Ex, job_id int32) error {
|
|
return newJob2(ctx, txn, model.Jobtype_TextSend, job_id)
|
|
}
|
|
func newJob(ctx context.Context, txn bob.Executor, t enums.Jobtype, id int32) error {
|
|
_, err := models.Jobs.Insert(&models.JobSetter{
|
|
Created: omit.From(time.Now()),
|
|
// ID
|
|
Type: omit.From(t),
|
|
RowID: omit.From(id),
|
|
}).One(ctx, txn)
|
|
if err != nil {
|
|
return fmt.Errorf("insert job: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
func newJob2(ctx context.Context, txn db.Ex, t model.Jobtype, id int32) error {
|
|
job := model.Job{
|
|
Created: time.Now(),
|
|
Type: t,
|
|
RowID: id,
|
|
}
|
|
_, err := query.JobInsert(ctx, txn, job)
|
|
if err != nil {
|
|
return fmt.Errorf("insert job: %w", err)
|
|
}
|
|
return nil
|
|
}
|