Add existing codebase
This commit is contained in:
commit
c23a68347b
16 changed files with 807 additions and 0 deletions
29
migrate.go
Normal file
29
migrate.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package link
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/jackc/tern/migrate"
|
||||
)
|
||||
|
||||
func Migrate(pool *pgxpool.Pool) error {
|
||||
conn, err := pool.Acquire(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
migrator, err := migrate.NewMigrator(context.Background(), conn.Conn(), "schema_version")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = migrator.LoadMigrations("./migrations"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = migrator.Migrate(context.Background()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue