2023-08-11 11:25:14 +00:00
|
|
|
package walletdatabase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/sqlite"
|
|
|
|
"github.com/status-im/status-go/walletdatabase/migrations"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DbInitializer struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a DbInitializer) Initialize(path, password string, kdfIterationsNumber int) (*sql.DB, error) {
|
|
|
|
return InitializeDB(path, password, kdfIterationsNumber)
|
|
|
|
}
|
|
|
|
|
2023-08-08 06:55:13 +00:00
|
|
|
var walletCustomSteps = []*sqlite.PostStep{}
|
2023-08-11 11:25:14 +00:00
|
|
|
|
|
|
|
func doMigration(db *sql.DB) error {
|
|
|
|
// Run all the new migrations
|
|
|
|
return migrations.Migrate(db, walletCustomSteps)
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitializeDB creates db file at a given path and applies migrations.
|
|
|
|
func InitializeDB(path, password string, kdfIterationsNumber int) (*sql.DB, error) {
|
|
|
|
db, err := sqlite.OpenDB(path, password, kdfIterationsNumber)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = doMigration(db)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|