2018-11-06 19:02:03 +01:00
|
|
|
/*
|
2020-02-21 01:14:45 +01:00
|
|
|
Package entity contains models for data storage based on GORM.
|
2018-11-06 19:02:03 +01:00
|
|
|
|
|
|
|
See http://gorm.io/docs/ for more information about GORM.
|
|
|
|
|
|
|
|
Additional information concerning data storage can be found in our Developer Guide:
|
|
|
|
|
|
|
|
https://github.com/photoprism/photoprism/wiki/Storage
|
|
|
|
*/
|
2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-11 19:11:44 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/photoprism/photoprism/internal/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
var log = event.Log
|
|
|
|
|
|
|
|
func logError(result *gorm.DB) {
|
|
|
|
if result.Error != nil {
|
|
|
|
log.Error(result.Error.Error())
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 14:32:48 +02:00
|
|
|
|
|
|
|
// Migrate creates all tables and inserts default entities as needed.
|
2020-04-30 20:07:03 +02:00
|
|
|
func Migrate() {
|
|
|
|
Db().AutoMigrate(
|
2020-04-30 14:32:48 +02:00
|
|
|
&Account{},
|
|
|
|
&File{},
|
|
|
|
&FileShare{},
|
|
|
|
&FileSync{},
|
|
|
|
&Photo{},
|
|
|
|
&Description{},
|
|
|
|
&Place{},
|
|
|
|
&Location{},
|
|
|
|
&Camera{},
|
|
|
|
&Lens{},
|
|
|
|
&Country{},
|
|
|
|
&Album{},
|
|
|
|
&PhotoAlbum{},
|
|
|
|
&Label{},
|
|
|
|
&Category{},
|
|
|
|
&PhotoLabel{},
|
|
|
|
&Keyword{},
|
|
|
|
&PhotoKeyword{},
|
|
|
|
&Link{},
|
|
|
|
)
|
|
|
|
|
2020-04-30 20:07:03 +02:00
|
|
|
CreateUnknownPlace()
|
|
|
|
CreateUnknownCountry()
|
|
|
|
CreateUnknownCamera()
|
|
|
|
CreateUnknownLens()
|
2020-04-30 14:32:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DropTables drops database tables for all known entities.
|
|
|
|
func DropTables(db *gorm.DB) {
|
|
|
|
db.DropTableIfExists(
|
|
|
|
&Account{},
|
|
|
|
&File{},
|
|
|
|
&FileShare{},
|
|
|
|
&FileSync{},
|
|
|
|
&Photo{},
|
|
|
|
&Description{},
|
|
|
|
&Place{},
|
|
|
|
&Location{},
|
|
|
|
&Camera{},
|
|
|
|
&Lens{},
|
|
|
|
&Country{},
|
|
|
|
&Album{},
|
|
|
|
&PhotoAlbum{},
|
|
|
|
&Label{},
|
|
|
|
&Category{},
|
|
|
|
&PhotoLabel{},
|
|
|
|
&Keyword{},
|
|
|
|
&PhotoKeyword{},
|
|
|
|
&Link{},
|
|
|
|
)
|
|
|
|
}
|