2021-11-28 13:52:27 +01:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMySQL8(t *testing.T) {
|
|
|
|
dbDsn := os.Getenv("PHOTOPRISM_TEST_DSN_MYSQL8")
|
|
|
|
|
2022-01-16 14:00:37 +01:00
|
|
|
if dbDsn == "" {
|
|
|
|
t.Skip("skipping MySQL 8 test: PHOTOPRISM_TEST_DSN_MYSQL8 is not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
dbDriver := MySQL
|
2021-11-28 13:52:27 +01:00
|
|
|
db, err := gorm.Open(dbDriver, dbDsn)
|
|
|
|
|
|
|
|
if err != nil || db == nil {
|
|
|
|
for i := 1; i <= 5; i++ {
|
|
|
|
db, err = gorm.Open(dbDriver, dbDsn)
|
|
|
|
|
|
|
|
if db != nil && err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil || db == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
db.LogMode(false)
|
|
|
|
|
|
|
|
DeprecatedTables.Drop(db)
|
|
|
|
Entities.Drop(db)
|
|
|
|
|
|
|
|
// First migration.
|
|
|
|
Entities.Migrate(db, false)
|
|
|
|
Entities.WaitForMigration(db)
|
|
|
|
|
|
|
|
// Second migration.
|
|
|
|
Entities.Migrate(db, false)
|
|
|
|
Entities.WaitForMigration(db)
|
|
|
|
|
|
|
|
// Third migration with force flag.
|
|
|
|
Entities.Migrate(db, true)
|
|
|
|
Entities.WaitForMigration(db)
|
|
|
|
}
|