Tests: replace hard coded dsn's with dsn.ToString or dsn.ForPSQL

This commit is contained in:
Keith Martin 2025-11-09 20:46:00 +10:00
parent 3e198f78a1
commit a78c8b9140
8 changed files with 57 additions and 63 deletions

View file

@ -104,7 +104,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("TargetPopulated", func(t *testing.T) {
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Setup target database
os.Remove("/go/src/github.com/photoprism/photoprism/storage/targetpopulated.test.db")
@ -117,7 +117,7 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "mysql",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "sqlite",
"--transfer-dsn", "/go/src/github.com/photoprism/photoprism/storage/targetpopulated.test.db?_busy_timeout=5000&_foreign_keys=on"}
cmdArgs := []string{"migrations", "transfer"}
@ -160,7 +160,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("TargetPopulatedBatch500", func(t *testing.T) {
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Setup target database
os.Remove("/go/src/github.com/photoprism/photoprism/storage/targetpopulated.test.db")
@ -173,7 +173,7 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "mysql",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "sqlite",
"--transfer-dsn", "/go/src/github.com/photoprism/photoprism/storage/targetpopulated.test.db?_busy_timeout=5000&_foreign_keys=on"}
cmdArgs := []string{"migrations", "transfer", "-batch", "500"}
@ -216,8 +216,8 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("MySQLtoPostgreSQL", func(t *testing.T) {
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
tfDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
tfDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
// Load migrate database as source
if dumpName, err := filepath.Abs("./testdata/transfer_mysql"); err != nil {
@ -237,9 +237,9 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "mysql",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "postgres",
"--transfer-dsn", tfDSN}
"--transfer-dsn", tfDSN.ToString()}
cmdArgs := []string{"migrations", "transfer", "-batch", "10"}
ctx := NewTestContextWithParse(appArgs, cmdArgs)
@ -310,7 +310,7 @@ func TestMigrationCommand(t *testing.T) {
assert.Contains(t, l, "migrate: number of usershares transfered 1")
// Make sure that a sequence update has worked.
testdb, err := gorm.Open(postgres.Open(tfDSN), &gorm.Config{})
testdb, err := gorm.Open(postgres.Open(tfDSN.ToString()), &gorm.Config{})
if err != nil {
assert.NoError(t, err)
t.FailNow()
@ -323,7 +323,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("MySQLtoSQLite", func(t *testing.T) {
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Remove target database file
os.Remove("/go/src/github.com/photoprism/photoprism/storage/mysqltosqlite.test.db")
@ -341,7 +341,7 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "mysql",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "sqlite",
"--transfer-dsn", "/go/src/github.com/photoprism/photoprism/storage/mysqltosqlite.test.db?_busy_timeout=5000&_foreign_keys=on"}
cmdArgs := []string{"migrations", "transfer", "-batch", "1000"}
@ -431,7 +431,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("MySQLtoSQLitePopulated", func(t *testing.T) {
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Remove target database file
os.Remove("/go/src/github.com/photoprism/photoprism/storage/mysqltosqlitepopulated.test.db")
@ -452,7 +452,7 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "mysql",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "sqlite",
"--transfer-dsn", "/go/src/github.com/photoprism/photoprism/storage/mysqltosqlitepopulated.test.db?_busy_timeout=5000&_foreign_keys=on"}
cmdArgs := []string{"migrations", "transfer", "-force"}
@ -542,8 +542,8 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("PostgreSQLtoMySQL", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
tfDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
tfDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Load migrate database as source
if dumpName, err := filepath.Abs("./testdata/transfer_postgresql"); err != nil {
@ -553,8 +553,7 @@ func TestMigrationCommand(t *testing.T) {
if err := testextras.ResetPostgresDB("migrate", testextras.GetDBMutexID()); err != nil {
t.Fatal(err)
}
psqlDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d", testextras.GetDBMutexID())
if err = exec.Command("psql", psqlDSN, "--file="+dumpName).Run(); err != nil {
if err = exec.Command("psql", dbDSN.ForPSQL(), "--file="+dumpName).Run(); err != nil {
t.Fatal(err)
}
}
@ -569,9 +568,9 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "postgres",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "mysql",
"--transfer-dsn", tfDSN}
"--transfer-dsn", tfDSN.ToString()}
cmdArgs := []string{"migrations", "transfer"}
ctx := NewTestContextWithParse(appArgs, cmdArgs)
@ -641,7 +640,7 @@ func TestMigrationCommand(t *testing.T) {
assert.Contains(t, l, "migrate: number of usershares transfered 1")
// Make sure that a sequence update has worked.
testdb, err := gorm.Open(mysql.Open(tfDSN), &gorm.Config{})
testdb, err := gorm.Open(mysql.Open(tfDSN.ToString()), &gorm.Config{})
if err != nil {
assert.NoError(t, err)
t.FailNow()
@ -654,7 +653,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("PostgreSQLtoSQLite", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
// Remove target database file
os.Remove("/go/src/github.com/photoprism/photoprism/storage/postgresqltosqlite.test.db")
@ -668,8 +667,7 @@ func TestMigrationCommand(t *testing.T) {
t.Fatal(err)
}
psqlDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d", testextras.GetDBMutexID())
if err = exec.Command("psql", psqlDSN, "--file="+dumpName).Run(); err != nil {
if err = exec.Command("psql", dbDSN.ForPSQL(), "--file="+dumpName).Run(); err != nil {
t.Fatal(err)
}
}
@ -679,7 +677,7 @@ func TestMigrationCommand(t *testing.T) {
appArgs := []string{"photoprism",
"--database-driver", "postgres",
"--database-dsn", dbDSN,
"--database-dsn", dbDSN.ToString(),
"--transfer-driver", "sqlite",
"--transfer-dsn", "/go/src/github.com/photoprism/photoprism/storage/postgresqltosqlite.test.db?_busy_timeout=5000&_foreign_keys=on"}
cmdArgs := []string{"migrations", "transfer"}
@ -769,7 +767,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("SQLiteToMySQL", func(t *testing.T) {
tfDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
tfDSN := dsn.DSN{Driver: dsn.DriverMariaDB, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
// Remove target database file
os.Remove("/go/src/github.com/photoprism/photoprism/storage/sqlitetomysql.test.db")
@ -791,7 +789,7 @@ func TestMigrationCommand(t *testing.T) {
"--database-driver", "sqlite",
"--database-dsn", "/go/src/github.com/photoprism/photoprism/storage/sqlitetomysql.test.db?_busy_timeout=5000&_foreign_keys=on",
"--transfer-driver", "mysql",
"--transfer-dsn", tfDSN}
"--transfer-dsn", tfDSN.ToString()}
cmdArgs := []string{"migrations", "transfer"}
ctx := NewTestContextWithParse(appArgs, cmdArgs)
@ -861,7 +859,7 @@ func TestMigrationCommand(t *testing.T) {
assert.Contains(t, l, "migrate: number of usershares transfered 1")
// Make sure that a sequence update has worked.
testdb, err := gorm.Open(mysql.Open(tfDSN), &gorm.Config{})
testdb, err := gorm.Open(mysql.Open(tfDSN.ToString()), &gorm.Config{})
if err != nil {
assert.NoError(t, err)
t.FailNow()
@ -879,7 +877,7 @@ func TestMigrationCommand(t *testing.T) {
})
t.Run("SQLiteToPostgreSQL", func(t *testing.T) {
tfDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
tfDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
// Remove target database file
os.Remove("/go/src/github.com/photoprism/photoprism/storage/sqlitetopostgresql.test.db")
@ -901,7 +899,7 @@ func TestMigrationCommand(t *testing.T) {
"--database-driver", "sqlite",
"--database-dsn", "/go/src/github.com/photoprism/photoprism/storage/sqlitetopostgresql.test.db?_busy_timeout=5000&_foreign_keys=on",
"--transfer-driver", "postgres",
"--transfer-dsn", tfDSN}
"--transfer-dsn", tfDSN.ToString()}
cmdArgs := []string{"migrations", "transfer"}
ctx := NewTestContextWithParse(appArgs, cmdArgs)
@ -971,7 +969,7 @@ func TestMigrationCommand(t *testing.T) {
assert.Contains(t, l, "migrate: number of usershares transfered 1")
// Make sure that a sequence update has worked.
testdb, err := gorm.Open(postgres.Open(tfDSN), &gorm.Config{})
testdb, err := gorm.Open(postgres.Open(tfDSN.ToString()), &gorm.Config{})
if err != nil {
assert.NoError(t, err)
t.FailNow()

View file

@ -20,6 +20,7 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/entity/migrate"
"github.com/photoprism/photoprism/internal/testextras"
"github.com/photoprism/photoprism/pkg/dsn"
"github.com/photoprism/photoprism/pkg/rnd"
)
@ -46,10 +47,10 @@ func TestDialectMysql(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMySQL, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
db, err := gorm.Open(mysql.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,
@ -143,10 +144,10 @@ func TestDialectMysql(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMySQL, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
db, err := gorm.Open(mysql.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -20,6 +20,7 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/entity/migrate"
"github.com/photoprism/photoprism/internal/testextras"
"github.com/photoprism/photoprism/pkg/dsn"
)
func TestDialectPostgreSQL(t *testing.T) {
@ -35,7 +36,7 @@ func TestDialectPostgreSQL(t *testing.T) {
defer dbtestMutex.Unlock()
log.Info("Expect many table does not exist or no such table Error or SQLSTATE from migration.go")
t.Run("ValidMigration", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
if dumpName, err := filepath.Abs("../migrate/testdata/migrate_postgres.sql"); err != nil {
t.Fatal(err)
@ -45,9 +46,7 @@ func TestDialectPostgreSQL(t *testing.T) {
t.Fatal(err)
}
psqlDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d", testextras.GetDBMutexID())
if err = exec.Command("psql", psqlDSN, "--file="+dumpName).Run(); err != nil {
if err = exec.Command("psql", dbDSN.ForPSQL(), "--file="+dumpName).Run(); err != nil {
t.Fatal(err)
}
}
@ -56,7 +55,7 @@ func TestDialectPostgreSQL(t *testing.T) {
log.SetLevel(logrus.TraceLevel)
db, err := gorm.Open(postgres.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,
@ -135,7 +134,7 @@ func TestDialectPostgreSQL(t *testing.T) {
})
t.Run("EmptyDB", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
// Clear Postgres source (migrate)
if err := testextras.ResetPostgresDB("migrate", testextras.GetDBMutexID()); err != nil {
@ -146,7 +145,7 @@ func TestDialectPostgreSQL(t *testing.T) {
log.SetLevel(logrus.TraceLevel)
db, err := gorm.Open(postgres.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -2,7 +2,6 @@ package entity
import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
@ -18,6 +17,7 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/entity/migrate"
"github.com/photoprism/photoprism/pkg/dsn"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/rnd"
)
@ -53,9 +53,9 @@ func TestDialectSQLite3(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dsn := fmt.Sprintf("%v?_foreign_keys=on&_busy_timeout=5000", dumpName)
dbDSN := dsn.DSN{Driver: dsn.DriverSQLite3, Server: filepath.Dir(dumpName), Name: filepath.Base(dumpName)}
db, err := gorm.Open(sqlite.Open(dsn),
db, err := gorm.Open(sqlite.Open(dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,
@ -151,9 +151,9 @@ func TestDialectSQLite3(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dsn := fmt.Sprintf("%v?_foreign_keys=on&_busy_timeout=5000", dumpName)
dbDSN := dsn.DSN{Driver: dsn.DriverSQLite3, Server: filepath.Dir(dumpName), Name: filepath.Base(dumpName)}
db, err := gorm.Open(sqlite.Open(dsn),
db, err := gorm.Open(sqlite.Open(dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -37,10 +37,10 @@ func TestDialectMysql(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dbDSN := fmt.Sprintf("migrate:migrate@tcp(mariadb:4001)/migrate_%02d?charset=utf8mb4,utf8&collation=utf8mb4_unicode_ci&parseTime=true&timeout=15s", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverMySQL, Net: "tcp", Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "mariadb:4001", User: "migrate", Password: "migrate"}
db, err := gorm.Open(mysql.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -24,7 +24,7 @@ func TestDialectPostgreSQL(t *testing.T) {
t.Skip("skipping test as not PostgreSQL")
}
t.Run("Existing", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
if dumpName, err := filepath.Abs("./testdata/migrate_postgres.sql"); err != nil {
t.Fatal(err)
@ -33,9 +33,8 @@ func TestDialectPostgreSQL(t *testing.T) {
if err := testextras.ResetPostgresDB("migrate", testextras.GetDBMutexID()); err != nil {
t.Fatal(err)
}
psqlDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d", testextras.GetDBMutexID())
if err = exec.Command("psql", psqlDSN, "--file="+dumpName).Run(); err != nil {
if err = exec.Command("psql", dbDSN.ForPSQL(), "--file="+dumpName).Run(); err != nil {
t.Fatal(err)
}
}
@ -45,7 +44,7 @@ func TestDialectPostgreSQL(t *testing.T) {
log.SetLevel(logrus.TraceLevel)
db, err := gorm.Open(postgres.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,
@ -111,7 +110,7 @@ func TestDialectPostgreSQL(t *testing.T) {
})
t.Run("New", func(t *testing.T) {
dbDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d?TimeZone=UTC&connect_timeout=15&lock_timeout=5000&sslmode=disable", testextras.GetDBMutexID())
dbDSN := dsn.DSN{Driver: dsn.DriverPostgreSQL, Name: fmt.Sprintf("migrate_%02d", testextras.GetDBMutexID()), Server: "postgres:5432", User: "migrate", Password: "migrate"}
if dumpName, err := filepath.Abs("./testdata/migrate_postgres.sql"); err != nil {
t.Fatal(err)
@ -121,9 +120,7 @@ func TestDialectPostgreSQL(t *testing.T) {
t.Fatal(err)
}
psqlDSN := fmt.Sprintf("postgresql://migrate:migrate@postgres:5432/migrate_%02d", testextras.GetDBMutexID())
if err = exec.Command("psql", psqlDSN, "--file="+dumpName).Run(); err != nil {
if err = exec.Command("psql", dbDSN.ForPSQL(), "--file="+dumpName).Run(); err != nil {
t.Fatal(err)
}
}
@ -133,7 +130,7 @@ func TestDialectPostgreSQL(t *testing.T) {
log.SetLevel(logrus.TraceLevel)
db, err := gorm.Open(postgres.Open(
dbDSN),
dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -1,7 +1,6 @@
package migrate
import (
"fmt"
"os"
"path/filepath"
"testing"
@ -42,9 +41,9 @@ func TestDialectSQLite3(t *testing.T) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
dsn := fmt.Sprintf("%v?_foreign_keys=on&_busy_timeout=5000", dumpName)
dbDSN := dsn.DSN{Driver: dsn.DriverSQLite3, Server: filepath.Dir(dumpName), Name: filepath.Base(dumpName)}
db, err := gorm.Open(sqlite.Open(dsn),
db, err := gorm.Open(sqlite.Open(dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,

View file

@ -2,7 +2,6 @@ package performancetest
import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
@ -21,6 +20,7 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/entity/migrate"
"github.com/photoprism/photoprism/pkg/dsn"
"github.com/photoprism/photoprism/pkg/fs"
)
@ -44,9 +44,9 @@ func sqliteMigration(original string, temp string, numberOfRecords int, skipSpee
log.SetLevel(logrus.ErrorLevel)
start := time.Now()
dsn := fmt.Sprintf("%v?_foreign_keys=on&_busy_timeout=5000", dumpName)
dbDSN := dsn.DSN{Driver: dsn.DriverSQLite3, Server: filepath.Dir(dumpName), Name: filepath.Base(dumpName)}
db, err := gorm.Open(sqlite.Open(dsn),
db, err := gorm.Open(sqlite.Open(dbDSN.ToString()),
&gorm.Config{
Logger: logger.New(
log,