Skip to content

Commit

Permalink
check full error
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Sep 20, 2023
1 parent 89ac50c commit cac68f0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions go/enclave/storage/init/migration/db_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/obscuronet/go-obscuro/go/enclave/storage/enclavedb"
)

const currentFileKey = "CURRENT_FILE"
const currentMigrationVersionKey = "CURRENT_MIGRATION_VERSION"

func DBMigration(db *sql.DB, sqlFiles embed.FS, logger gethlog.Logger) error {
migrationFiles, err := readMigrationFiles(sqlFiles)
Expand All @@ -27,7 +27,7 @@ func DBMigration(db *sql.DB, sqlFiles embed.FS, logger gethlog.Logger) error {
maxMigration := int64(len(migrationFiles))

var maxDB int64
config, err := enclavedb.FetchConfig(db, currentFileKey)
config, err := enclavedb.FetchConfig(db, currentMigrationVersionKey)
if err != nil {
// first time there is no entry, so we assume nothing was executed
if errors.Is(err, errutil.ErrNotFound) {
Expand All @@ -48,6 +48,8 @@ func DBMigration(db *sql.DB, sqlFiles embed.FS, logger gethlog.Logger) error {
}
err = executeMigration(db, string(content), i)
if err != nil {
fmt.Println(err)
logger.Error(fmt.Sprintf("%s", err.Error()))
return fmt.Errorf("unable to execute migration for %s - %w", migrationFiles[i].Name(), err)
}
logger.Info("Successfully executed", "file", migrationFiles[i].Name(), "index", i)
Expand All @@ -66,7 +68,7 @@ func executeMigration(db *sql.DB, content string, migrationOrder int64) error {
return err
}

_, err = enclavedb.WriteConfigToTx(tx, currentFileKey, big.NewInt(migrationOrder).Bytes())
_, err = enclavedb.WriteConfigToTx(tx, currentMigrationVersionKey, big.NewInt(migrationOrder).Bytes())
if err != nil {
return err
}
Expand Down

0 comments on commit cac68f0

Please sign in to comment.