1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

refactor(database): add special handling for PostgreSQL-specific migrations

This commit is contained in:
Julien Voisin 2024-12-26 22:09:37 +00:00 committed by GitHub
parent 89620a7dd2
commit 518bc4d6ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 165 additions and 148 deletions

View file

@ -10,7 +10,7 @@ import (
"time"
// Postgresql driver import
_ "github.com/lib/pq"
pq "github.com/lib/pq"
)
// NewConnectionPool configures the database connection pool.
@ -32,6 +32,14 @@ func Migrate(db *sql.DB) error {
var currentVersion int
db.QueryRow(`SELECT version FROM schema_version`).Scan(&currentVersion)
driver := ""
switch db.Driver().(type) {
case *pq.Driver:
driver = "postgresql"
default:
panic(fmt.Sprintf("the driver %s isn't supported", db.Driver()))
}
slog.Info("Running database migrations",
slog.Int("current_version", currentVersion),
slog.Int("latest_version", schemaVersion),
@ -45,7 +53,7 @@ func Migrate(db *sql.DB) error {
return fmt.Errorf("[Migration v%d] %v", newVersion, err)
}
if err := migrations[version](tx); err != nil {
if err := migrations[version](tx, driver); err != nil {
tx.Rollback()
return fmt.Errorf("[Migration v%d] %v", newVersion, err)
}