photoprism/internal/entity/mysql8_test.go
Michael Mayer e3bb8b19dd Routing: Prefix frontend UI routes with /library #840 #2466
Also improves migrations and updates the db schema docs.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-15 21:54:11 +02:00

57 lines
1 KiB
Go

package entity
import (
"os"
"testing"
"time"
"github.com/photoprism/photoprism/internal/migrate"
"github.com/jinzhu/gorm"
)
func TestMySQL8(t *testing.T) {
dbDsn := os.Getenv("PHOTOPRISM_TEST_DSN_MYSQL8")
if dbDsn == "" {
t.Skip("skipping MySQL 8 test: PHOTOPRISM_TEST_DSN_MYSQL8 is not set")
}
dbDriver := MySQL
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, migrate.Opt(false, nil))
Entities.WaitForMigration(db)
// Second migration.
Entities.Migrate(db, migrate.Opt(false, nil))
Entities.WaitForMigration(db)
// Third migration with force flag.
Entities.Migrate(db, migrate.Opt(false, []string{"20211121-094727"}))
Entities.WaitForMigration(db)
}