Backend: Remove deprecated columns from geo and places
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
f08405d96c
commit
8c53049b4a
|
@ -13,11 +13,10 @@ import (
|
||||||
// Geo represents a S2 cell with location data.
|
// Geo represents a S2 cell with location data.
|
||||||
type Geo struct {
|
type Geo struct {
|
||||||
ID string `gorm:"type:varbinary(42);primary_key;auto_increment:false;" json:"ID" yaml:"ID"`
|
ID string `gorm:"type:varbinary(42);primary_key;auto_increment:false;" json:"ID" yaml:"ID"`
|
||||||
PlaceID string `gorm:"type:varbinary(42);default:'zz'" json:"-" yaml:"PlaceID"`
|
|
||||||
Place *Place `gorm:"PRELOAD:true" json:"Place" yaml:"-"`
|
|
||||||
GeoName string `gorm:"type:varchar(255);" json:"Name" yaml:"Name,omitempty"`
|
GeoName string `gorm:"type:varchar(255);" json:"Name" yaml:"Name,omitempty"`
|
||||||
GeoCategory string `gorm:"type:varchar(64);" json:"Category" yaml:"Category,omitempty"`
|
GeoCategory string `gorm:"type:varchar(64);" json:"Category" yaml:"Category,omitempty"`
|
||||||
GeoSource string `gorm:"type:varbinary(16);" json:"Source" yaml:"Source,omitempty"`
|
PlaceID string `gorm:"type:varbinary(42);default:'zz'" json:"-" yaml:"PlaceID"`
|
||||||
|
Place *Place `gorm:"PRELOAD:true" json:"Place" yaml:"-"`
|
||||||
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
|
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
|
||||||
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
|
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
|
||||||
}
|
}
|
||||||
|
@ -34,7 +33,6 @@ var UnknownLocation = Geo{
|
||||||
PlaceID: "zz",
|
PlaceID: "zz",
|
||||||
GeoName: "",
|
GeoName: "",
|
||||||
GeoCategory: "",
|
GeoCategory: "",
|
||||||
GeoSource: SrcAuto,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUnknownLocation creates the default location if not exists.
|
// CreateUnknownLocation creates the default location if not exists.
|
||||||
|
@ -102,7 +100,6 @@ func (m *Geo) Find(api string) error {
|
||||||
m.PlaceID = m.Place.ID
|
m.PlaceID = m.Place.ID
|
||||||
m.GeoName = l.Name()
|
m.GeoName = l.Name()
|
||||||
m.GeoCategory = l.Category()
|
m.GeoCategory = l.Category()
|
||||||
m.GeoSource = l.Source()
|
|
||||||
|
|
||||||
if err := db.Create(m).Error; err == nil {
|
if err := db.Create(m).Error; err == nil {
|
||||||
log.Infof("geo: added %s [%s]", m.ID, time.Since(start))
|
log.Infof("geo: added %s [%s]", m.ID, time.Since(start))
|
||||||
|
@ -237,13 +234,3 @@ func (m *Geo) CountryCode() string {
|
||||||
func (m *Geo) CountryName() string {
|
func (m *Geo) CountryName() string {
|
||||||
return m.Place.CountryName()
|
return m.Place.CountryName()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes returns the locations place notes
|
|
||||||
func (m *Geo) Notes() string {
|
|
||||||
return m.Place.Notes()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Source returns the source of location information
|
|
||||||
func (m *Geo) Source() string {
|
|
||||||
return m.GeoSource
|
|
||||||
}
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ var GeoFixtures = GeoMap{
|
||||||
GeoName: "Adosada Platform",
|
GeoName: "Adosada Platform",
|
||||||
GeoCategory: "botanical garden",
|
GeoCategory: "botanical garden",
|
||||||
Place: PlaceFixtures.Pointer("mexico"),
|
Place: PlaceFixtures.Pointer("mexico"),
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -47,7 +46,6 @@ var GeoFixtures = GeoMap{
|
||||||
},
|
},
|
||||||
GeoName: "Lobotes Caravan Park",
|
GeoName: "Lobotes Caravan Park",
|
||||||
GeoCategory: "camping",
|
GeoCategory: "camping",
|
||||||
GeoSource: "manual",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -57,7 +55,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("zinkwazi"),
|
Place: PlaceFixtures.Pointer("zinkwazi"),
|
||||||
GeoName: "Zinkwazi Beach",
|
GeoName: "Zinkwazi Beach",
|
||||||
GeoCategory: "beach",
|
GeoCategory: "beach",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -67,7 +64,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("holidaypark"),
|
Place: PlaceFixtures.Pointer("holidaypark"),
|
||||||
GeoName: "Holiday Park",
|
GeoName: "Holiday Park",
|
||||||
GeoCategory: "park",
|
GeoCategory: "park",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -77,7 +73,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("emptyNameLongCity"),
|
Place: PlaceFixtures.Pointer("emptyNameLongCity"),
|
||||||
GeoName: "",
|
GeoName: "",
|
||||||
GeoCategory: "botanical garden",
|
GeoCategory: "botanical garden",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -87,7 +82,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("emptyNameShortCity"),
|
Place: PlaceFixtures.Pointer("emptyNameShortCity"),
|
||||||
GeoName: "",
|
GeoName: "",
|
||||||
GeoCategory: "botanical garden",
|
GeoCategory: "botanical garden",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -97,7 +91,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("veryLongLocName"),
|
Place: PlaceFixtures.Pointer("veryLongLocName"),
|
||||||
GeoName: "longlonglonglonglonglonglonglonglonglonglonglonglongName",
|
GeoName: "longlonglonglonglonglonglonglonglonglonglonglonglongName",
|
||||||
GeoCategory: "cape",
|
GeoCategory: "cape",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
@ -107,7 +100,6 @@ var GeoFixtures = GeoMap{
|
||||||
Place: PlaceFixtures.Pointer("mediumLongLocName"),
|
Place: PlaceFixtures.Pointer("mediumLongLocName"),
|
||||||
GeoName: "longlonglonglonglonglongName",
|
GeoName: "longlonglonglonglonglongName",
|
||||||
GeoCategory: "botanical garden",
|
GeoCategory: "botanical garden",
|
||||||
GeoSource: "places",
|
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,6 @@ func TestNewLocation(t *testing.T) {
|
||||||
l.GeoCategory = "restaurant"
|
l.GeoCategory = "restaurant"
|
||||||
l.GeoName = "LocationName"
|
l.GeoName = "LocationName"
|
||||||
l.Place = PlaceFixtures.Pointer("zinkwazi")
|
l.Place = PlaceFixtures.Pointer("zinkwazi")
|
||||||
l.GeoSource = "places"
|
|
||||||
|
|
||||||
assert.Equal(t, "restaurant", l.Category())
|
assert.Equal(t, "restaurant", l.Category())
|
||||||
assert.Equal(t, false, l.NoCategory())
|
assert.Equal(t, false, l.NoCategory())
|
||||||
|
@ -28,8 +27,6 @@ func TestNewLocation(t *testing.T) {
|
||||||
assert.Equal(t, false, l.NoState())
|
assert.Equal(t, false, l.NoState())
|
||||||
assert.Equal(t, "za", l.CountryCode())
|
assert.Equal(t, "za", l.CountryCode())
|
||||||
assert.Equal(t, "South Africa", l.CountryName())
|
assert.Equal(t, "South Africa", l.CountryName())
|
||||||
assert.Equal(t, "places", l.Source())
|
|
||||||
assert.Equal(t, "africa", l.Notes())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
"github.com/photoprism/photoprism/internal/maps"
|
"github.com/photoprism/photoprism/internal/maps"
|
||||||
"github.com/photoprism/photoprism/pkg/txt"
|
"github.com/photoprism/photoprism/pkg/txt"
|
||||||
)
|
)
|
||||||
|
@ -17,12 +16,10 @@ type Place struct {
|
||||||
GeoState string `gorm:"type:varchar(255);" json:"State" yaml:"State,omitempty"`
|
GeoState string `gorm:"type:varchar(255);" json:"State" yaml:"State,omitempty"`
|
||||||
GeoCountry string `gorm:"type:varbinary(2);" json:"Country" yaml:"Country,omitempty"`
|
GeoCountry string `gorm:"type:varbinary(2);" json:"Country" yaml:"Country,omitempty"`
|
||||||
GeoKeywords string `gorm:"type:varchar(255);" json:"Keywords" yaml:"Keywords,omitempty"`
|
GeoKeywords string `gorm:"type:varchar(255);" json:"Keywords" yaml:"Keywords,omitempty"`
|
||||||
GeoNotes string `gorm:"type:text;" json:"Notes" yaml:"Notes,omitempty"`
|
|
||||||
GeoFavorite bool `json:"Favorite" yaml:"Favorite,omitempty"`
|
GeoFavorite bool `json:"Favorite" yaml:"Favorite,omitempty"`
|
||||||
PhotoCount int `gorm:"default:1" json:"PhotoCount" yaml:"-"`
|
PhotoCount int `gorm:"default:1" json:"PhotoCount" yaml:"-"`
|
||||||
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
|
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
|
||||||
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
|
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
|
||||||
New bool `gorm:"-" json:"-" yaml:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnknownPlace is PhotoPrism's default place.
|
// UnknownPlace is PhotoPrism's default place.
|
||||||
|
@ -33,7 +30,6 @@ var UnknownPlace = Place{
|
||||||
GeoState: "Unknown",
|
GeoState: "Unknown",
|
||||||
GeoCountry: "zz",
|
GeoCountry: "zz",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "",
|
|
||||||
GeoFavorite: false,
|
GeoFavorite: false,
|
||||||
PhotoCount: -1,
|
PhotoCount: -1,
|
||||||
}
|
}
|
||||||
|
@ -43,12 +39,6 @@ func CreateUnknownPlace() {
|
||||||
FirstOrCreatePlace(&UnknownPlace)
|
FirstOrCreatePlace(&UnknownPlace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AfterCreate sets the New column used for database callback
|
|
||||||
func (m *Place) AfterCreate(scope *gorm.Scope) error {
|
|
||||||
m.New = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindPlace finds a matching place or returns nil.
|
// FindPlace finds a matching place or returns nil.
|
||||||
func FindPlace(id string, label string) *Place {
|
func FindPlace(id string, label string) *Place {
|
||||||
place := &Place{}
|
place := &Place{}
|
||||||
|
@ -151,8 +141,3 @@ func (m Place) CountryCode() string {
|
||||||
func (m Place) CountryName() string {
|
func (m Place) CountryName() string {
|
||||||
return maps.CountryNames[m.GeoCountry]
|
return maps.CountryNames[m.GeoCountry]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes returns place Notes
|
|
||||||
func (m Place) Notes() string {
|
|
||||||
return m.GeoNotes
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "State of Mexico",
|
GeoState: "State of Mexico",
|
||||||
GeoCountry: "mx",
|
GeoCountry: "mx",
|
||||||
GeoKeywords: "ancient, pyramid",
|
GeoKeywords: "ancient, pyramid",
|
||||||
GeoNotes: "",
|
|
||||||
GeoFavorite: false,
|
GeoFavorite: false,
|
||||||
PhotoCount: 1,
|
PhotoCount: 1,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -43,7 +42,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "KwaZulu-Natal",
|
GeoState: "KwaZulu-Natal",
|
||||||
GeoCountry: "za",
|
GeoCountry: "za",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "africa",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -56,7 +54,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "Rheinland-Pfalz",
|
GeoState: "Rheinland-Pfalz",
|
||||||
GeoCountry: "de",
|
GeoCountry: "de",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "germany",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -69,7 +66,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "Rheinland-Pfalz",
|
GeoState: "Rheinland-Pfalz",
|
||||||
GeoCountry: "de",
|
GeoCountry: "de",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "germany",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -82,7 +78,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "Rheinland-Pfalz",
|
GeoState: "Rheinland-Pfalz",
|
||||||
GeoCountry: "de",
|
GeoCountry: "de",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "germany",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -95,7 +90,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "Rheinland-Pfalz",
|
GeoState: "Rheinland-Pfalz",
|
||||||
GeoCountry: "de",
|
GeoCountry: "de",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "germany",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
@ -108,7 +102,6 @@ var PlaceFixtures = PlacesMap{
|
||||||
GeoState: "New york",
|
GeoState: "New york",
|
||||||
GeoCountry: "us",
|
GeoCountry: "us",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "",
|
|
||||||
GeoFavorite: true,
|
GeoFavorite: true,
|
||||||
PhotoCount: 2,
|
PhotoCount: 2,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
|
|
|
@ -70,12 +70,10 @@ func TestPlace_Find(t *testing.T) {
|
||||||
GeoState: "",
|
GeoState: "",
|
||||||
GeoCountry: "",
|
GeoCountry: "",
|
||||||
GeoKeywords: "",
|
GeoKeywords: "",
|
||||||
GeoNotes: "",
|
|
||||||
GeoFavorite: false,
|
GeoFavorite: false,
|
||||||
PhotoCount: 0,
|
PhotoCount: 0,
|
||||||
CreatedAt: Timestamp(),
|
CreatedAt: Timestamp(),
|
||||||
UpdatedAt: Timestamp(),
|
UpdatedAt: Timestamp(),
|
||||||
New: false,
|
|
||||||
}
|
}
|
||||||
err := place.Find()
|
err := place.Find()
|
||||||
assert.EqualError(t, err, "record not found")
|
assert.EqualError(t, err, "record not found")
|
||||||
|
|
Loading…
Reference in a new issue