Refactor code
This commit is contained in:
parent
4c3f095109
commit
db6f98ba79
3 changed files with 17 additions and 26 deletions
27
database/migrate.go
Normal file
27
database/migrate.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/jackc/tern/migrate"
|
||||
)
|
||||
|
||||
func Migrate(pool *pgxpool.Pool) {
|
||||
conn, err := pool.Acquire(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
migrator, err := migrate.NewMigrator(context.Background(), conn.Conn(), "schema_version")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err = migrator.LoadMigrations("./migrations"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err = migrator.Migrate(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue