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:
parent
89620a7dd2
commit
518bc4d6ff
2 changed files with 165 additions and 148 deletions
|
@ -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(¤tVersion)
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue