Skip to content

Commit

Permalink
Add special handling for postgresql-specific migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Dec 22, 2024
1 parent d345c87 commit c63e8bf
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 146 deletions.
10 changes: 8 additions & 2 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

// Postgresql driver import
_ "github.com/lib/pq"
pq "github.com/lib/pq"
)

// NewConnectionPool configures the database connection pool.
Expand All @@ -32,6 +32,12 @@ func Migrate(db *sql.DB) error {
var currentVersion int
db.QueryRow(`SELECT version FROM schema_version`).Scan(&currentVersion)

driver := ""
switch db.Driver().(type) {

Check failure on line 36 in internal/database/database.go

View workflow job for this annotation

GitHub Actions / Golang Linters

singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
case *pq.Driver:
driver = "postgresql"
}

slog.Info("Running database migrations",
slog.Int("current_version", currentVersion),
slog.Int("latest_version", schemaVersion),
Expand All @@ -45,7 +51,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)
}
Expand Down
Loading

0 comments on commit c63e8bf

Please sign in to comment.