From bf3dedf7cd46700e14b389542eca9c9a96566240 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 11 Nov 2025 22:53:48 +0000 Subject: [PATCH] Pull notifications from the database Previously we were storing them, just not showing them. --- arcgis.go | 7 +- dbinfo/history_polygonlocation.bob.go | 12 +- dbinfo/history_proposedtreatmentarea.bob.go | 12 +- dbinfo/history_treatment.bob.go | 12 +- dbinfo/notification.bob.go | 52 +-- factory/bobfactory_main.bob.go | 12 +- factory/history_polygonlocation.bob.go | 63 ++++ factory/history_proposedtreatmentarea.bob.go | 63 ++++ factory/history_treatment.bob.go | 63 ++++ factory/notification.bob.go | 317 +++++++++---------- factory/user_.bob.go | 2 +- html.go | 33 +- migrations/00010_add_notification.sql | 9 +- models/history_polygonlocation.bob.go | 218 +++++++------ models/history_proposedtreatmentarea.bob.go | 182 ++++++----- models/history_treatment.bob.go | 266 +++++++++------- models/notification.bob.go | 159 ++++++---- models/user_.bob.go | 9 +- 18 files changed, 905 insertions(+), 586 deletions(-) diff --git a/arcgis.go b/arcgis.go index f431e21d..2827d566 100644 --- a/arcgis.go +++ b/arcgis.go @@ -458,9 +458,10 @@ func markTokenFailed(ctx context.Context, oauth *models.OauthToken) { return } notificationSetter := models.NotificationSetter{ - Message: omitnull.From("Oauth token invalidated"), - Link: omitnull.From("/oauth/refresh"), - Type: omitnull.From(enums.NotificationtypeOauthTokenInvalidated), + Created: omit.From(time.Now()), + Message: omit.From("Oauth token invalidated"), + Link: omit.From("/oauth/refresh"), + Type: omit.From(enums.NotificationtypeOauthTokenInvalidated), } err = user.InsertUserNotifications(ctx, PGInstance.BobDB, ¬ificationSetter) if err != nil { diff --git a/dbinfo/history_polygonlocation.bob.go b/dbinfo/history_polygonlocation.bob.go index c11ca098..6ea7b3ba 100644 --- a/dbinfo/history_polygonlocation.bob.go +++ b/dbinfo/history_polygonlocation.bob.go @@ -429,6 +429,15 @@ var HistoryPolygonlocations = Table[ Generated: false, AutoIncr: false, }, + Created: column{ + Name: "created", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, Indexes: historyPolygonlocationIndexes{ HistoryPolygonlocationPkey: index{ @@ -521,11 +530,12 @@ type historyPolygonlocationColumns struct { GeometryX column GeometryY column Version column + Created column } func (c historyPolygonlocationColumns) AsSlice() []column { return []column{ - c.OrganizationID, c.Accessdesc, c.Acres, c.Active, c.Comments, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Filter, c.Globalid, c.Habitat, c.Hectares, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Symbology, c.ShapeArea, c.ShapeLength, c.Usetype, c.Waterorigin, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, + c.OrganizationID, c.Accessdesc, c.Acres, c.Active, c.Comments, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Filter, c.Globalid, c.Habitat, c.Hectares, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Symbology, c.ShapeArea, c.ShapeLength, c.Usetype, c.Waterorigin, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, c.Created, } } diff --git a/dbinfo/history_proposedtreatmentarea.bob.go b/dbinfo/history_proposedtreatmentarea.bob.go index 8d76ffd6..50c29ae6 100644 --- a/dbinfo/history_proposedtreatmentarea.bob.go +++ b/dbinfo/history_proposedtreatmentarea.bob.go @@ -348,6 +348,15 @@ var HistoryProposedtreatmentareas = Table[ Generated: false, AutoIncr: false, }, + Created: column{ + Name: "created", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, Indexes: historyProposedtreatmentareaIndexes{ HistoryProposedtreatmentareaPkey: index{ @@ -431,11 +440,12 @@ type historyProposedtreatmentareaColumns struct { GeometryX column GeometryY column Version column + Created column } func (c historyProposedtreatmentareaColumns) AsSlice() []column { return []column{ - c.OrganizationID, c.Acres, c.Comments, c.Completed, c.Completedby, c.Completeddate, c.Creationdate, c.Creator, c.Duedate, c.Exported, c.Editdate, c.Editor, c.Globalid, c.Hectares, c.Issprayroute, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Method, c.Name, c.Objectid, c.Priority, c.Reviewed, c.Reviewedby, c.Revieweddate, c.ShapeArea, c.ShapeLength, c.Targetapprate, c.Targetproduct, c.Targetspecies, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, + c.OrganizationID, c.Acres, c.Comments, c.Completed, c.Completedby, c.Completeddate, c.Creationdate, c.Creator, c.Duedate, c.Exported, c.Editdate, c.Editor, c.Globalid, c.Hectares, c.Issprayroute, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Method, c.Name, c.Objectid, c.Priority, c.Reviewed, c.Reviewedby, c.Revieweddate, c.ShapeArea, c.ShapeLength, c.Targetapprate, c.Targetproduct, c.Targetspecies, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, c.Created, } } diff --git a/dbinfo/history_treatment.bob.go b/dbinfo/history_treatment.bob.go index a4046457..3983d0f6 100644 --- a/dbinfo/history_treatment.bob.go +++ b/dbinfo/history_treatment.bob.go @@ -537,6 +537,15 @@ var HistoryTreatments = Table[ Generated: false, AutoIncr: false, }, + Created: column{ + Name: "created", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, Indexes: historyTreatmentIndexes{ HistoryTreatmentPkey: index{ @@ -641,11 +650,12 @@ type historyTreatmentColumns struct { GeometryY column TempSitecond column Version column + Created column } func (c historyTreatmentColumns) AsSlice() []column { return []column{ - c.OrganizationID, c.Activity, c.Areaunit, c.Avetemp, c.Barrierrouteid, c.Cbcount, c.Comments, c.Containercount, c.Creationdate, c.Creator, c.Enddatetime, c.Equiptype, c.Editdate, c.Editor, c.Fieldtech, c.Flowrate, c.Globalid, c.Habitat, c.InspID, c.Invloc, c.Linelocid, c.Locationname, c.Method, c.Objectid, c.Pointlocid, c.Polygonlocid, c.Product, c.Ptaid, c.Qty, c.Qtyunit, c.Raingauge, c.Recordstatus, c.Reviewed, c.Reviewedby, c.Revieweddate, c.Sdid, c.Sitecond, c.Srid, c.Startdatetime, c.Targetspecies, c.Tirecount, c.Treatacres, c.Treatarea, c.Treathectares, c.Treatmenthours, c.Treatmentlength, c.Treatmentlengthunits, c.Totalcostprodcut, c.Ulvrouteid, c.Warningoverride, c.Winddir, c.Windspeed, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.TempSitecond, c.Version, + c.OrganizationID, c.Activity, c.Areaunit, c.Avetemp, c.Barrierrouteid, c.Cbcount, c.Comments, c.Containercount, c.Creationdate, c.Creator, c.Enddatetime, c.Equiptype, c.Editdate, c.Editor, c.Fieldtech, c.Flowrate, c.Globalid, c.Habitat, c.InspID, c.Invloc, c.Linelocid, c.Locationname, c.Method, c.Objectid, c.Pointlocid, c.Polygonlocid, c.Product, c.Ptaid, c.Qty, c.Qtyunit, c.Raingauge, c.Recordstatus, c.Reviewed, c.Reviewedby, c.Revieweddate, c.Sdid, c.Sitecond, c.Srid, c.Startdatetime, c.Targetspecies, c.Tirecount, c.Treatacres, c.Treatarea, c.Treathectares, c.Treatmenthours, c.Treatmentlength, c.Treatmentlengthunits, c.Totalcostprodcut, c.Ulvrouteid, c.Warningoverride, c.Winddir, c.Windspeed, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.TempSitecond, c.Version, c.Created, } } diff --git a/dbinfo/notification.bob.go b/dbinfo/notification.bob.go index a601dfe3..741c9a34 100644 --- a/dbinfo/notification.bob.go +++ b/dbinfo/notification.bob.go @@ -24,39 +24,48 @@ var Notifications = Table[ Generated: false, AutoIncr: false, }, - UserID: column{ - Name: "user_id", - DBType: "integer", - Default: "NULL", + Created: column{ + Name: "created", + DBType: "timestamp without time zone", + Default: "", Comment: "", - Nullable: true, - Generated: false, - AutoIncr: false, - }, - Message: column{ - Name: "message", - DBType: "text", - Default: "NULL", - Comment: "", - Nullable: true, + Nullable: false, Generated: false, AutoIncr: false, }, Link: column{ Name: "link", DBType: "text", - Default: "NULL", + Default: "", Comment: "", - Nullable: true, + Nullable: false, + Generated: false, + AutoIncr: false, + }, + Message: column{ + Name: "message", + DBType: "text", + Default: "", + Comment: "", + Nullable: false, Generated: false, AutoIncr: false, }, Type: column{ Name: "type", DBType: "public.notificationtype", - Default: "NULL", + Default: "", Comment: "", - Nullable: true, + Nullable: false, + Generated: false, + AutoIncr: false, + }, + UserID: column{ + Name: "user_id", + DBType: "integer", + Default: "", + Comment: "", + Nullable: false, Generated: false, AutoIncr: false, }, @@ -102,15 +111,16 @@ var Notifications = Table[ type notificationColumns struct { ID column - UserID column - Message column + Created column Link column + Message column Type column + UserID column } func (c notificationColumns) AsSlice() []column { return []column{ - c.ID, c.UserID, c.Message, c.Link, c.Type, + c.ID, c.Created, c.Link, c.Message, c.Type, c.UserID, } } diff --git a/factory/bobfactory_main.bob.go b/factory/bobfactory_main.bob.go index c87d314e..39f24a00 100644 --- a/factory/bobfactory_main.bob.go +++ b/factory/bobfactory_main.bob.go @@ -2453,6 +2453,7 @@ func (f *Factory) FromExistingHistoryPolygonlocation(m *models.HistoryPolygonloc o.GeometryX = func() null.Val[float64] { return m.GeometryX } o.GeometryY = func() null.Val[float64] { return m.GeometryY } o.Version = func() int32 { return m.Version } + o.Created = func() null.Val[time.Time] { return m.Created } ctx := context.Background() if m.R.Organization != nil { @@ -2626,6 +2627,7 @@ func (f *Factory) FromExistingHistoryProposedtreatmentarea(m *models.HistoryProp o.GeometryX = func() null.Val[float64] { return m.GeometryX } o.GeometryY = func() null.Val[float64] { return m.GeometryY } o.Version = func() int32 { return m.Version } + o.Created = func() null.Val[time.Time] { return m.Created } ctx := context.Background() if m.R.Organization != nil { @@ -3438,6 +3440,7 @@ func (f *Factory) FromExistingHistoryTreatment(m *models.HistoryTreatment) *Hist o.GeometryY = func() null.Val[float64] { return m.GeometryY } o.TempSitecond = func() null.Val[string] { return m.TempSitecond } o.Version = func() int32 { return m.Version } + o.Created = func() null.Val[time.Time] { return m.Created } ctx := context.Background() if m.R.Organization != nil { @@ -3611,10 +3614,11 @@ func (f *Factory) FromExistingNotification(m *models.Notification) *Notification o := &NotificationTemplate{f: f, alreadyPersisted: true} o.ID = func() int32 { return m.ID } - o.UserID = func() null.Val[int32] { return m.UserID } - o.Message = func() null.Val[string] { return m.Message } - o.Link = func() null.Val[string] { return m.Link } - o.Type = func() null.Val[enums.Notificationtype] { return m.Type } + o.Created = func() time.Time { return m.Created } + o.Link = func() string { return m.Link } + o.Message = func() string { return m.Message } + o.Type = func() enums.Notificationtype { return m.Type } + o.UserID = func() int32 { return m.UserID } ctx := context.Background() if m.R.UserUser != nil { diff --git a/factory/history_polygonlocation.bob.go b/factory/history_polygonlocation.bob.go index 8f9bb05b..0b0abe57 100644 --- a/factory/history_polygonlocation.bob.go +++ b/factory/history_polygonlocation.bob.go @@ -6,6 +6,7 @@ package factory import ( "context" "testing" + "time" models "github.com/Gleipnir-Technology/nidus-sync/models" "github.com/aarondl/opt/null" @@ -82,6 +83,7 @@ type HistoryPolygonlocationTemplate struct { GeometryX func() null.Val[float64] GeometryY func() null.Val[float64] Version func() int32 + Created func() null.Val[time.Time] r historyPolygonlocationR f *Factory @@ -304,6 +306,10 @@ func (o HistoryPolygonlocationTemplate) BuildSetter() *models.HistoryPolygonloca val := o.Version() m.Version = omit.From(val) } + if o.Created != nil { + val := o.Created() + m.Created = omitnull.FromNull(val) + } return m } @@ -464,6 +470,9 @@ func (o HistoryPolygonlocationTemplate) Build() *models.HistoryPolygonlocation { if o.Version != nil { m.Version = o.Version() } + if o.Created != nil { + m.Created = o.Created() + } o.setModelRels(m) @@ -661,6 +670,7 @@ func (m historyPolygonlocationMods) RandomizeAllColumns(f *faker.Faker) HistoryP HistoryPolygonlocationMods.RandomGeometryX(f), HistoryPolygonlocationMods.RandomGeometryY(f), HistoryPolygonlocationMods.RandomVersion(f), + HistoryPolygonlocationMods.RandomCreated(f), } } @@ -3036,6 +3046,59 @@ func (m historyPolygonlocationMods) RandomVersion(f *faker.Faker) HistoryPolygon }) } +// Set the model columns to this value +func (m historyPolygonlocationMods) Created(val null.Val[time.Time]) HistoryPolygonlocationMod { + return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) { + o.Created = func() null.Val[time.Time] { return val } + }) +} + +// Set the Column from the function +func (m historyPolygonlocationMods) CreatedFunc(f func() null.Val[time.Time]) HistoryPolygonlocationMod { + return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) { + o.Created = f + }) +} + +// Clear any values for the column +func (m historyPolygonlocationMods) UnsetCreated() HistoryPolygonlocationMod { + return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) { + o.Created = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m historyPolygonlocationMods) RandomCreated(f *faker.Faker) HistoryPolygonlocationMod { + return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m historyPolygonlocationMods) RandomCreatedNotNull(f *faker.Faker) HistoryPolygonlocationMod { + return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + func (m historyPolygonlocationMods) WithParentsCascading() HistoryPolygonlocationMod { return HistoryPolygonlocationModFunc(func(ctx context.Context, o *HistoryPolygonlocationTemplate) { if isDone, _ := historyPolygonlocationWithParentsCascadingCtx.Value(ctx); isDone { diff --git a/factory/history_proposedtreatmentarea.bob.go b/factory/history_proposedtreatmentarea.bob.go index 09870cba..2f9f5693 100644 --- a/factory/history_proposedtreatmentarea.bob.go +++ b/factory/history_proposedtreatmentarea.bob.go @@ -6,6 +6,7 @@ package factory import ( "context" "testing" + "time" models "github.com/Gleipnir-Technology/nidus-sync/models" "github.com/aarondl/opt/null" @@ -73,6 +74,7 @@ type HistoryProposedtreatmentareaTemplate struct { GeometryX func() null.Val[float64] GeometryY func() null.Val[float64] Version func() int32 + Created func() null.Val[time.Time] r historyProposedtreatmentareaR f *Factory @@ -259,6 +261,10 @@ func (o HistoryProposedtreatmentareaTemplate) BuildSetter() *models.HistoryPropo val := o.Version() m.Version = omit.From(val) } + if o.Created != nil { + val := o.Created() + m.Created = omitnull.FromNull(val) + } return m } @@ -392,6 +398,9 @@ func (o HistoryProposedtreatmentareaTemplate) Build() *models.HistoryProposedtre if o.Version != nil { m.Version = o.Version() } + if o.Created != nil { + m.Created = o.Created() + } o.setModelRels(m) @@ -580,6 +589,7 @@ func (m historyProposedtreatmentareaMods) RandomizeAllColumns(f *faker.Faker) Hi HistoryProposedtreatmentareaMods.RandomGeometryX(f), HistoryProposedtreatmentareaMods.RandomGeometryY(f), HistoryProposedtreatmentareaMods.RandomVersion(f), + HistoryProposedtreatmentareaMods.RandomCreated(f), } } @@ -2478,6 +2488,59 @@ func (m historyProposedtreatmentareaMods) RandomVersion(f *faker.Faker) HistoryP }) } +// Set the model columns to this value +func (m historyProposedtreatmentareaMods) Created(val null.Val[time.Time]) HistoryProposedtreatmentareaMod { + return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) { + o.Created = func() null.Val[time.Time] { return val } + }) +} + +// Set the Column from the function +func (m historyProposedtreatmentareaMods) CreatedFunc(f func() null.Val[time.Time]) HistoryProposedtreatmentareaMod { + return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) { + o.Created = f + }) +} + +// Clear any values for the column +func (m historyProposedtreatmentareaMods) UnsetCreated() HistoryProposedtreatmentareaMod { + return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) { + o.Created = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m historyProposedtreatmentareaMods) RandomCreated(f *faker.Faker) HistoryProposedtreatmentareaMod { + return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m historyProposedtreatmentareaMods) RandomCreatedNotNull(f *faker.Faker) HistoryProposedtreatmentareaMod { + return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + func (m historyProposedtreatmentareaMods) WithParentsCascading() HistoryProposedtreatmentareaMod { return HistoryProposedtreatmentareaModFunc(func(ctx context.Context, o *HistoryProposedtreatmentareaTemplate) { if isDone, _ := historyProposedtreatmentareaWithParentsCascadingCtx.Value(ctx); isDone { diff --git a/factory/history_treatment.bob.go b/factory/history_treatment.bob.go index 7a3ed505..acf4d3c6 100644 --- a/factory/history_treatment.bob.go +++ b/factory/history_treatment.bob.go @@ -6,6 +6,7 @@ package factory import ( "context" "testing" + "time" models "github.com/Gleipnir-Technology/nidus-sync/models" "github.com/aarondl/opt/null" @@ -94,6 +95,7 @@ type HistoryTreatmentTemplate struct { GeometryY func() null.Val[float64] TempSitecond func() null.Val[string] Version func() int32 + Created func() null.Val[time.Time] r historyTreatmentR f *Factory @@ -364,6 +366,10 @@ func (o HistoryTreatmentTemplate) BuildSetter() *models.HistoryTreatmentSetter { val := o.Version() m.Version = omit.From(val) } + if o.Created != nil { + val := o.Created() + m.Created = omitnull.FromNull(val) + } return m } @@ -560,6 +566,9 @@ func (o HistoryTreatmentTemplate) Build() *models.HistoryTreatment { if o.Version != nil { m.Version = o.Version() } + if o.Created != nil { + m.Created = o.Created() + } o.setModelRels(m) @@ -769,6 +778,7 @@ func (m historyTreatmentMods) RandomizeAllColumns(f *faker.Faker) HistoryTreatme HistoryTreatmentMods.RandomGeometryY(f), HistoryTreatmentMods.RandomTempSitecond(f), HistoryTreatmentMods.RandomVersion(f), + HistoryTreatmentMods.RandomCreated(f), } } @@ -3780,6 +3790,59 @@ func (m historyTreatmentMods) RandomVersion(f *faker.Faker) HistoryTreatmentMod }) } +// Set the model columns to this value +func (m historyTreatmentMods) Created(val null.Val[time.Time]) HistoryTreatmentMod { + return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) { + o.Created = func() null.Val[time.Time] { return val } + }) +} + +// Set the Column from the function +func (m historyTreatmentMods) CreatedFunc(f func() null.Val[time.Time]) HistoryTreatmentMod { + return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) { + o.Created = f + }) +} + +// Clear any values for the column +func (m historyTreatmentMods) UnsetCreated() HistoryTreatmentMod { + return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) { + o.Created = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m historyTreatmentMods) RandomCreated(f *faker.Faker) HistoryTreatmentMod { + return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m historyTreatmentMods) RandomCreatedNotNull(f *faker.Faker) HistoryTreatmentMod { + return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) { + o.Created = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + func (m historyTreatmentMods) WithParentsCascading() HistoryTreatmentMod { return HistoryTreatmentModFunc(func(ctx context.Context, o *HistoryTreatmentTemplate) { if isDone, _ := historyTreatmentWithParentsCascadingCtx.Value(ctx); isDone { diff --git a/factory/notification.bob.go b/factory/notification.bob.go index 2224ceb9..c3c53070 100644 --- a/factory/notification.bob.go +++ b/factory/notification.bob.go @@ -6,12 +6,11 @@ package factory import ( "context" "testing" + "time" enums "github.com/Gleipnir-Technology/nidus-sync/enums" models "github.com/Gleipnir-Technology/nidus-sync/models" - "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" "github.com/jaswdr/faker/v2" "github.com/stephenafamo/bob" ) @@ -38,10 +37,11 @@ func (mods NotificationModSlice) Apply(ctx context.Context, n *NotificationTempl // all columns are optional and should be set by mods type NotificationTemplate struct { ID func() int32 - UserID func() null.Val[int32] - Message func() null.Val[string] - Link func() null.Val[string] - Type func() null.Val[enums.Notificationtype] + Created func() time.Time + Link func() string + Message func() string + Type func() enums.Notificationtype + UserID func() int32 r notificationR f *Factory @@ -70,7 +70,7 @@ func (t NotificationTemplate) setModelRels(o *models.Notification) { if t.r.UserUser != nil { rel := t.r.UserUser.o.Build() rel.R.UserNotifications = append(rel.R.UserNotifications, o) - o.UserID = null.From(rel.ID) // h2 + o.UserID = rel.ID // h2 o.R.UserUser = rel } } @@ -84,21 +84,25 @@ func (o NotificationTemplate) BuildSetter() *models.NotificationSetter { val := o.ID() m.ID = omit.From(val) } - if o.UserID != nil { - val := o.UserID() - m.UserID = omitnull.FromNull(val) - } - if o.Message != nil { - val := o.Message() - m.Message = omitnull.FromNull(val) + if o.Created != nil { + val := o.Created() + m.Created = omit.From(val) } if o.Link != nil { val := o.Link() - m.Link = omitnull.FromNull(val) + m.Link = omit.From(val) + } + if o.Message != nil { + val := o.Message() + m.Message = omit.From(val) } if o.Type != nil { val := o.Type() - m.Type = omitnull.FromNull(val) + m.Type = omit.From(val) + } + if o.UserID != nil { + val := o.UserID() + m.UserID = omit.From(val) } return m @@ -125,18 +129,21 @@ func (o NotificationTemplate) Build() *models.Notification { if o.ID != nil { m.ID = o.ID() } - if o.UserID != nil { - m.UserID = o.UserID() - } - if o.Message != nil { - m.Message = o.Message() + if o.Created != nil { + m.Created = o.Created() } if o.Link != nil { m.Link = o.Link() } + if o.Message != nil { + m.Message = o.Message() + } if o.Type != nil { m.Type = o.Type() } + if o.UserID != nil { + m.UserID = o.UserID() + } o.setModelRels(m) @@ -157,6 +164,26 @@ func (o NotificationTemplate) BuildMany(number int) models.NotificationSlice { } func ensureCreatableNotification(m *models.NotificationSetter) { + if !(m.Created.IsValue()) { + val := random_time_Time(nil) + m.Created = omit.From(val) + } + if !(m.Link.IsValue()) { + val := random_string(nil) + m.Link = omit.From(val) + } + if !(m.Message.IsValue()) { + val := random_string(nil) + m.Message = omit.From(val) + } + if !(m.Type.IsValue()) { + val := random_enums_Notificationtype(nil) + m.Type = omit.From(val) + } + if !(m.UserID.IsValue()) { + val := random_int32(nil) + m.UserID = omit.From(val) + } } // insertOptRels creates and inserts any optional the relationships on *models.Notification @@ -165,25 +192,6 @@ func ensureCreatableNotification(m *models.NotificationSetter) { func (o *NotificationTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Notification) error { var err error - isUserUserDone, _ := notificationRelUserUserCtx.Value(ctx) - if !isUserUserDone && o.r.UserUser != nil { - ctx = notificationRelUserUserCtx.WithValue(ctx, true) - if o.r.UserUser.o.alreadyPersisted { - m.R.UserUser = o.r.UserUser.o.Build() - } else { - var rel0 *models.User - rel0, err = o.r.UserUser.o.Create(ctx, exec) - if err != nil { - return err - } - err = m.AttachUserUser(ctx, exec, rel0) - if err != nil { - return err - } - } - - } - return err } @@ -194,11 +202,30 @@ func (o *NotificationTemplate) Create(ctx context.Context, exec bob.Executor) (* opt := o.BuildSetter() ensureCreatableNotification(opt) + if o.r.UserUser == nil { + NotificationMods.WithNewUserUser().Apply(ctx, o) + } + + var rel0 *models.User + + if o.r.UserUser.o.alreadyPersisted { + rel0 = o.r.UserUser.o.Build() + } else { + rel0, err = o.r.UserUser.o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + opt.UserID = omit.From(rel0.ID) + m, err := models.Notifications.Insert(opt).One(ctx, exec) if err != nil { return nil, err } + m.R.UserUser = rel0 + if err := o.insertOptRels(ctx, exec, m); err != nil { return nil, err } @@ -277,10 +304,11 @@ type notificationMods struct{} func (m notificationMods) RandomizeAllColumns(f *faker.Faker) NotificationMod { return NotificationModSlice{ NotificationMods.RandomID(f), - NotificationMods.RandomUserID(f), - NotificationMods.RandomMessage(f), + NotificationMods.RandomCreated(f), NotificationMods.RandomLink(f), + NotificationMods.RandomMessage(f), NotificationMods.RandomType(f), + NotificationMods.RandomUserID(f), } } @@ -316,120 +344,45 @@ func (m notificationMods) RandomID(f *faker.Faker) NotificationMod { } // Set the model columns to this value -func (m notificationMods) UserID(val null.Val[int32]) NotificationMod { +func (m notificationMods) Created(val time.Time) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.UserID = func() null.Val[int32] { return val } + o.Created = func() time.Time { return val } }) } // Set the Column from the function -func (m notificationMods) UserIDFunc(f func() null.Val[int32]) NotificationMod { +func (m notificationMods) CreatedFunc(f func() time.Time) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.UserID = f + o.Created = f }) } // Clear any values for the column -func (m notificationMods) UnsetUserID() NotificationMod { +func (m notificationMods) UnsetCreated() NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.UserID = nil + o.Created = nil }) } // Generates a random value for the column using the given faker // if faker is nil, a default faker is used -// The generated value is sometimes null -func (m notificationMods) RandomUserID(f *faker.Faker) NotificationMod { +func (m notificationMods) RandomCreated(f *faker.Faker) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.UserID = func() null.Val[int32] { - if f == nil { - f = &defaultFaker - } - - val := random_int32(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m notificationMods) RandomUserIDNotNull(f *faker.Faker) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.UserID = func() null.Val[int32] { - if f == nil { - f = &defaultFaker - } - - val := random_int32(f) - return null.From(val) + o.Created = func() time.Time { + return random_time_Time(f) } }) } // Set the model columns to this value -func (m notificationMods) Message(val null.Val[string]) NotificationMod { +func (m notificationMods) Link(val string) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Message = func() null.Val[string] { return val } + o.Link = func() string { return val } }) } // Set the Column from the function -func (m notificationMods) MessageFunc(f func() null.Val[string]) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Message = f - }) -} - -// Clear any values for the column -func (m notificationMods) UnsetMessage() NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Message = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is sometimes null -func (m notificationMods) RandomMessage(f *faker.Faker) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Message = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m notificationMods) RandomMessageNotNull(f *faker.Faker) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Message = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Set the model columns to this value -func (m notificationMods) Link(val null.Val[string]) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Link = func() null.Val[string] { return val } - }) -} - -// Set the Column from the function -func (m notificationMods) LinkFunc(f func() null.Val[string]) NotificationMod { +func (m notificationMods) LinkFunc(f func() string) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { o.Link = f }) @@ -444,45 +397,54 @@ func (m notificationMods) UnsetLink() NotificationMod { // Generates a random value for the column using the given faker // if faker is nil, a default faker is used -// The generated value is sometimes null func (m notificationMods) RandomLink(f *faker.Faker) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Link = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m notificationMods) RandomLinkNotNull(f *faker.Faker) NotificationMod { - return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Link = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) + o.Link = func() string { + return random_string(f) } }) } // Set the model columns to this value -func (m notificationMods) Type(val null.Val[enums.Notificationtype]) NotificationMod { +func (m notificationMods) Message(val string) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Type = func() null.Val[enums.Notificationtype] { return val } + o.Message = func() string { return val } }) } // Set the Column from the function -func (m notificationMods) TypeFunc(f func() null.Val[enums.Notificationtype]) NotificationMod { +func (m notificationMods) MessageFunc(f func() string) NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.Message = f + }) +} + +// Clear any values for the column +func (m notificationMods) UnsetMessage() NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.Message = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m notificationMods) RandomMessage(f *faker.Faker) NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.Message = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m notificationMods) Type(val enums.Notificationtype) NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.Type = func() enums.Notificationtype { return val } + }) +} + +// Set the Column from the function +func (m notificationMods) TypeFunc(f func() enums.Notificationtype) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { o.Type = f }) @@ -497,32 +459,41 @@ func (m notificationMods) UnsetType() NotificationMod { // Generates a random value for the column using the given faker // if faker is nil, a default faker is used -// The generated value is sometimes null func (m notificationMods) RandomType(f *faker.Faker) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Type = func() null.Val[enums.Notificationtype] { - if f == nil { - f = &defaultFaker - } - - val := random_enums_Notificationtype(f) - return null.From(val) + o.Type = func() enums.Notificationtype { + return random_enums_Notificationtype(f) } }) } +// Set the model columns to this value +func (m notificationMods) UserID(val int32) NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.UserID = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m notificationMods) UserIDFunc(f func() int32) NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.UserID = f + }) +} + +// Clear any values for the column +func (m notificationMods) UnsetUserID() NotificationMod { + return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { + o.UserID = nil + }) +} + // Generates a random value for the column using the given faker // if faker is nil, a default faker is used -// The generated value is never null -func (m notificationMods) RandomTypeNotNull(f *faker.Faker) NotificationMod { +func (m notificationMods) RandomUserID(f *faker.Faker) NotificationMod { return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) { - o.Type = func() null.Val[enums.Notificationtype] { - if f == nil { - f = &defaultFaker - } - - val := random_enums_Notificationtype(f) - return null.From(val) + o.UserID = func() int32 { + return random_int32(f) } }) } diff --git a/factory/user_.bob.go b/factory/user_.bob.go index be02c99d..9e3d145f 100644 --- a/factory/user_.bob.go +++ b/factory/user_.bob.go @@ -90,7 +90,7 @@ func (t UserTemplate) setModelRels(o *models.User) { for _, r := range t.r.UserNotifications { related := r.o.BuildMany(r.number) for _, rel := range related { - rel.UserID = null.From(o.ID) // h2 + rel.UserID = o.ID // h2 rel.R.UserUser = o } rel = append(rel, related...) diff --git a/html.go b/html.go index d981224e..2605fb28 100644 --- a/html.go +++ b/html.go @@ -14,6 +14,7 @@ import ( "strings" "time" + enums "github.com/Gleipnir-Technology/nidus-sync/enums" "github.com/Gleipnir-Technology/nidus-sync/models" "github.com/aarondl/opt/null" //"github.com/riverqueue/river/rivershared/util/slogutil" @@ -169,7 +170,7 @@ func htmlDashboard(ctx context.Context, w http.ResponseWriter, user *models.User Status: "Completed", }) } - notifications, err := notificationsForUser(user) + notifications, err := notificationsForUser(ctx, user) if err != nil { respondError(w, "Failed to get notifications", err, http.StatusInternalServerError) return @@ -427,15 +428,31 @@ type Notification struct { Type string } -func notificationsForUser(u *models.User) ([]Notification, error) { - return []Notification{Notification{ - Link: "/foo/bar", - Message: "hey, your oauth is broken.", - Time: time.Now(), - Type: "alert", - }}, nil +func notificationsForUser(ctx context.Context, u *models.User) ([]Notification, error) { + results := make([]Notification, 0) + notifications, err := u.UserNotifications().All(ctx, PGInstance.BobDB) + if err != nil { + return results, fmt.Errorf("Failed to get notifications: %v", err) + } + for _, n := range notifications { + results = append(results, Notification{ + Link: n.Link, + Message: n.Message, + Time: n.Created, + Type: notificationTypeName(n.Type), + }) + } + return results, nil } +func notificationTypeName(t enums.Notificationtype) string { + switch t { + case enums.NotificationtypeOauthTokenInvalidated: + return "alert" + default: + return "unknown-type" + } +} func renderOrError(w http.ResponseWriter, template BuiltTemplate, context interface{}) { buf := &bytes.Buffer{} err := template.ExecuteTemplate(buf, context) diff --git a/migrations/00010_add_notification.sql b/migrations/00010_add_notification.sql index e8cb4d1b..3ad0ee72 100644 --- a/migrations/00010_add_notification.sql +++ b/migrations/00010_add_notification.sql @@ -4,10 +4,11 @@ CREATE TYPE NotificationType AS ENUM ( CREATE TABLE notification ( id SERIAL PRIMARY KEY, - user_id INTEGER REFERENCES user_(id), - message TEXT, - link TEXT, - type NotificationType); + created TIMESTAMP WITHOUT TIME ZONE NOT NULL, + link TEXT NOT NULL, + message TEXT NOT NULL, + type NotificationType NOT NULL, + user_id INTEGER REFERENCES user_(id) NOT NULL); diff --git a/models/history_polygonlocation.bob.go b/models/history_polygonlocation.bob.go index f4327170..522ec498 100644 --- a/models/history_polygonlocation.bob.go +++ b/models/history_polygonlocation.bob.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "time" "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" @@ -25,52 +26,53 @@ import ( // HistoryPolygonlocation is an object representing the database table. type HistoryPolygonlocation struct { - OrganizationID int32 `db:"organization_id" ` - Accessdesc null.Val[string] `db:"accessdesc" ` - Acres null.Val[float64] `db:"acres" ` - Active null.Val[int16] `db:"active" ` - Comments null.Val[string] `db:"comments" ` - Creationdate null.Val[int64] `db:"creationdate" ` - Creator null.Val[string] `db:"creator" ` - Description null.Val[string] `db:"description" ` - Externalid null.Val[string] `db:"externalid" ` - Editdate null.Val[int64] `db:"editdate" ` - Editor null.Val[string] `db:"editor" ` - Filter null.Val[string] `db:"filter" ` - Globalid null.Val[string] `db:"globalid" ` - Habitat null.Val[string] `db:"habitat" ` - Hectares null.Val[float64] `db:"hectares" ` - Jurisdiction null.Val[string] `db:"jurisdiction" ` - Larvinspectinterval null.Val[int16] `db:"larvinspectinterval" ` - Lastinspectactiontaken null.Val[string] `db:"lastinspectactiontaken" ` - Lastinspectactivity null.Val[string] `db:"lastinspectactivity" ` - Lastinspectavglarvae null.Val[float64] `db:"lastinspectavglarvae" ` - Lastinspectavgpupae null.Val[float64] `db:"lastinspectavgpupae" ` - Lastinspectbreeding null.Val[string] `db:"lastinspectbreeding" ` - Lastinspectconditions null.Val[string] `db:"lastinspectconditions" ` - Lastinspectdate null.Val[int64] `db:"lastinspectdate" ` - Lastinspectfieldspecies null.Val[string] `db:"lastinspectfieldspecies" ` - Lastinspectlstages null.Val[string] `db:"lastinspectlstages" ` - Lasttreatactivity null.Val[string] `db:"lasttreatactivity" ` - Lasttreatdate null.Val[int64] `db:"lasttreatdate" ` - Lasttreatproduct null.Val[string] `db:"lasttreatproduct" ` - Lasttreatqty null.Val[float64] `db:"lasttreatqty" ` - Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" ` - Locationnumber null.Val[int64] `db:"locationnumber" ` - Name null.Val[string] `db:"name" ` - Nextactiondatescheduled null.Val[int64] `db:"nextactiondatescheduled" ` - Objectid int32 `db:"objectid,pk" ` - Priority null.Val[string] `db:"priority" ` - Symbology null.Val[string] `db:"symbology" ` - ShapeArea null.Val[float64] `db:"shape__area" ` - ShapeLength null.Val[float64] `db:"shape__length" ` - Usetype null.Val[string] `db:"usetype" ` - Waterorigin null.Val[string] `db:"waterorigin" ` - Zone null.Val[string] `db:"zone" ` - Zone2 null.Val[string] `db:"zone2" ` - GeometryX null.Val[float64] `db:"geometry_x" ` - GeometryY null.Val[float64] `db:"geometry_y" ` - Version int32 `db:"version,pk" ` + OrganizationID int32 `db:"organization_id" ` + Accessdesc null.Val[string] `db:"accessdesc" ` + Acres null.Val[float64] `db:"acres" ` + Active null.Val[int16] `db:"active" ` + Comments null.Val[string] `db:"comments" ` + Creationdate null.Val[int64] `db:"creationdate" ` + Creator null.Val[string] `db:"creator" ` + Description null.Val[string] `db:"description" ` + Externalid null.Val[string] `db:"externalid" ` + Editdate null.Val[int64] `db:"editdate" ` + Editor null.Val[string] `db:"editor" ` + Filter null.Val[string] `db:"filter" ` + Globalid null.Val[string] `db:"globalid" ` + Habitat null.Val[string] `db:"habitat" ` + Hectares null.Val[float64] `db:"hectares" ` + Jurisdiction null.Val[string] `db:"jurisdiction" ` + Larvinspectinterval null.Val[int16] `db:"larvinspectinterval" ` + Lastinspectactiontaken null.Val[string] `db:"lastinspectactiontaken" ` + Lastinspectactivity null.Val[string] `db:"lastinspectactivity" ` + Lastinspectavglarvae null.Val[float64] `db:"lastinspectavglarvae" ` + Lastinspectavgpupae null.Val[float64] `db:"lastinspectavgpupae" ` + Lastinspectbreeding null.Val[string] `db:"lastinspectbreeding" ` + Lastinspectconditions null.Val[string] `db:"lastinspectconditions" ` + Lastinspectdate null.Val[int64] `db:"lastinspectdate" ` + Lastinspectfieldspecies null.Val[string] `db:"lastinspectfieldspecies" ` + Lastinspectlstages null.Val[string] `db:"lastinspectlstages" ` + Lasttreatactivity null.Val[string] `db:"lasttreatactivity" ` + Lasttreatdate null.Val[int64] `db:"lasttreatdate" ` + Lasttreatproduct null.Val[string] `db:"lasttreatproduct" ` + Lasttreatqty null.Val[float64] `db:"lasttreatqty" ` + Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" ` + Locationnumber null.Val[int64] `db:"locationnumber" ` + Name null.Val[string] `db:"name" ` + Nextactiondatescheduled null.Val[int64] `db:"nextactiondatescheduled" ` + Objectid int32 `db:"objectid,pk" ` + Priority null.Val[string] `db:"priority" ` + Symbology null.Val[string] `db:"symbology" ` + ShapeArea null.Val[float64] `db:"shape__area" ` + ShapeLength null.Val[float64] `db:"shape__length" ` + Usetype null.Val[string] `db:"usetype" ` + Waterorigin null.Val[string] `db:"waterorigin" ` + Zone null.Val[string] `db:"zone" ` + Zone2 null.Val[string] `db:"zone2" ` + GeometryX null.Val[float64] `db:"geometry_x" ` + GeometryY null.Val[float64] `db:"geometry_y" ` + Version int32 `db:"version,pk" ` + Created null.Val[time.Time] `db:"created" ` R historyPolygonlocationR `db:"-" ` } @@ -93,7 +95,7 @@ type historyPolygonlocationR struct { func buildHistoryPolygonlocationColumns(alias string) historyPolygonlocationColumns { return historyPolygonlocationColumns{ ColumnsExpr: expr.NewColumnsExpr( - "organization_id", "accessdesc", "acres", "active", "comments", "creationdate", "creator", "description", "externalid", "editdate", "editor", "filter", "globalid", "habitat", "hectares", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "symbology", "shape__area", "shape__length", "usetype", "waterorigin", "zone", "zone2", "geometry_x", "geometry_y", "version", + "organization_id", "accessdesc", "acres", "active", "comments", "creationdate", "creator", "description", "externalid", "editdate", "editor", "filter", "globalid", "habitat", "hectares", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "symbology", "shape__area", "shape__length", "usetype", "waterorigin", "zone", "zone2", "geometry_x", "geometry_y", "version", "created", ).WithParent("history_polygonlocation"), tableAlias: alias, OrganizationID: psql.Quote(alias, "organization_id"), @@ -142,6 +144,7 @@ func buildHistoryPolygonlocationColumns(alias string) historyPolygonlocationColu GeometryX: psql.Quote(alias, "geometry_x"), GeometryY: psql.Quote(alias, "geometry_y"), Version: psql.Quote(alias, "version"), + Created: psql.Quote(alias, "created"), } } @@ -194,6 +197,7 @@ type historyPolygonlocationColumns struct { GeometryX psql.Expression GeometryY psql.Expression Version psql.Expression + Created psql.Expression } func (c historyPolygonlocationColumns) Alias() string { @@ -208,56 +212,57 @@ func (historyPolygonlocationColumns) AliasedAs(alias string) historyPolygonlocat // All values are optional, and do not have to be set // Generated columns are not included type HistoryPolygonlocationSetter struct { - OrganizationID omit.Val[int32] `db:"organization_id" ` - Accessdesc omitnull.Val[string] `db:"accessdesc" ` - Acres omitnull.Val[float64] `db:"acres" ` - Active omitnull.Val[int16] `db:"active" ` - Comments omitnull.Val[string] `db:"comments" ` - Creationdate omitnull.Val[int64] `db:"creationdate" ` - Creator omitnull.Val[string] `db:"creator" ` - Description omitnull.Val[string] `db:"description" ` - Externalid omitnull.Val[string] `db:"externalid" ` - Editdate omitnull.Val[int64] `db:"editdate" ` - Editor omitnull.Val[string] `db:"editor" ` - Filter omitnull.Val[string] `db:"filter" ` - Globalid omitnull.Val[string] `db:"globalid" ` - Habitat omitnull.Val[string] `db:"habitat" ` - Hectares omitnull.Val[float64] `db:"hectares" ` - Jurisdiction omitnull.Val[string] `db:"jurisdiction" ` - Larvinspectinterval omitnull.Val[int16] `db:"larvinspectinterval" ` - Lastinspectactiontaken omitnull.Val[string] `db:"lastinspectactiontaken" ` - Lastinspectactivity omitnull.Val[string] `db:"lastinspectactivity" ` - Lastinspectavglarvae omitnull.Val[float64] `db:"lastinspectavglarvae" ` - Lastinspectavgpupae omitnull.Val[float64] `db:"lastinspectavgpupae" ` - Lastinspectbreeding omitnull.Val[string] `db:"lastinspectbreeding" ` - Lastinspectconditions omitnull.Val[string] `db:"lastinspectconditions" ` - Lastinspectdate omitnull.Val[int64] `db:"lastinspectdate" ` - Lastinspectfieldspecies omitnull.Val[string] `db:"lastinspectfieldspecies" ` - Lastinspectlstages omitnull.Val[string] `db:"lastinspectlstages" ` - Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" ` - Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" ` - Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" ` - Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" ` - Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" ` - Locationnumber omitnull.Val[int64] `db:"locationnumber" ` - Name omitnull.Val[string] `db:"name" ` - Nextactiondatescheduled omitnull.Val[int64] `db:"nextactiondatescheduled" ` - Objectid omit.Val[int32] `db:"objectid,pk" ` - Priority omitnull.Val[string] `db:"priority" ` - Symbology omitnull.Val[string] `db:"symbology" ` - ShapeArea omitnull.Val[float64] `db:"shape__area" ` - ShapeLength omitnull.Val[float64] `db:"shape__length" ` - Usetype omitnull.Val[string] `db:"usetype" ` - Waterorigin omitnull.Val[string] `db:"waterorigin" ` - Zone omitnull.Val[string] `db:"zone" ` - Zone2 omitnull.Val[string] `db:"zone2" ` - GeometryX omitnull.Val[float64] `db:"geometry_x" ` - GeometryY omitnull.Val[float64] `db:"geometry_y" ` - Version omit.Val[int32] `db:"version,pk" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + Accessdesc omitnull.Val[string] `db:"accessdesc" ` + Acres omitnull.Val[float64] `db:"acres" ` + Active omitnull.Val[int16] `db:"active" ` + Comments omitnull.Val[string] `db:"comments" ` + Creationdate omitnull.Val[int64] `db:"creationdate" ` + Creator omitnull.Val[string] `db:"creator" ` + Description omitnull.Val[string] `db:"description" ` + Externalid omitnull.Val[string] `db:"externalid" ` + Editdate omitnull.Val[int64] `db:"editdate" ` + Editor omitnull.Val[string] `db:"editor" ` + Filter omitnull.Val[string] `db:"filter" ` + Globalid omitnull.Val[string] `db:"globalid" ` + Habitat omitnull.Val[string] `db:"habitat" ` + Hectares omitnull.Val[float64] `db:"hectares" ` + Jurisdiction omitnull.Val[string] `db:"jurisdiction" ` + Larvinspectinterval omitnull.Val[int16] `db:"larvinspectinterval" ` + Lastinspectactiontaken omitnull.Val[string] `db:"lastinspectactiontaken" ` + Lastinspectactivity omitnull.Val[string] `db:"lastinspectactivity" ` + Lastinspectavglarvae omitnull.Val[float64] `db:"lastinspectavglarvae" ` + Lastinspectavgpupae omitnull.Val[float64] `db:"lastinspectavgpupae" ` + Lastinspectbreeding omitnull.Val[string] `db:"lastinspectbreeding" ` + Lastinspectconditions omitnull.Val[string] `db:"lastinspectconditions" ` + Lastinspectdate omitnull.Val[int64] `db:"lastinspectdate" ` + Lastinspectfieldspecies omitnull.Val[string] `db:"lastinspectfieldspecies" ` + Lastinspectlstages omitnull.Val[string] `db:"lastinspectlstages" ` + Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" ` + Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" ` + Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" ` + Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" ` + Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" ` + Locationnumber omitnull.Val[int64] `db:"locationnumber" ` + Name omitnull.Val[string] `db:"name" ` + Nextactiondatescheduled omitnull.Val[int64] `db:"nextactiondatescheduled" ` + Objectid omit.Val[int32] `db:"objectid,pk" ` + Priority omitnull.Val[string] `db:"priority" ` + Symbology omitnull.Val[string] `db:"symbology" ` + ShapeArea omitnull.Val[float64] `db:"shape__area" ` + ShapeLength omitnull.Val[float64] `db:"shape__length" ` + Usetype omitnull.Val[string] `db:"usetype" ` + Waterorigin omitnull.Val[string] `db:"waterorigin" ` + Zone omitnull.Val[string] `db:"zone" ` + Zone2 omitnull.Val[string] `db:"zone2" ` + GeometryX omitnull.Val[float64] `db:"geometry_x" ` + GeometryY omitnull.Val[float64] `db:"geometry_y" ` + Version omit.Val[int32] `db:"version,pk" ` + Created omitnull.Val[time.Time] `db:"created" ` } func (s HistoryPolygonlocationSetter) SetColumns() []string { - vals := make([]string, 0, 46) + vals := make([]string, 0, 47) if s.OrganizationID.IsValue() { vals = append(vals, "organization_id") } @@ -396,6 +401,9 @@ func (s HistoryPolygonlocationSetter) SetColumns() []string { if s.Version.IsValue() { vals = append(vals, "version") } + if !s.Created.IsUnset() { + vals = append(vals, "created") + } return vals } @@ -538,6 +546,9 @@ func (s HistoryPolygonlocationSetter) Overwrite(t *HistoryPolygonlocation) { if s.Version.IsValue() { t.Version = s.Version.MustGet() } + if !s.Created.IsUnset() { + t.Created = s.Created.MustGetNull() + } } func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) { @@ -546,7 +557,7 @@ func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) { }) q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 46) + vals := make([]bob.Expression, 47) if s.OrganizationID.IsValue() { vals[0] = psql.Arg(s.OrganizationID.MustGet()) } else { @@ -823,6 +834,12 @@ func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) { vals[45] = psql.Raw("DEFAULT") } + if !s.Created.IsUnset() { + vals[46] = psql.Arg(s.Created.MustGetNull()) + } else { + vals[46] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -832,7 +849,7 @@ func (s HistoryPolygonlocationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] } func (s HistoryPolygonlocationSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 46) + exprs := make([]bob.Expression, 0, 47) if s.OrganizationID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -1156,6 +1173,13 @@ func (s HistoryPolygonlocationSetter) Expressions(prefix ...string) []bob.Expres }}) } + if !s.Created.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + return exprs } @@ -1511,6 +1535,7 @@ type historyPolygonlocationWhere[Q psql.Filterable] struct { GeometryX psql.WhereNullMod[Q, float64] GeometryY psql.WhereNullMod[Q, float64] Version psql.WhereMod[Q, int32] + Created psql.WhereNullMod[Q, time.Time] } func (historyPolygonlocationWhere[Q]) AliasedAs(alias string) historyPolygonlocationWhere[Q] { @@ -1565,6 +1590,7 @@ func buildHistoryPolygonlocationWhere[Q psql.Filterable](cols historyPolygonloca GeometryX: psql.WhereNull[Q, float64](cols.GeometryX), GeometryY: psql.WhereNull[Q, float64](cols.GeometryY), Version: psql.Where[Q, int32](cols.Version), + Created: psql.WhereNull[Q, time.Time](cols.Created), } } diff --git a/models/history_proposedtreatmentarea.bob.go b/models/history_proposedtreatmentarea.bob.go index a9f00da1..97ff3010 100644 --- a/models/history_proposedtreatmentarea.bob.go +++ b/models/history_proposedtreatmentarea.bob.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "time" "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" @@ -25,43 +26,44 @@ import ( // HistoryProposedtreatmentarea is an object representing the database table. type HistoryProposedtreatmentarea struct { - OrganizationID int32 `db:"organization_id" ` - Acres null.Val[float64] `db:"acres" ` - Comments null.Val[string] `db:"comments" ` - Completed null.Val[int16] `db:"completed" ` - Completedby null.Val[string] `db:"completedby" ` - Completeddate null.Val[int64] `db:"completeddate" ` - Creationdate null.Val[int64] `db:"creationdate" ` - Creator null.Val[string] `db:"creator" ` - Duedate null.Val[int64] `db:"duedate" ` - Exported null.Val[int16] `db:"exported" ` - Editdate null.Val[int64] `db:"editdate" ` - Editor null.Val[string] `db:"editor" ` - Globalid null.Val[string] `db:"globalid" ` - Hectares null.Val[float64] `db:"hectares" ` - Issprayroute null.Val[int16] `db:"issprayroute" ` - Lasttreatactivity null.Val[string] `db:"lasttreatactivity" ` - Lasttreatdate null.Val[int64] `db:"lasttreatdate" ` - Lasttreatproduct null.Val[string] `db:"lasttreatproduct" ` - Lasttreatqty null.Val[float64] `db:"lasttreatqty" ` - Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" ` - Method null.Val[string] `db:"method" ` - Name null.Val[string] `db:"name" ` - Objectid int32 `db:"objectid,pk" ` - Priority null.Val[string] `db:"priority" ` - Reviewed null.Val[int16] `db:"reviewed" ` - Reviewedby null.Val[string] `db:"reviewedby" ` - Revieweddate null.Val[int64] `db:"revieweddate" ` - ShapeArea null.Val[float64] `db:"shape__area" ` - ShapeLength null.Val[float64] `db:"shape__length" ` - Targetapprate null.Val[float64] `db:"targetapprate" ` - Targetproduct null.Val[string] `db:"targetproduct" ` - Targetspecies null.Val[string] `db:"targetspecies" ` - Zone null.Val[string] `db:"zone" ` - Zone2 null.Val[string] `db:"zone2" ` - GeometryX null.Val[float64] `db:"geometry_x" ` - GeometryY null.Val[float64] `db:"geometry_y" ` - Version int32 `db:"version,pk" ` + OrganizationID int32 `db:"organization_id" ` + Acres null.Val[float64] `db:"acres" ` + Comments null.Val[string] `db:"comments" ` + Completed null.Val[int16] `db:"completed" ` + Completedby null.Val[string] `db:"completedby" ` + Completeddate null.Val[int64] `db:"completeddate" ` + Creationdate null.Val[int64] `db:"creationdate" ` + Creator null.Val[string] `db:"creator" ` + Duedate null.Val[int64] `db:"duedate" ` + Exported null.Val[int16] `db:"exported" ` + Editdate null.Val[int64] `db:"editdate" ` + Editor null.Val[string] `db:"editor" ` + Globalid null.Val[string] `db:"globalid" ` + Hectares null.Val[float64] `db:"hectares" ` + Issprayroute null.Val[int16] `db:"issprayroute" ` + Lasttreatactivity null.Val[string] `db:"lasttreatactivity" ` + Lasttreatdate null.Val[int64] `db:"lasttreatdate" ` + Lasttreatproduct null.Val[string] `db:"lasttreatproduct" ` + Lasttreatqty null.Val[float64] `db:"lasttreatqty" ` + Lasttreatqtyunit null.Val[string] `db:"lasttreatqtyunit" ` + Method null.Val[string] `db:"method" ` + Name null.Val[string] `db:"name" ` + Objectid int32 `db:"objectid,pk" ` + Priority null.Val[string] `db:"priority" ` + Reviewed null.Val[int16] `db:"reviewed" ` + Reviewedby null.Val[string] `db:"reviewedby" ` + Revieweddate null.Val[int64] `db:"revieweddate" ` + ShapeArea null.Val[float64] `db:"shape__area" ` + ShapeLength null.Val[float64] `db:"shape__length" ` + Targetapprate null.Val[float64] `db:"targetapprate" ` + Targetproduct null.Val[string] `db:"targetproduct" ` + Targetspecies null.Val[string] `db:"targetspecies" ` + Zone null.Val[string] `db:"zone" ` + Zone2 null.Val[string] `db:"zone2" ` + GeometryX null.Val[float64] `db:"geometry_x" ` + GeometryY null.Val[float64] `db:"geometry_y" ` + Version int32 `db:"version,pk" ` + Created null.Val[time.Time] `db:"created" ` R historyProposedtreatmentareaR `db:"-" ` } @@ -84,7 +86,7 @@ type historyProposedtreatmentareaR struct { func buildHistoryProposedtreatmentareaColumns(alias string) historyProposedtreatmentareaColumns { return historyProposedtreatmentareaColumns{ ColumnsExpr: expr.NewColumnsExpr( - "organization_id", "acres", "comments", "completed", "completedby", "completeddate", "creationdate", "creator", "duedate", "exported", "editdate", "editor", "globalid", "hectares", "issprayroute", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "method", "name", "objectid", "priority", "reviewed", "reviewedby", "revieweddate", "shape__area", "shape__length", "targetapprate", "targetproduct", "targetspecies", "zone", "zone2", "geometry_x", "geometry_y", "version", + "organization_id", "acres", "comments", "completed", "completedby", "completeddate", "creationdate", "creator", "duedate", "exported", "editdate", "editor", "globalid", "hectares", "issprayroute", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "method", "name", "objectid", "priority", "reviewed", "reviewedby", "revieweddate", "shape__area", "shape__length", "targetapprate", "targetproduct", "targetspecies", "zone", "zone2", "geometry_x", "geometry_y", "version", "created", ).WithParent("history_proposedtreatmentarea"), tableAlias: alias, OrganizationID: psql.Quote(alias, "organization_id"), @@ -124,6 +126,7 @@ func buildHistoryProposedtreatmentareaColumns(alias string) historyProposedtreat GeometryX: psql.Quote(alias, "geometry_x"), GeometryY: psql.Quote(alias, "geometry_y"), Version: psql.Quote(alias, "version"), + Created: psql.Quote(alias, "created"), } } @@ -167,6 +170,7 @@ type historyProposedtreatmentareaColumns struct { GeometryX psql.Expression GeometryY psql.Expression Version psql.Expression + Created psql.Expression } func (c historyProposedtreatmentareaColumns) Alias() string { @@ -181,47 +185,48 @@ func (historyProposedtreatmentareaColumns) AliasedAs(alias string) historyPropos // All values are optional, and do not have to be set // Generated columns are not included type HistoryProposedtreatmentareaSetter struct { - OrganizationID omit.Val[int32] `db:"organization_id" ` - Acres omitnull.Val[float64] `db:"acres" ` - Comments omitnull.Val[string] `db:"comments" ` - Completed omitnull.Val[int16] `db:"completed" ` - Completedby omitnull.Val[string] `db:"completedby" ` - Completeddate omitnull.Val[int64] `db:"completeddate" ` - Creationdate omitnull.Val[int64] `db:"creationdate" ` - Creator omitnull.Val[string] `db:"creator" ` - Duedate omitnull.Val[int64] `db:"duedate" ` - Exported omitnull.Val[int16] `db:"exported" ` - Editdate omitnull.Val[int64] `db:"editdate" ` - Editor omitnull.Val[string] `db:"editor" ` - Globalid omitnull.Val[string] `db:"globalid" ` - Hectares omitnull.Val[float64] `db:"hectares" ` - Issprayroute omitnull.Val[int16] `db:"issprayroute" ` - Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" ` - Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" ` - Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" ` - Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" ` - Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" ` - Method omitnull.Val[string] `db:"method" ` - Name omitnull.Val[string] `db:"name" ` - Objectid omit.Val[int32] `db:"objectid,pk" ` - Priority omitnull.Val[string] `db:"priority" ` - Reviewed omitnull.Val[int16] `db:"reviewed" ` - Reviewedby omitnull.Val[string] `db:"reviewedby" ` - Revieweddate omitnull.Val[int64] `db:"revieweddate" ` - ShapeArea omitnull.Val[float64] `db:"shape__area" ` - ShapeLength omitnull.Val[float64] `db:"shape__length" ` - Targetapprate omitnull.Val[float64] `db:"targetapprate" ` - Targetproduct omitnull.Val[string] `db:"targetproduct" ` - Targetspecies omitnull.Val[string] `db:"targetspecies" ` - Zone omitnull.Val[string] `db:"zone" ` - Zone2 omitnull.Val[string] `db:"zone2" ` - GeometryX omitnull.Val[float64] `db:"geometry_x" ` - GeometryY omitnull.Val[float64] `db:"geometry_y" ` - Version omit.Val[int32] `db:"version,pk" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + Acres omitnull.Val[float64] `db:"acres" ` + Comments omitnull.Val[string] `db:"comments" ` + Completed omitnull.Val[int16] `db:"completed" ` + Completedby omitnull.Val[string] `db:"completedby" ` + Completeddate omitnull.Val[int64] `db:"completeddate" ` + Creationdate omitnull.Val[int64] `db:"creationdate" ` + Creator omitnull.Val[string] `db:"creator" ` + Duedate omitnull.Val[int64] `db:"duedate" ` + Exported omitnull.Val[int16] `db:"exported" ` + Editdate omitnull.Val[int64] `db:"editdate" ` + Editor omitnull.Val[string] `db:"editor" ` + Globalid omitnull.Val[string] `db:"globalid" ` + Hectares omitnull.Val[float64] `db:"hectares" ` + Issprayroute omitnull.Val[int16] `db:"issprayroute" ` + Lasttreatactivity omitnull.Val[string] `db:"lasttreatactivity" ` + Lasttreatdate omitnull.Val[int64] `db:"lasttreatdate" ` + Lasttreatproduct omitnull.Val[string] `db:"lasttreatproduct" ` + Lasttreatqty omitnull.Val[float64] `db:"lasttreatqty" ` + Lasttreatqtyunit omitnull.Val[string] `db:"lasttreatqtyunit" ` + Method omitnull.Val[string] `db:"method" ` + Name omitnull.Val[string] `db:"name" ` + Objectid omit.Val[int32] `db:"objectid,pk" ` + Priority omitnull.Val[string] `db:"priority" ` + Reviewed omitnull.Val[int16] `db:"reviewed" ` + Reviewedby omitnull.Val[string] `db:"reviewedby" ` + Revieweddate omitnull.Val[int64] `db:"revieweddate" ` + ShapeArea omitnull.Val[float64] `db:"shape__area" ` + ShapeLength omitnull.Val[float64] `db:"shape__length" ` + Targetapprate omitnull.Val[float64] `db:"targetapprate" ` + Targetproduct omitnull.Val[string] `db:"targetproduct" ` + Targetspecies omitnull.Val[string] `db:"targetspecies" ` + Zone omitnull.Val[string] `db:"zone" ` + Zone2 omitnull.Val[string] `db:"zone2" ` + GeometryX omitnull.Val[float64] `db:"geometry_x" ` + GeometryY omitnull.Val[float64] `db:"geometry_y" ` + Version omit.Val[int32] `db:"version,pk" ` + Created omitnull.Val[time.Time] `db:"created" ` } func (s HistoryProposedtreatmentareaSetter) SetColumns() []string { - vals := make([]string, 0, 37) + vals := make([]string, 0, 38) if s.OrganizationID.IsValue() { vals = append(vals, "organization_id") } @@ -333,6 +338,9 @@ func (s HistoryProposedtreatmentareaSetter) SetColumns() []string { if s.Version.IsValue() { vals = append(vals, "version") } + if !s.Created.IsUnset() { + vals = append(vals, "created") + } return vals } @@ -448,6 +456,9 @@ func (s HistoryProposedtreatmentareaSetter) Overwrite(t *HistoryProposedtreatmen if s.Version.IsValue() { t.Version = s.Version.MustGet() } + if !s.Created.IsUnset() { + t.Created = s.Created.MustGetNull() + } } func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) { @@ -456,7 +467,7 @@ func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) { }) q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 37) + vals := make([]bob.Expression, 38) if s.OrganizationID.IsValue() { vals[0] = psql.Arg(s.OrganizationID.MustGet()) } else { @@ -679,6 +690,12 @@ func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) { vals[36] = psql.Raw("DEFAULT") } + if !s.Created.IsUnset() { + vals[37] = psql.Arg(s.Created.MustGetNull()) + } else { + vals[37] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -688,7 +705,7 @@ func (s HistoryProposedtreatmentareaSetter) UpdateMod() bob.Mod[*dialect.UpdateQ } func (s HistoryProposedtreatmentareaSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 37) + exprs := make([]bob.Expression, 0, 38) if s.OrganizationID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -949,6 +966,13 @@ func (s HistoryProposedtreatmentareaSetter) Expressions(prefix ...string) []bob. }}) } + if !s.Created.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + return exprs } @@ -1295,6 +1319,7 @@ type historyProposedtreatmentareaWhere[Q psql.Filterable] struct { GeometryX psql.WhereNullMod[Q, float64] GeometryY psql.WhereNullMod[Q, float64] Version psql.WhereMod[Q, int32] + Created psql.WhereNullMod[Q, time.Time] } func (historyProposedtreatmentareaWhere[Q]) AliasedAs(alias string) historyProposedtreatmentareaWhere[Q] { @@ -1340,6 +1365,7 @@ func buildHistoryProposedtreatmentareaWhere[Q psql.Filterable](cols historyPropo GeometryX: psql.WhereNull[Q, float64](cols.GeometryX), GeometryY: psql.WhereNull[Q, float64](cols.GeometryY), Version: psql.Where[Q, int32](cols.Version), + Created: psql.WhereNull[Q, time.Time](cols.Created), } } diff --git a/models/history_treatment.bob.go b/models/history_treatment.bob.go index 2b030fac..9b4f55bd 100644 --- a/models/history_treatment.bob.go +++ b/models/history_treatment.bob.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "time" "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" @@ -25,64 +26,65 @@ import ( // HistoryTreatment is an object representing the database table. type HistoryTreatment struct { - OrganizationID int32 `db:"organization_id" ` - Activity null.Val[string] `db:"activity" ` - Areaunit null.Val[string] `db:"areaunit" ` - Avetemp null.Val[float64] `db:"avetemp" ` - Barrierrouteid null.Val[string] `db:"barrierrouteid" ` - Cbcount null.Val[int16] `db:"cbcount" ` - Comments null.Val[string] `db:"comments" ` - Containercount null.Val[int16] `db:"containercount" ` - Creationdate null.Val[int64] `db:"creationdate" ` - Creator null.Val[string] `db:"creator" ` - Enddatetime null.Val[int64] `db:"enddatetime" ` - Equiptype null.Val[string] `db:"equiptype" ` - Editdate null.Val[int64] `db:"editdate" ` - Editor null.Val[string] `db:"editor" ` - Fieldtech null.Val[string] `db:"fieldtech" ` - Flowrate null.Val[float64] `db:"flowrate" ` - Globalid null.Val[string] `db:"globalid" ` - Habitat null.Val[string] `db:"habitat" ` - InspID null.Val[string] `db:"insp_id" ` - Invloc null.Val[string] `db:"invloc" ` - Linelocid null.Val[string] `db:"linelocid" ` - Locationname null.Val[string] `db:"locationname" ` - Method null.Val[string] `db:"method" ` - Objectid int32 `db:"objectid,pk" ` - Pointlocid null.Val[string] `db:"pointlocid" ` - Polygonlocid null.Val[string] `db:"polygonlocid" ` - Product null.Val[string] `db:"product" ` - Ptaid null.Val[string] `db:"ptaid" ` - Qty null.Val[float64] `db:"qty" ` - Qtyunit null.Val[string] `db:"qtyunit" ` - Raingauge null.Val[float64] `db:"raingauge" ` - Recordstatus null.Val[int16] `db:"recordstatus" ` - Reviewed null.Val[int16] `db:"reviewed" ` - Reviewedby null.Val[string] `db:"reviewedby" ` - Revieweddate null.Val[int64] `db:"revieweddate" ` - Sdid null.Val[string] `db:"sdid" ` - Sitecond null.Val[string] `db:"sitecond" ` - Srid null.Val[string] `db:"srid" ` - Startdatetime null.Val[int64] `db:"startdatetime" ` - Targetspecies null.Val[string] `db:"targetspecies" ` - Tirecount null.Val[int16] `db:"tirecount" ` - Treatacres null.Val[float64] `db:"treatacres" ` - Treatarea null.Val[float64] `db:"treatarea" ` - Treathectares null.Val[float64] `db:"treathectares" ` - Treatmenthours null.Val[float64] `db:"treatmenthours" ` - Treatmentlength null.Val[float64] `db:"treatmentlength" ` - Treatmentlengthunits null.Val[string] `db:"treatmentlengthunits" ` - Totalcostprodcut null.Val[float64] `db:"totalcostprodcut" ` - Ulvrouteid null.Val[string] `db:"ulvrouteid" ` - Warningoverride null.Val[int16] `db:"warningoverride" ` - Winddir null.Val[string] `db:"winddir" ` - Windspeed null.Val[float64] `db:"windspeed" ` - Zone null.Val[string] `db:"zone" ` - Zone2 null.Val[string] `db:"zone2" ` - GeometryX null.Val[float64] `db:"geometry_x" ` - GeometryY null.Val[float64] `db:"geometry_y" ` - TempSitecond null.Val[string] `db:"temp_sitecond" ` - Version int32 `db:"version,pk" ` + OrganizationID int32 `db:"organization_id" ` + Activity null.Val[string] `db:"activity" ` + Areaunit null.Val[string] `db:"areaunit" ` + Avetemp null.Val[float64] `db:"avetemp" ` + Barrierrouteid null.Val[string] `db:"barrierrouteid" ` + Cbcount null.Val[int16] `db:"cbcount" ` + Comments null.Val[string] `db:"comments" ` + Containercount null.Val[int16] `db:"containercount" ` + Creationdate null.Val[int64] `db:"creationdate" ` + Creator null.Val[string] `db:"creator" ` + Enddatetime null.Val[int64] `db:"enddatetime" ` + Equiptype null.Val[string] `db:"equiptype" ` + Editdate null.Val[int64] `db:"editdate" ` + Editor null.Val[string] `db:"editor" ` + Fieldtech null.Val[string] `db:"fieldtech" ` + Flowrate null.Val[float64] `db:"flowrate" ` + Globalid null.Val[string] `db:"globalid" ` + Habitat null.Val[string] `db:"habitat" ` + InspID null.Val[string] `db:"insp_id" ` + Invloc null.Val[string] `db:"invloc" ` + Linelocid null.Val[string] `db:"linelocid" ` + Locationname null.Val[string] `db:"locationname" ` + Method null.Val[string] `db:"method" ` + Objectid int32 `db:"objectid,pk" ` + Pointlocid null.Val[string] `db:"pointlocid" ` + Polygonlocid null.Val[string] `db:"polygonlocid" ` + Product null.Val[string] `db:"product" ` + Ptaid null.Val[string] `db:"ptaid" ` + Qty null.Val[float64] `db:"qty" ` + Qtyunit null.Val[string] `db:"qtyunit" ` + Raingauge null.Val[float64] `db:"raingauge" ` + Recordstatus null.Val[int16] `db:"recordstatus" ` + Reviewed null.Val[int16] `db:"reviewed" ` + Reviewedby null.Val[string] `db:"reviewedby" ` + Revieweddate null.Val[int64] `db:"revieweddate" ` + Sdid null.Val[string] `db:"sdid" ` + Sitecond null.Val[string] `db:"sitecond" ` + Srid null.Val[string] `db:"srid" ` + Startdatetime null.Val[int64] `db:"startdatetime" ` + Targetspecies null.Val[string] `db:"targetspecies" ` + Tirecount null.Val[int16] `db:"tirecount" ` + Treatacres null.Val[float64] `db:"treatacres" ` + Treatarea null.Val[float64] `db:"treatarea" ` + Treathectares null.Val[float64] `db:"treathectares" ` + Treatmenthours null.Val[float64] `db:"treatmenthours" ` + Treatmentlength null.Val[float64] `db:"treatmentlength" ` + Treatmentlengthunits null.Val[string] `db:"treatmentlengthunits" ` + Totalcostprodcut null.Val[float64] `db:"totalcostprodcut" ` + Ulvrouteid null.Val[string] `db:"ulvrouteid" ` + Warningoverride null.Val[int16] `db:"warningoverride" ` + Winddir null.Val[string] `db:"winddir" ` + Windspeed null.Val[float64] `db:"windspeed" ` + Zone null.Val[string] `db:"zone" ` + Zone2 null.Val[string] `db:"zone2" ` + GeometryX null.Val[float64] `db:"geometry_x" ` + GeometryY null.Val[float64] `db:"geometry_y" ` + TempSitecond null.Val[string] `db:"temp_sitecond" ` + Version int32 `db:"version,pk" ` + Created null.Val[time.Time] `db:"created" ` R historyTreatmentR `db:"-" ` } @@ -105,7 +107,7 @@ type historyTreatmentR struct { func buildHistoryTreatmentColumns(alias string) historyTreatmentColumns { return historyTreatmentColumns{ ColumnsExpr: expr.NewColumnsExpr( - "organization_id", "activity", "areaunit", "avetemp", "barrierrouteid", "cbcount", "comments", "containercount", "creationdate", "creator", "enddatetime", "equiptype", "editdate", "editor", "fieldtech", "flowrate", "globalid", "habitat", "insp_id", "invloc", "linelocid", "locationname", "method", "objectid", "pointlocid", "polygonlocid", "product", "ptaid", "qty", "qtyunit", "raingauge", "recordstatus", "reviewed", "reviewedby", "revieweddate", "sdid", "sitecond", "srid", "startdatetime", "targetspecies", "tirecount", "treatacres", "treatarea", "treathectares", "treatmenthours", "treatmentlength", "treatmentlengthunits", "totalcostprodcut", "ulvrouteid", "warningoverride", "winddir", "windspeed", "zone", "zone2", "geometry_x", "geometry_y", "temp_sitecond", "version", + "organization_id", "activity", "areaunit", "avetemp", "barrierrouteid", "cbcount", "comments", "containercount", "creationdate", "creator", "enddatetime", "equiptype", "editdate", "editor", "fieldtech", "flowrate", "globalid", "habitat", "insp_id", "invloc", "linelocid", "locationname", "method", "objectid", "pointlocid", "polygonlocid", "product", "ptaid", "qty", "qtyunit", "raingauge", "recordstatus", "reviewed", "reviewedby", "revieweddate", "sdid", "sitecond", "srid", "startdatetime", "targetspecies", "tirecount", "treatacres", "treatarea", "treathectares", "treatmenthours", "treatmentlength", "treatmentlengthunits", "totalcostprodcut", "ulvrouteid", "warningoverride", "winddir", "windspeed", "zone", "zone2", "geometry_x", "geometry_y", "temp_sitecond", "version", "created", ).WithParent("history_treatment"), tableAlias: alias, OrganizationID: psql.Quote(alias, "organization_id"), @@ -166,6 +168,7 @@ func buildHistoryTreatmentColumns(alias string) historyTreatmentColumns { GeometryY: psql.Quote(alias, "geometry_y"), TempSitecond: psql.Quote(alias, "temp_sitecond"), Version: psql.Quote(alias, "version"), + Created: psql.Quote(alias, "created"), } } @@ -230,6 +233,7 @@ type historyTreatmentColumns struct { GeometryY psql.Expression TempSitecond psql.Expression Version psql.Expression + Created psql.Expression } func (c historyTreatmentColumns) Alias() string { @@ -244,68 +248,69 @@ func (historyTreatmentColumns) AliasedAs(alias string) historyTreatmentColumns { // All values are optional, and do not have to be set // Generated columns are not included type HistoryTreatmentSetter struct { - OrganizationID omit.Val[int32] `db:"organization_id" ` - Activity omitnull.Val[string] `db:"activity" ` - Areaunit omitnull.Val[string] `db:"areaunit" ` - Avetemp omitnull.Val[float64] `db:"avetemp" ` - Barrierrouteid omitnull.Val[string] `db:"barrierrouteid" ` - Cbcount omitnull.Val[int16] `db:"cbcount" ` - Comments omitnull.Val[string] `db:"comments" ` - Containercount omitnull.Val[int16] `db:"containercount" ` - Creationdate omitnull.Val[int64] `db:"creationdate" ` - Creator omitnull.Val[string] `db:"creator" ` - Enddatetime omitnull.Val[int64] `db:"enddatetime" ` - Equiptype omitnull.Val[string] `db:"equiptype" ` - Editdate omitnull.Val[int64] `db:"editdate" ` - Editor omitnull.Val[string] `db:"editor" ` - Fieldtech omitnull.Val[string] `db:"fieldtech" ` - Flowrate omitnull.Val[float64] `db:"flowrate" ` - Globalid omitnull.Val[string] `db:"globalid" ` - Habitat omitnull.Val[string] `db:"habitat" ` - InspID omitnull.Val[string] `db:"insp_id" ` - Invloc omitnull.Val[string] `db:"invloc" ` - Linelocid omitnull.Val[string] `db:"linelocid" ` - Locationname omitnull.Val[string] `db:"locationname" ` - Method omitnull.Val[string] `db:"method" ` - Objectid omit.Val[int32] `db:"objectid,pk" ` - Pointlocid omitnull.Val[string] `db:"pointlocid" ` - Polygonlocid omitnull.Val[string] `db:"polygonlocid" ` - Product omitnull.Val[string] `db:"product" ` - Ptaid omitnull.Val[string] `db:"ptaid" ` - Qty omitnull.Val[float64] `db:"qty" ` - Qtyunit omitnull.Val[string] `db:"qtyunit" ` - Raingauge omitnull.Val[float64] `db:"raingauge" ` - Recordstatus omitnull.Val[int16] `db:"recordstatus" ` - Reviewed omitnull.Val[int16] `db:"reviewed" ` - Reviewedby omitnull.Val[string] `db:"reviewedby" ` - Revieweddate omitnull.Val[int64] `db:"revieweddate" ` - Sdid omitnull.Val[string] `db:"sdid" ` - Sitecond omitnull.Val[string] `db:"sitecond" ` - Srid omitnull.Val[string] `db:"srid" ` - Startdatetime omitnull.Val[int64] `db:"startdatetime" ` - Targetspecies omitnull.Val[string] `db:"targetspecies" ` - Tirecount omitnull.Val[int16] `db:"tirecount" ` - Treatacres omitnull.Val[float64] `db:"treatacres" ` - Treatarea omitnull.Val[float64] `db:"treatarea" ` - Treathectares omitnull.Val[float64] `db:"treathectares" ` - Treatmenthours omitnull.Val[float64] `db:"treatmenthours" ` - Treatmentlength omitnull.Val[float64] `db:"treatmentlength" ` - Treatmentlengthunits omitnull.Val[string] `db:"treatmentlengthunits" ` - Totalcostprodcut omitnull.Val[float64] `db:"totalcostprodcut" ` - Ulvrouteid omitnull.Val[string] `db:"ulvrouteid" ` - Warningoverride omitnull.Val[int16] `db:"warningoverride" ` - Winddir omitnull.Val[string] `db:"winddir" ` - Windspeed omitnull.Val[float64] `db:"windspeed" ` - Zone omitnull.Val[string] `db:"zone" ` - Zone2 omitnull.Val[string] `db:"zone2" ` - GeometryX omitnull.Val[float64] `db:"geometry_x" ` - GeometryY omitnull.Val[float64] `db:"geometry_y" ` - TempSitecond omitnull.Val[string] `db:"temp_sitecond" ` - Version omit.Val[int32] `db:"version,pk" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + Activity omitnull.Val[string] `db:"activity" ` + Areaunit omitnull.Val[string] `db:"areaunit" ` + Avetemp omitnull.Val[float64] `db:"avetemp" ` + Barrierrouteid omitnull.Val[string] `db:"barrierrouteid" ` + Cbcount omitnull.Val[int16] `db:"cbcount" ` + Comments omitnull.Val[string] `db:"comments" ` + Containercount omitnull.Val[int16] `db:"containercount" ` + Creationdate omitnull.Val[int64] `db:"creationdate" ` + Creator omitnull.Val[string] `db:"creator" ` + Enddatetime omitnull.Val[int64] `db:"enddatetime" ` + Equiptype omitnull.Val[string] `db:"equiptype" ` + Editdate omitnull.Val[int64] `db:"editdate" ` + Editor omitnull.Val[string] `db:"editor" ` + Fieldtech omitnull.Val[string] `db:"fieldtech" ` + Flowrate omitnull.Val[float64] `db:"flowrate" ` + Globalid omitnull.Val[string] `db:"globalid" ` + Habitat omitnull.Val[string] `db:"habitat" ` + InspID omitnull.Val[string] `db:"insp_id" ` + Invloc omitnull.Val[string] `db:"invloc" ` + Linelocid omitnull.Val[string] `db:"linelocid" ` + Locationname omitnull.Val[string] `db:"locationname" ` + Method omitnull.Val[string] `db:"method" ` + Objectid omit.Val[int32] `db:"objectid,pk" ` + Pointlocid omitnull.Val[string] `db:"pointlocid" ` + Polygonlocid omitnull.Val[string] `db:"polygonlocid" ` + Product omitnull.Val[string] `db:"product" ` + Ptaid omitnull.Val[string] `db:"ptaid" ` + Qty omitnull.Val[float64] `db:"qty" ` + Qtyunit omitnull.Val[string] `db:"qtyunit" ` + Raingauge omitnull.Val[float64] `db:"raingauge" ` + Recordstatus omitnull.Val[int16] `db:"recordstatus" ` + Reviewed omitnull.Val[int16] `db:"reviewed" ` + Reviewedby omitnull.Val[string] `db:"reviewedby" ` + Revieweddate omitnull.Val[int64] `db:"revieweddate" ` + Sdid omitnull.Val[string] `db:"sdid" ` + Sitecond omitnull.Val[string] `db:"sitecond" ` + Srid omitnull.Val[string] `db:"srid" ` + Startdatetime omitnull.Val[int64] `db:"startdatetime" ` + Targetspecies omitnull.Val[string] `db:"targetspecies" ` + Tirecount omitnull.Val[int16] `db:"tirecount" ` + Treatacres omitnull.Val[float64] `db:"treatacres" ` + Treatarea omitnull.Val[float64] `db:"treatarea" ` + Treathectares omitnull.Val[float64] `db:"treathectares" ` + Treatmenthours omitnull.Val[float64] `db:"treatmenthours" ` + Treatmentlength omitnull.Val[float64] `db:"treatmentlength" ` + Treatmentlengthunits omitnull.Val[string] `db:"treatmentlengthunits" ` + Totalcostprodcut omitnull.Val[float64] `db:"totalcostprodcut" ` + Ulvrouteid omitnull.Val[string] `db:"ulvrouteid" ` + Warningoverride omitnull.Val[int16] `db:"warningoverride" ` + Winddir omitnull.Val[string] `db:"winddir" ` + Windspeed omitnull.Val[float64] `db:"windspeed" ` + Zone omitnull.Val[string] `db:"zone" ` + Zone2 omitnull.Val[string] `db:"zone2" ` + GeometryX omitnull.Val[float64] `db:"geometry_x" ` + GeometryY omitnull.Val[float64] `db:"geometry_y" ` + TempSitecond omitnull.Val[string] `db:"temp_sitecond" ` + Version omit.Val[int32] `db:"version,pk" ` + Created omitnull.Val[time.Time] `db:"created" ` } func (s HistoryTreatmentSetter) SetColumns() []string { - vals := make([]string, 0, 58) + vals := make([]string, 0, 59) if s.OrganizationID.IsValue() { vals = append(vals, "organization_id") } @@ -480,6 +485,9 @@ func (s HistoryTreatmentSetter) SetColumns() []string { if s.Version.IsValue() { vals = append(vals, "version") } + if !s.Created.IsUnset() { + vals = append(vals, "created") + } return vals } @@ -658,6 +666,9 @@ func (s HistoryTreatmentSetter) Overwrite(t *HistoryTreatment) { if s.Version.IsValue() { t.Version = s.Version.MustGet() } + if !s.Created.IsUnset() { + t.Created = s.Created.MustGetNull() + } } func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) { @@ -666,7 +677,7 @@ func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) { }) q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 58) + vals := make([]bob.Expression, 59) if s.OrganizationID.IsValue() { vals[0] = psql.Arg(s.OrganizationID.MustGet()) } else { @@ -1015,6 +1026,12 @@ func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) { vals[57] = psql.Raw("DEFAULT") } + if !s.Created.IsUnset() { + vals[58] = psql.Arg(s.Created.MustGetNull()) + } else { + vals[58] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -1024,7 +1041,7 @@ func (s HistoryTreatmentSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } func (s HistoryTreatmentSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 58) + exprs := make([]bob.Expression, 0, 59) if s.OrganizationID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -1432,6 +1449,13 @@ func (s HistoryTreatmentSetter) Expressions(prefix ...string) []bob.Expression { }}) } + if !s.Created.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + return exprs } @@ -1799,6 +1823,7 @@ type historyTreatmentWhere[Q psql.Filterable] struct { GeometryY psql.WhereNullMod[Q, float64] TempSitecond psql.WhereNullMod[Q, string] Version psql.WhereMod[Q, int32] + Created psql.WhereNullMod[Q, time.Time] } func (historyTreatmentWhere[Q]) AliasedAs(alias string) historyTreatmentWhere[Q] { @@ -1865,6 +1890,7 @@ func buildHistoryTreatmentWhere[Q psql.Filterable](cols historyTreatmentColumns) GeometryY: psql.WhereNull[Q, float64](cols.GeometryY), TempSitecond: psql.WhereNull[Q, string](cols.TempSitecond), Version: psql.Where[Q, int32](cols.Version), + Created: psql.WhereNull[Q, time.Time](cols.Created), } } diff --git a/models/notification.bob.go b/models/notification.bob.go index dbff0a62..55b05a16 100644 --- a/models/notification.bob.go +++ b/models/notification.bob.go @@ -7,11 +7,10 @@ import ( "context" "fmt" "io" + "time" enums "github.com/Gleipnir-Technology/nidus-sync/enums" - "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" "github.com/stephenafamo/bob" "github.com/stephenafamo/bob/dialect/psql" "github.com/stephenafamo/bob/dialect/psql/dialect" @@ -26,11 +25,12 @@ import ( // Notification is an object representing the database table. type Notification struct { - ID int32 `db:"id,pk" ` - UserID null.Val[int32] `db:"user_id" ` - Message null.Val[string] `db:"message" ` - Link null.Val[string] `db:"link" ` - Type null.Val[enums.Notificationtype] `db:"type" ` + ID int32 `db:"id,pk" ` + Created time.Time `db:"created" ` + Link string `db:"link" ` + Message string `db:"message" ` + Type enums.Notificationtype `db:"type" ` + UserID int32 `db:"user_id" ` R notificationR `db:"-" ` } @@ -53,14 +53,15 @@ type notificationR struct { func buildNotificationColumns(alias string) notificationColumns { return notificationColumns{ ColumnsExpr: expr.NewColumnsExpr( - "id", "user_id", "message", "link", "type", + "id", "created", "link", "message", "type", "user_id", ).WithParent("notification"), tableAlias: alias, ID: psql.Quote(alias, "id"), - UserID: psql.Quote(alias, "user_id"), - Message: psql.Quote(alias, "message"), + Created: psql.Quote(alias, "created"), Link: psql.Quote(alias, "link"), + Message: psql.Quote(alias, "message"), Type: psql.Quote(alias, "type"), + UserID: psql.Quote(alias, "user_id"), } } @@ -68,10 +69,11 @@ type notificationColumns struct { expr.ColumnsExpr tableAlias string ID psql.Expression - UserID psql.Expression - Message psql.Expression + Created psql.Expression Link psql.Expression + Message psql.Expression Type psql.Expression + UserID psql.Expression } func (c notificationColumns) Alias() string { @@ -86,30 +88,34 @@ func (notificationColumns) AliasedAs(alias string) notificationColumns { // All values are optional, and do not have to be set // Generated columns are not included type NotificationSetter struct { - ID omit.Val[int32] `db:"id,pk" ` - UserID omitnull.Val[int32] `db:"user_id" ` - Message omitnull.Val[string] `db:"message" ` - Link omitnull.Val[string] `db:"link" ` - Type omitnull.Val[enums.Notificationtype] `db:"type" ` + ID omit.Val[int32] `db:"id,pk" ` + Created omit.Val[time.Time] `db:"created" ` + Link omit.Val[string] `db:"link" ` + Message omit.Val[string] `db:"message" ` + Type omit.Val[enums.Notificationtype] `db:"type" ` + UserID omit.Val[int32] `db:"user_id" ` } func (s NotificationSetter) SetColumns() []string { - vals := make([]string, 0, 5) + vals := make([]string, 0, 6) if s.ID.IsValue() { vals = append(vals, "id") } - if !s.UserID.IsUnset() { - vals = append(vals, "user_id") + if s.Created.IsValue() { + vals = append(vals, "created") } - if !s.Message.IsUnset() { - vals = append(vals, "message") - } - if !s.Link.IsUnset() { + if s.Link.IsValue() { vals = append(vals, "link") } - if !s.Type.IsUnset() { + if s.Message.IsValue() { + vals = append(vals, "message") + } + if s.Type.IsValue() { vals = append(vals, "type") } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } return vals } @@ -117,17 +123,20 @@ func (s NotificationSetter) Overwrite(t *Notification) { if s.ID.IsValue() { t.ID = s.ID.MustGet() } - if !s.UserID.IsUnset() { - t.UserID = s.UserID.MustGetNull() + if s.Created.IsValue() { + t.Created = s.Created.MustGet() } - if !s.Message.IsUnset() { - t.Message = s.Message.MustGetNull() + if s.Link.IsValue() { + t.Link = s.Link.MustGet() } - if !s.Link.IsUnset() { - t.Link = s.Link.MustGetNull() + if s.Message.IsValue() { + t.Message = s.Message.MustGet() } - if !s.Type.IsUnset() { - t.Type = s.Type.MustGetNull() + if s.Type.IsValue() { + t.Type = s.Type.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() } } @@ -137,37 +146,43 @@ func (s *NotificationSetter) Apply(q *dialect.InsertQuery) { }) q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 5) + vals := make([]bob.Expression, 6) if s.ID.IsValue() { vals[0] = psql.Arg(s.ID.MustGet()) } else { vals[0] = psql.Raw("DEFAULT") } - if !s.UserID.IsUnset() { - vals[1] = psql.Arg(s.UserID.MustGetNull()) + if s.Created.IsValue() { + vals[1] = psql.Arg(s.Created.MustGet()) } else { vals[1] = psql.Raw("DEFAULT") } - if !s.Message.IsUnset() { - vals[2] = psql.Arg(s.Message.MustGetNull()) + if s.Link.IsValue() { + vals[2] = psql.Arg(s.Link.MustGet()) } else { vals[2] = psql.Raw("DEFAULT") } - if !s.Link.IsUnset() { - vals[3] = psql.Arg(s.Link.MustGetNull()) + if s.Message.IsValue() { + vals[3] = psql.Arg(s.Message.MustGet()) } else { vals[3] = psql.Raw("DEFAULT") } - if !s.Type.IsUnset() { - vals[4] = psql.Arg(s.Type.MustGetNull()) + if s.Type.IsValue() { + vals[4] = psql.Arg(s.Type.MustGet()) } else { vals[4] = psql.Raw("DEFAULT") } + if s.UserID.IsValue() { + vals[5] = psql.Arg(s.UserID.MustGet()) + } else { + vals[5] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -177,7 +192,7 @@ func (s NotificationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } func (s NotificationSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 5) + exprs := make([]bob.Expression, 0, 6) if s.ID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -186,34 +201,41 @@ func (s NotificationSetter) Expressions(prefix ...string) []bob.Expression { }}) } - if !s.UserID.IsUnset() { + if s.Created.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "user_id")...), - psql.Arg(s.UserID), + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), }}) } - if !s.Message.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "message")...), - psql.Arg(s.Message), - }}) - } - - if !s.Link.IsUnset() { + if s.Link.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "link")...), psql.Arg(s.Link), }}) } - if !s.Type.IsUnset() { + if s.Message.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "message")...), + psql.Arg(s.Message), + }}) + } + + if s.Type.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "type")...), psql.Arg(s.Type), }}) } + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "user_id")...), + psql.Arg(s.UserID), + }}) + } + return exprs } @@ -448,7 +470,7 @@ func (o *Notification) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuer } func (os NotificationSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - pkUserID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + pkUserID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { continue @@ -466,7 +488,7 @@ func (os NotificationSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) User func attachNotificationUserUser0(ctx context.Context, exec bob.Executor, count int, notification0 *Notification, user1 *User) (*Notification, error) { setter := &NotificationSetter{ - UserID: omitnull.From(user1.ID), + UserID: omit.From(user1.ID), } err := notification0.Update(ctx, exec, setter) @@ -514,10 +536,11 @@ func (notification0 *Notification) AttachUserUser(ctx context.Context, exec bob. type notificationWhere[Q psql.Filterable] struct { ID psql.WhereMod[Q, int32] - UserID psql.WhereNullMod[Q, int32] - Message psql.WhereNullMod[Q, string] - Link psql.WhereNullMod[Q, string] - Type psql.WhereNullMod[Q, enums.Notificationtype] + Created psql.WhereMod[Q, time.Time] + Link psql.WhereMod[Q, string] + Message psql.WhereMod[Q, string] + Type psql.WhereMod[Q, enums.Notificationtype] + UserID psql.WhereMod[Q, int32] } func (notificationWhere[Q]) AliasedAs(alias string) notificationWhere[Q] { @@ -527,10 +550,11 @@ func (notificationWhere[Q]) AliasedAs(alias string) notificationWhere[Q] { func buildNotificationWhere[Q psql.Filterable](cols notificationColumns) notificationWhere[Q] { return notificationWhere[Q]{ ID: psql.Where[Q, int32](cols.ID), - UserID: psql.WhereNull[Q, int32](cols.UserID), - Message: psql.WhereNull[Q, string](cols.Message), - Link: psql.WhereNull[Q, string](cols.Link), - Type: psql.WhereNull[Q, enums.Notificationtype](cols.Type), + Created: psql.Where[Q, time.Time](cols.Created), + Link: psql.Where[Q, string](cols.Link), + Message: psql.Where[Q, string](cols.Message), + Type: psql.Where[Q, enums.Notificationtype](cols.Type), + UserID: psql.Where[Q, int32](cols.UserID), } } @@ -635,11 +659,8 @@ func (os NotificationSlice) LoadUserUser(ctx context.Context, exec bob.Executor, } for _, rel := range users { - if !o.UserID.IsValue() { - continue - } - if !(o.UserID.IsValue() && o.UserID.MustGet() == rel.ID) { + if !(o.UserID == rel.ID) { continue } diff --git a/models/user_.bob.go b/models/user_.bob.go index d21f84de..b7c64258 100644 --- a/models/user_.bob.go +++ b/models/user_.bob.go @@ -678,7 +678,7 @@ func (os UserSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) Organiza func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifications1 []*NotificationSetter, user0 *User) (NotificationSlice, error) { for i := range notifications1 { - notifications1[i].UserID = omitnull.From(user0.ID) + notifications1[i].UserID = omit.From(user0.ID) } ret, err := Notifications.Insert(bob.ToMods(notifications1...)).All(ctx, exec) @@ -691,7 +691,7 @@ func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifi func attachUserUserNotifications0(ctx context.Context, exec bob.Executor, count int, notifications1 NotificationSlice, user0 *User) (NotificationSlice, error) { setter := &NotificationSetter{ - UserID: omitnull.From(user0.ID), + UserID: omit.From(user0.ID), } err := notifications1.UpdateAll(ctx, exec, *setter) @@ -1056,10 +1056,7 @@ func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor for _, rel := range notifications { - if !rel.UserID.IsValue() { - continue - } - if !(rel.UserID.IsValue() && o.ID == rel.UserID.MustGet()) { + if !(o.ID == rel.UserID) { continue }