Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deploys from main - remove migration file for now #1540

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions go/enclave/storage/init/edgelessdb/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ GRANT ALL ON obsdb.l1_msg TO obscuro;

create table if not exists obsdb.rollup
(
id INTEGER AUTO_INCREMENT,
start_seq int NOT NULL,
end_seq int NOT NULL,
header blob NOT NULL,
block binary(32) NOT NULL,
INDEX (block),
primary key (id)
);
hash binary(32),
start_seq int NOT NULL,
end_seq int NOT NULL,
header blob NOT NULL,
compression_block binary(32) NOT NULL,
INDEX (compression_block),
primary key (hash)
);
GRANT ALL ON obsdb.rollup TO obscuro;

create table if not exists obsdb.batch_body
Expand Down
13 changes: 0 additions & 13 deletions go/enclave/storage/init/edgelessdb/002_init.sql

This file was deleted.

11 changes: 6 additions & 5 deletions go/enclave/storage/init/migration/db_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the reason for the changes in this file? Since the 002 file was removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It clears up comments and a variable name that threw me off the first time I was reading the code, and adds more info to the error.

Made those changes while debugging the code initially, and felt like they would be good to keep.
Likely it would be good to keep the comment and the error, but perhaps change back the var name if you prefer ?
What do you think ?

"embed"
"errors"
"fmt"
"io/fs"
"math/big"
"sort"
Expand All @@ -15,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 @@ -26,9 +27,9 @@ 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 001 was executed already
// first time there is no entry, so 001 was executed already ( triggered at launch/manifest time )
if errors.Is(err, errutil.ErrNotFound) {
maxDB = 1
} else {
Expand All @@ -47,7 +48,7 @@ func DBMigration(db *sql.DB, sqlFiles embed.FS, logger gethlog.Logger) error {
}
err = executeMigration(db, string(content), i)
if err != nil {
return err
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 @@ -65,7 +66,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