parent
6ad9181887
commit
bbb12003fc
|
@ -152,7 +152,7 @@ func SetupDatabase() (*gorm.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MigrateDatabase(db *gorm.DB) error {
|
func MigrateDatabase(db *gorm.DB) error {
|
||||||
db.AutoMigrate(
|
err := db.AutoMigrate(
|
||||||
&models.User{},
|
&models.User{},
|
||||||
&models.AccessToken{},
|
&models.AccessToken{},
|
||||||
&models.SiteInfo{},
|
&models.SiteInfo{},
|
||||||
|
@ -170,6 +170,10 @@ func MigrateDatabase(db *gorm.DB) error {
|
||||||
&models.ImageFace{},
|
&models.ImageFace{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Auto migration failed: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
// v2.1.0 - Replaced by Media.CreatedAt
|
// v2.1.0 - Replaced by Media.CreatedAt
|
||||||
if db.Migrator().HasColumn(&models.Media{}, "date_imported") {
|
if db.Migrator().HasColumn(&models.Media{}, "date_imported") {
|
||||||
db.Migrator().DropColumn(&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
|
// v2.3.0 - Changed type of MediaEXIF.Exposure and MediaEXIF.Flash
|
||||||
// from string values to decimal and int respectively
|
// from string values to decimal and int respectively
|
||||||
err := migrate_exif_fields(db)
|
err = migrate_exif_fields(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("Failed to run exif fields migration: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -64,6 +64,10 @@ func migrate_exif_fields_exposure(db *gorm.DB) error {
|
||||||
|
|
||||||
err := db.Transaction(func(tx *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 {
|
type exifModel struct {
|
||||||
ID int `gorm:"primarykey"`
|
ID int `gorm:"primarykey"`
|
||||||
Exposure *string
|
Exposure *string
|
||||||
|
@ -77,11 +81,6 @@ func migrate_exif_fields_exposure(db *gorm.DB) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if *result.Exposure == "" {
|
|
||||||
result.Exposure = nil
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
frac := strings.Split(*result.Exposure, "/")
|
frac := strings.Split(*result.Exposure, "/")
|
||||||
if len(frac) != 2 {
|
if len(frac) != 2 {
|
||||||
return errors.Errorf("failed to convert exposure value (%s) expected format x/y", frac)
|
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 {
|
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 {
|
type exifModel struct {
|
||||||
ID int `gorm:"primarykey"`
|
ID int `gorm:"primarykey"`
|
||||||
Flash *string
|
Flash *string
|
||||||
|
@ -162,11 +165,6 @@ func migrate_exif_fields_flash(db *gorm.DB) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if *result.Flash == "" {
|
|
||||||
result.Flash = nil
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for index, name := range flashDescriptions {
|
for index, name := range flashDescriptions {
|
||||||
if *result.Flash == name {
|
if *result.Flash == name {
|
||||||
*result.Flash = fmt.Sprintf("%d", index)
|
*result.Flash = fmt.Sprintf("%d", index)
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
"lint": "npm run lint:types & npm run lint:eslint",
|
"lint": "npm run lint:types & npm run lint:eslint",
|
||||||
"lint:eslint": "eslint ./src --max-warnings 0 --cache --config .eslintrc.js",
|
"lint:eslint": "eslint ./src --max-warnings 0 --cache --config .eslintrc.js",
|
||||||
"lint:types": "tsc --noemit",
|
"lint:types": "tsc --noemit",
|
||||||
"jest": "jest",
|
"jest": "jest --verbose",
|
||||||
"genSchemaTypes": "npx apollo client:codegen --target=typescript",
|
"genSchemaTypes": "npx apollo client:codegen --target=typescript",
|
||||||
"prepare": "(cd .. && npx husky install)"
|
"prepare": "(cd .. && npx husky install)"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue