Backend: Remove deprecated columns from geo and places

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-07-12 06:54:07 +02:00
parent f08405d96c
commit 8c53049b4a
6 changed files with 2 additions and 50 deletions

View file

@ -13,11 +13,10 @@ import (
// Geo represents a S2 cell with location data.
type Geo struct {
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"`
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:"-"`
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
}
@ -34,7 +33,6 @@ var UnknownLocation = Geo{
PlaceID: "zz",
GeoName: "",
GeoCategory: "",
GeoSource: SrcAuto,
}
// 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.GeoName = l.Name()
m.GeoCategory = l.Category()
m.GeoSource = l.Source()
if err := db.Create(m).Error; err == nil {
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 {
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
}

View file

@ -29,7 +29,6 @@ var GeoFixtures = GeoMap{
GeoName: "Adosada Platform",
GeoCategory: "botanical garden",
Place: PlaceFixtures.Pointer("mexico"),
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -47,7 +46,6 @@ var GeoFixtures = GeoMap{
},
GeoName: "Lobotes Caravan Park",
GeoCategory: "camping",
GeoSource: "manual",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -57,7 +55,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("zinkwazi"),
GeoName: "Zinkwazi Beach",
GeoCategory: "beach",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -67,7 +64,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("holidaypark"),
GeoName: "Holiday Park",
GeoCategory: "park",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -77,7 +73,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("emptyNameLongCity"),
GeoName: "",
GeoCategory: "botanical garden",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -87,7 +82,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("emptyNameShortCity"),
GeoName: "",
GeoCategory: "botanical garden",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -97,7 +91,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("veryLongLocName"),
GeoName: "longlonglonglonglonglonglonglonglonglonglonglonglongName",
GeoCategory: "cape",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},
@ -107,7 +100,6 @@ var GeoFixtures = GeoMap{
Place: PlaceFixtures.Pointer("mediumLongLocName"),
GeoName: "longlonglonglonglonglongName",
GeoCategory: "botanical garden",
GeoSource: "places",
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
},

View file

@ -12,7 +12,6 @@ func TestNewLocation(t *testing.T) {
l.GeoCategory = "restaurant"
l.GeoName = "LocationName"
l.Place = PlaceFixtures.Pointer("zinkwazi")
l.GeoSource = "places"
assert.Equal(t, "restaurant", l.Category())
assert.Equal(t, false, l.NoCategory())
@ -28,8 +27,6 @@ func TestNewLocation(t *testing.T) {
assert.Equal(t, false, l.NoState())
assert.Equal(t, "za", l.CountryCode())
assert.Equal(t, "South Africa", l.CountryName())
assert.Equal(t, "places", l.Source())
assert.Equal(t, "africa", l.Notes())
})
}

View file

@ -4,7 +4,6 @@ import (
"strings"
"time"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/maps"
"github.com/photoprism/photoprism/pkg/txt"
)
@ -17,12 +16,10 @@ type Place struct {
GeoState string `gorm:"type:varchar(255);" json:"State" yaml:"State,omitempty"`
GeoCountry string `gorm:"type:varbinary(2);" json:"Country" yaml:"Country,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"`
PhotoCount int `gorm:"default:1" json:"PhotoCount" yaml:"-"`
CreatedAt time.Time `json:"CreatedAt" yaml:"-"`
UpdatedAt time.Time `json:"UpdatedAt" yaml:"-"`
New bool `gorm:"-" json:"-" yaml:"-"`
}
// UnknownPlace is PhotoPrism's default place.
@ -33,7 +30,6 @@ var UnknownPlace = Place{
GeoState: "Unknown",
GeoCountry: "zz",
GeoKeywords: "",
GeoNotes: "",
GeoFavorite: false,
PhotoCount: -1,
}
@ -43,12 +39,6 @@ func CreateUnknownPlace() {
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.
func FindPlace(id string, label string) *Place {
place := &Place{}
@ -151,8 +141,3 @@ func (m Place) CountryCode() string {
func (m Place) CountryName() string {
return maps.CountryNames[m.GeoCountry]
}
// Notes returns place Notes
func (m Place) Notes() string {
return m.GeoNotes
}

View file

@ -30,7 +30,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "State of Mexico",
GeoCountry: "mx",
GeoKeywords: "ancient, pyramid",
GeoNotes: "",
GeoFavorite: false,
PhotoCount: 1,
CreatedAt: Timestamp(),
@ -43,7 +42,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "KwaZulu-Natal",
GeoCountry: "za",
GeoKeywords: "",
GeoNotes: "africa",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),
@ -56,7 +54,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "Rheinland-Pfalz",
GeoCountry: "de",
GeoKeywords: "",
GeoNotes: "germany",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),
@ -69,7 +66,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "Rheinland-Pfalz",
GeoCountry: "de",
GeoKeywords: "",
GeoNotes: "germany",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),
@ -82,7 +78,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "Rheinland-Pfalz",
GeoCountry: "de",
GeoKeywords: "",
GeoNotes: "germany",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),
@ -95,7 +90,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "Rheinland-Pfalz",
GeoCountry: "de",
GeoKeywords: "",
GeoNotes: "germany",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),
@ -108,7 +102,6 @@ var PlaceFixtures = PlacesMap{
GeoState: "New york",
GeoCountry: "us",
GeoKeywords: "",
GeoNotes: "",
GeoFavorite: true,
PhotoCount: 2,
CreatedAt: Timestamp(),

View file

@ -70,12 +70,10 @@ func TestPlace_Find(t *testing.T) {
GeoState: "",
GeoCountry: "",
GeoKeywords: "",
GeoNotes: "",
GeoFavorite: false,
PhotoCount: 0,
CreatedAt: Timestamp(),
UpdatedAt: Timestamp(),
New: false,
}
err := place.Find()
assert.EqualError(t, err, "record not found")