Store addresses on every geocode

This commit is contained in:
Eli Ribble 2026-04-10 22:32:40 +00:00
parent e04b86218d
commit 730f40956f
No known key found for this signature in database
12 changed files with 223 additions and 229 deletions

View file

@ -10,8 +10,17 @@ var AddressErrors = &addressErrors{
columns: []string{"id"},
s: "address_pkey",
},
ErrUniqueAddressGidUnique: &UniqueConstraintError{
schema: "",
table: "address",
columns: []string{"gid"},
s: "address_gid_unique",
},
}
type addressErrors struct {
ErrUniqueAddressPkey *UniqueConstraintError
ErrUniqueAddressGidUnique *UniqueConstraintError
}

View file

@ -17,7 +17,7 @@ var Addresses = Table[
Columns: addressColumns{
Country: column{
Name: "country",
DBType: "public.countrytype",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
@ -160,6 +160,23 @@ var Addresses = Table[
Where: "",
Include: []string{},
},
AddressGidUnique: index{
Type: "btree",
Name: "address_gid_unique",
Columns: []indexColumn{
{
Name: "gid",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
IdxAddressGeom: index{
Type: "gist",
Name: "idx_address_geom",
@ -184,6 +201,14 @@ var Addresses = Table[
Comment: "",
},
Uniques: addressUniques{
AddressGidUnique: constraint{
Name: "address_gid_unique",
Columns: []string{"gid"},
Comment: "",
},
},
Comment: "",
}
@ -211,13 +236,14 @@ func (c addressColumns) AsSlice() []column {
}
type addressIndexes struct {
AddressPkey index
IdxAddressGeom index
AddressPkey index
AddressGidUnique index
IdxAddressGeom index
}
func (i addressIndexes) AsSlice() []index {
return []index{
i.AddressPkey, i.IdxAddressGeom,
i.AddressPkey, i.AddressGidUnique, i.IdxAddressGeom,
}
}
@ -227,10 +253,14 @@ func (f addressForeignKeys) AsSlice() []foreignKey {
return []foreignKey{}
}
type addressUniques struct{}
type addressUniques struct {
AddressGidUnique constraint
}
func (u addressUniques) AsSlice() []constraint {
return []constraint{}
return []constraint{
u.AddressGidUnique,
}
}
type addressChecks struct{}

View file

@ -846,76 +846,6 @@ func (e *CommsTextorigin) Scan(value any) error {
return nil
}
// Enum values for Countrytype
const (
CountrytypeUsa Countrytype = "usa"
)
func AllCountrytype() []Countrytype {
return []Countrytype{
CountrytypeUsa,
}
}
type Countrytype string
func (e Countrytype) String() string {
return string(e)
}
func (e Countrytype) Valid() bool {
switch e {
case CountrytypeUsa:
return true
default:
return false
}
}
// useful when testing in other packages
func (e Countrytype) All() []Countrytype {
return AllCountrytype()
}
func (e Countrytype) MarshalText() ([]byte, error) {
return []byte(e), nil
}
func (e *Countrytype) UnmarshalText(text []byte) error {
return e.Scan(text)
}
func (e Countrytype) MarshalBinary() ([]byte, error) {
return []byte(e), nil
}
func (e *Countrytype) UnmarshalBinary(data []byte) error {
return e.Scan(data)
}
func (e Countrytype) Value() (driver.Value, error) {
return string(e), nil
}
func (e *Countrytype) Scan(value any) error {
switch x := value.(type) {
case string:
*e = Countrytype(x)
case []byte:
*e = Countrytype(x)
case nil:
return fmt.Errorf("cannot nil into Countrytype")
default:
return fmt.Errorf("cannot scan type %T: %v", value, value)
}
if !e.Valid() {
return fmt.Errorf("invalid Countrytype value: %s", *e)
}
return nil
}
// Enum values for FileuploadCsvtype
const (
FileuploadCsvtypePoollist FileuploadCsvtype = "PoolList"

View file

@ -0,0 +1,8 @@
-- +goose Up
ALTER TABLE address
ALTER COLUMN country
TYPE TEXT
USING country::TEXT;
DROP TYPE CountryType;
-- +goose Down

View file

@ -0,0 +1,7 @@
-- +goose Up
UPDATE address
SET gid = gen_random_uuid()
WHERE gid = '';
ALTER TABLE address ADD CONSTRAINT address_gid_unique UNIQUE (gid);
-- +goose Down
ALTER TABLE address DROP CONSTRAINT address_gid_unique;

View file

@ -18,7 +18,6 @@ import (
"github.com/Gleipnir-Technology/bob/expr"
"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"
@ -26,7 +25,7 @@ import (
// Address is an object representing the database table.
type Address struct {
Country enums.Countrytype `db:"country" `
Country string `db:"country" `
Created time.Time `db:"created" `
Location string `db:"location" `
H3cell string `db:"h3cell" `
@ -118,18 +117,18 @@ func (addressColumns) AliasedAs(alias string) addressColumns {
// All values are optional, and do not have to be set
// Generated columns are not included
type AddressSetter struct {
Country omit.Val[enums.Countrytype] `db:"country" `
Created omit.Val[time.Time] `db:"created" `
Location omit.Val[string] `db:"location" `
H3cell omit.Val[string] `db:"h3cell" `
ID omit.Val[int32] `db:"id,pk" `
Locality omit.Val[string] `db:"locality" `
PostalCode omit.Val[string] `db:"postal_code" `
Street omit.Val[string] `db:"street" `
Unit omit.Val[string] `db:"unit" `
Region omit.Val[string] `db:"region" `
Number omit.Val[string] `db:"number_" `
Gid omit.Val[string] `db:"gid" `
Country omit.Val[string] `db:"country" `
Created omit.Val[time.Time] `db:"created" `
Location omit.Val[string] `db:"location" `
H3cell omit.Val[string] `db:"h3cell" `
ID omit.Val[int32] `db:"id,pk" `
Locality omit.Val[string] `db:"locality" `
PostalCode omit.Val[string] `db:"postal_code" `
Street omit.Val[string] `db:"street" `
Unit omit.Val[string] `db:"unit" `
Region omit.Val[string] `db:"region" `
Number omit.Val[string] `db:"number_" `
Gid omit.Val[string] `db:"gid" `
}
func (s AddressSetter) SetColumns() []string {
@ -1151,7 +1150,7 @@ func (address0 *Address) AttachSite(ctx context.Context, exec bob.Executor, site
}
type addressWhere[Q psql.Filterable] struct {
Country psql.WhereMod[Q, enums.Countrytype]
Country psql.WhereMod[Q, string]
Created psql.WhereMod[Q, time.Time]
Location psql.WhereMod[Q, string]
H3cell psql.WhereMod[Q, string]
@ -1173,7 +1172,7 @@ func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
return addressWhere[Q]{
Country: psql.Where[Q, enums.Countrytype](cols.Country),
Country: psql.Where[Q, string](cols.Country),
Created: psql.Where[Q, time.Time](cols.Created),
Location: psql.Where[Q, string](cols.Location),
H3cell: psql.Where[Q, string](cols.H3cell),