From edfd8e285f48d068f4a10dd28cf8efdfd91fcfbf Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Fri, 20 Mar 2026 17:59:13 +0000 Subject: [PATCH] Add location x and y to address table For easier reference --- db/dbinfo/address.bob.go | 22 ++++++++++++++++++++- db/migrations/00122_address_location_xy.sql | 6 ++++++ db/models/address.bob.go | 13 +++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 db/migrations/00122_address_location_xy.sql diff --git a/db/dbinfo/address.bob.go b/db/dbinfo/address.bob.go index 6b6cec17..76e30696 100644 --- a/db/dbinfo/address.bob.go +++ b/db/dbinfo/address.bob.go @@ -114,6 +114,24 @@ var Addresses = Table[ Generated: false, AutoIncr: false, }, + LocationX: column{ + Name: "location_x", + DBType: "double precision", + Default: "GENERATED", + Comment: "", + Nullable: true, + Generated: true, + AutoIncr: false, + }, + LocationY: column{ + Name: "location_y", + DBType: "double precision", + Default: "GENERATED", + Comment: "", + Nullable: true, + Generated: true, + AutoIncr: false, + }, }, Indexes: addressIndexes{ AddressPkey: index{ @@ -172,11 +190,13 @@ type addressColumns struct { Unit column Region column Number column + LocationX column + LocationY column } func (c addressColumns) AsSlice() []column { return []column{ - c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, + c.Country, c.Created, c.Location, c.H3cell, c.ID, c.Locality, c.PostalCode, c.Street, c.Unit, c.Region, c.Number, c.LocationX, c.LocationY, } } diff --git a/db/migrations/00122_address_location_xy.sql b/db/migrations/00122_address_location_xy.sql new file mode 100644 index 00000000..16b9774d --- /dev/null +++ b/db/migrations/00122_address_location_xy.sql @@ -0,0 +1,6 @@ +-- +goose Up +ALTER TABLE address ADD COLUMN location_x DOUBLE PRECISION GENERATED ALWAYS AS (ST_X(location)) STORED; +ALTER TABLE address ADD COLUMN location_y DOUBLE PRECISION GENERATED ALWAYS AS (ST_Y(location)) STORED; +-- +goose Down +ALTER TABLE address DROP COLUMN location_y; +ALTER TABLE address DROP COLUMN location_x; diff --git a/db/models/address.bob.go b/db/models/address.bob.go index 26cc3cb0..fd94c7ba 100644 --- a/db/models/address.bob.go +++ b/db/models/address.bob.go @@ -19,6 +19,7 @@ import ( "github.com/Gleipnir-Technology/bob/orm" "github.com/Gleipnir-Technology/bob/types/pgtypes" enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" ) @@ -36,6 +37,8 @@ type Address struct { Unit string `db:"unit" ` Region string `db:"region" ` Number string `db:"number_" ` + LocationX null.Val[float64] `db:"location_x,generated" ` + LocationY null.Val[float64] `db:"location_y,generated" ` R addressR `db:"-" ` } @@ -63,7 +66,7 @@ type addressR struct { func buildAddressColumns(alias string) addressColumns { return addressColumns{ ColumnsExpr: expr.NewColumnsExpr( - "country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", + "country", "created", "location", "h3cell", "id", "locality", "postal_code", "street", "unit", "region", "number_", "location_x", "location_y", ).WithParent("address"), tableAlias: alias, Country: psql.Quote(alias, "country"), @@ -77,6 +80,8 @@ func buildAddressColumns(alias string) addressColumns { Unit: psql.Quote(alias, "unit"), Region: psql.Quote(alias, "region"), Number: psql.Quote(alias, "number_"), + LocationX: psql.Quote(alias, "location_x"), + LocationY: psql.Quote(alias, "location_y"), } } @@ -94,6 +99,8 @@ type addressColumns struct { Unit psql.Expression Region psql.Expression Number psql.Expression + LocationX psql.Expression + LocationY psql.Expression } func (c addressColumns) Alias() string { @@ -1132,6 +1139,8 @@ type addressWhere[Q psql.Filterable] struct { Unit psql.WhereMod[Q, string] Region psql.WhereMod[Q, string] Number psql.WhereMod[Q, string] + LocationX psql.WhereNullMod[Q, float64] + LocationY psql.WhereNullMod[Q, float64] } func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] { @@ -1151,6 +1160,8 @@ func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] { Unit: psql.Where[Q, string](cols.Unit), Region: psql.Where[Q, string](cols.Region), Number: psql.Where[Q, string](cols.Number), + LocationX: psql.WhereNull[Q, float64](cols.LocationX), + LocationY: psql.WhereNull[Q, float64](cols.LocationY), } }