mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
drop the legacy upgradeDB
This commit is contained in:
parent
ecf94cdeea
commit
276b6c1e48
|
@ -1,13 +1,9 @@
|
||||||
package bbgo
|
package bbgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
// register the go migrations
|
// register the go migrations
|
||||||
_ "github.com/c9s/bbgo/pkg/migrations"
|
_ "github.com/c9s/bbgo/pkg/migrations"
|
||||||
|
|
||||||
"github.com/c9s/rockhopper"
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
@ -23,28 +19,3 @@ func ConnectMySQL(dsn string) (*sqlx.DB, error) {
|
||||||
return sqlx.Connect("mysql", dsn)
|
return sqlx.Connect("mysql", dsn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func upgradeDB(ctx context.Context, driver string, db *sql.DB) error {
|
|
||||||
dialect, err := rockhopper.LoadDialect(driver)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
loader := &rockhopper.GoMigrationLoader{}
|
|
||||||
migrations, err := loader.Load()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
rh := rockhopper.New(driver, dialect, db)
|
|
||||||
|
|
||||||
currentVersion, err := rh.CurrentVersion()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := rockhopper.Up(ctx, rh, migrations, currentVersion, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
driver: mysql
|
driver: mysql
|
||||||
dialect: mysql
|
dialect: mysql
|
||||||
dsn: "root@tcp(localhost:3306)/bbgo?parseTime=true"
|
dsn: "root@tcp(localhost:3306)/bbgo?parseTime=true"
|
||||||
migrationsDir: migrations
|
migrationsDir: migrations/mysql
|
||||||
|
|
Loading…
Reference in New Issue
Block a user