mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 20:59:03 +00:00
@@ -152,7 +152,7 @@ func SetupDatabase() (*gorm.DB, error) {
|
||||
}
|
||||
|
||||
func MigrateDatabase(db *gorm.DB) error {
|
||||
db.AutoMigrate(
|
||||
err := db.AutoMigrate(
|
||||
&models.User{},
|
||||
&models.AccessToken{},
|
||||
&models.SiteInfo{},
|
||||
@@ -170,6 +170,10 @@ func MigrateDatabase(db *gorm.DB) error {
|
||||
&models.ImageFace{},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Auto migration failed: %v\n", err)
|
||||
}
|
||||
|
||||
// v2.1.0 - Replaced by Media.CreatedAt
|
||||
if db.Migrator().HasColumn(&models.Media{}, "date_imported") {
|
||||
db.Migrator().DropColumn(&models.Media{}, "date_imported")
|
||||
@@ -177,9 +181,9 @@ func MigrateDatabase(db *gorm.DB) error {
|
||||
|
||||
// v2.3.0 - Changed type of MediaEXIF.Exposure and MediaEXIF.Flash
|
||||
// from string values to decimal and int respectively
|
||||
err := migrate_exif_fields(db)
|
||||
err = migrate_exif_fields(db)
|
||||
if err != nil {
|
||||
return err
|
||||
log.Printf("Failed to run exif fields migration: %v\n", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -64,6 +64,10 @@ func migrate_exif_fields_exposure(db *gorm.DB) error {
|
||||
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
if err := tx.Exec("UPDATE media_exif SET exposure = NULL WHERE exposure = ''").Error; err != nil {
|
||||
return errors.Wrapf(err, "convert flash attribute empty values to NULL")
|
||||
}
|
||||
|
||||
type exifModel struct {
|
||||
ID int `gorm:"primarykey"`
|
||||
Exposure *string
|
||||
@@ -77,11 +81,6 @@ func migrate_exif_fields_exposure(db *gorm.DB) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if *result.Exposure == "" {
|
||||
result.Exposure = nil
|
||||
continue
|
||||
}
|
||||
|
||||
frac := strings.Split(*result.Exposure, "/")
|
||||
if len(frac) != 2 {
|
||||
return errors.Errorf("failed to convert exposure value (%s) expected format x/y", frac)
|
||||
@@ -119,6 +118,10 @@ func migrate_exif_fields_flash(db *gorm.DB) error {
|
||||
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
if err := tx.Exec("UPDATE media_exif SET flash = NULL WHERE flash = ''").Error; err != nil {
|
||||
return errors.Wrapf(err, "convert flash attribute empty values to NULL")
|
||||
}
|
||||
|
||||
type exifModel struct {
|
||||
ID int `gorm:"primarykey"`
|
||||
Flash *string
|
||||
@@ -162,11 +165,6 @@ func migrate_exif_fields_flash(db *gorm.DB) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if *result.Flash == "" {
|
||||
result.Flash = nil
|
||||
continue
|
||||
}
|
||||
|
||||
for index, name := range flashDescriptions {
|
||||
if *result.Flash == name {
|
||||
*result.Flash = fmt.Sprintf("%d", index)
|
||||
|
||||
Reference in New Issue
Block a user