From 34208be4d628668af8162e9f4326cf4f6978a8d9 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Thu, 21 Sep 2023 11:26:54 +0100 Subject: [PATCH] Fix deploys from main - remove migration file for now (#1540) * Fixes to the dev-testnet deploy * deploy from 0 * check full error * plucking that err * fix * test * fix perms --- go/enclave/storage/init/edgelessdb/001_init.sql | 16 ++++++++-------- go/enclave/storage/init/edgelessdb/002_init.sql | 13 ------------- .../storage/init/migration/db_migration.go | 11 ++++++----- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 go/enclave/storage/init/edgelessdb/002_init.sql diff --git a/go/enclave/storage/init/edgelessdb/001_init.sql b/go/enclave/storage/init/edgelessdb/001_init.sql index fb81076e49..c09b16d66c 100644 --- a/go/enclave/storage/init/edgelessdb/001_init.sql +++ b/go/enclave/storage/init/edgelessdb/001_init.sql @@ -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 diff --git a/go/enclave/storage/init/edgelessdb/002_init.sql b/go/enclave/storage/init/edgelessdb/002_init.sql deleted file mode 100644 index 4b532ba776..0000000000 --- a/go/enclave/storage/init/edgelessdb/002_init.sql +++ /dev/null @@ -1,13 +0,0 @@ -drop table obsdb.rollup; - -create table if not exists obsdb.rollup -( - 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; diff --git a/go/enclave/storage/init/migration/db_migration.go b/go/enclave/storage/init/migration/db_migration.go index 3afc838487..b243bc0125 100644 --- a/go/enclave/storage/init/migration/db_migration.go +++ b/go/enclave/storage/init/migration/db_migration.go @@ -4,6 +4,7 @@ import ( "database/sql" "embed" "errors" + "fmt" "io/fs" "math/big" "sort" @@ -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) @@ -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 { @@ -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) } @@ -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 }