db: make migrations a struct instead of a plain string
This commit is contained in:
@@ -20,11 +20,11 @@ type DBConfig struct {
|
||||
sql_schema *string
|
||||
|
||||
// Database starts at version 0. First migration brings us to version 1
|
||||
migrations *[]string
|
||||
migrations *[]Migration
|
||||
version_number uint
|
||||
}
|
||||
|
||||
func Init(schema *string, migrationsList *[]string) DBConfig {
|
||||
func Init(schema *string, migrationsList *[]Migration) DBConfig {
|
||||
return DBConfig{
|
||||
sql_schema: schema,
|
||||
migrations: migrationsList,
|
||||
@@ -99,7 +99,7 @@ func (c DBConfig) CheckAndUpdateVersion(db *sqlx.DB) error {
|
||||
func (c DBConfig) UpgradeFromXToY(db *sqlx.DB, x uint, y uint) {
|
||||
for i := x; i < y; i++ {
|
||||
fmt.Print(textutils.ColorCyan)
|
||||
fmt.Println((*c.migrations)[i])
|
||||
fmt.Println((*c.migrations)[i].SQL)
|
||||
fmt.Print(textutils.ColorReset)
|
||||
|
||||
// Execute the migration in a transaction
|
||||
@@ -107,7 +107,7 @@ func (c DBConfig) UpgradeFromXToY(db *sqlx.DB, x uint, y uint) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tx.MustExec((*c.migrations)[i])
|
||||
tx.MustExec((*c.migrations)[i].SQL)
|
||||
tx.MustExec("update db_version set version = ?", i+1)
|
||||
if err := tx.Commit(); err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user