Commit 518bc4d 1 parent 89620a7 commit 518bc4d Copy full SHA for 518bc4d
File tree 2 files changed +163
-146
lines changed
2 files changed +163
-146
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"time"
11
11
12
12
// Postgresql driver import
13
- _ "github.com/lib/pq"
13
+ pq "github.com/lib/pq"
14
14
)
15
15
16
16
// NewConnectionPool configures the database connection pool.
@@ -32,6 +32,14 @@ func Migrate(db *sql.DB) error {
32
32
var currentVersion int
33
33
db .QueryRow (`SELECT version FROM schema_version` ).Scan (& currentVersion )
34
34
35
+ driver := ""
36
+ switch db .Driver ().(type ) {
37
+ case * pq.Driver :
38
+ driver = "postgresql"
39
+ default :
40
+ panic (fmt .Sprintf ("the driver %s isn't supported" , db .Driver ()))
41
+ }
42
+
35
43
slog .Info ("Running database migrations" ,
36
44
slog .Int ("current_version" , currentVersion ),
37
45
slog .Int ("latest_version" , schemaVersion ),
@@ -45,7 +53,7 @@ func Migrate(db *sql.DB) error {
45
53
return fmt .Errorf ("[Migration v%d] %v" , newVersion , err )
46
54
}
47
55
48
- if err := migrations [version ](tx ); err != nil {
56
+ if err := migrations [version ](tx , driver ); err != nil {
49
57
tx .Rollback ()
50
58
return fmt .Errorf ("[Migration v%d] %v" , newVersion , err )
51
59
}
You can’t perform that action at this time.
0 commit comments