44 lines
758 B
Go
44 lines
758 B
Go
package migrations
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/status-im/migrate/v4"
|
|
"github.com/status-im/migrate/v4/database/sqlcipher"
|
|
bindata "github.com/status-im/migrate/v4/source/go_bindata"
|
|
)
|
|
|
|
// Migrate applies migrations.
|
|
func Migrate(db *sql.DB) error {
|
|
resources := bindata.Resource(
|
|
AssetNames(),
|
|
func(name string) ([]byte, error) {
|
|
return Asset(name)
|
|
},
|
|
)
|
|
|
|
source, err := bindata.WithInstance(resources)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
driver, err := sqlcipher.WithInstance(db, &sqlcipher.Config{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
m, err := migrate.NewWithInstance(
|
|
"go-bindata",
|
|
source,
|
|
"sqlcipher",
|
|
driver)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = m.Up(); err != migrate.ErrNoChange {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|