Skip to content

Commit

Permalink
Merge pull request #611 from input-output-hk/greg/600/database_migration
Browse files Browse the repository at this point in the history
Greg/600/database migration
  • Loading branch information
ghubertpalo committed Nov 29, 2022
2 parents 206613d + 19e0a35 commit 8c5557c
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/edit-cargo-toml-version.py
Expand Up @@ -20,7 +20,7 @@ def append_label_to_cargo_toml_version(cargo_toml_path, label: str, dry_run: boo
print("No package section (probably a workspace file), skipping this Cargo.toml")
return

new_version = f"{cargo_toml['package']['version'].split('-', 1)[0]}-{label}"
new_version = f"{cargo_toml['package']['version'].split('+', 1)[0]}+{label}"
print(f"{cargo_toml_path} new version: {new_version}")

if not dry_run:
Expand Down
27 changes: 14 additions & 13 deletions mithril-aggregator/src/command_args.rs
Expand Up @@ -12,7 +12,7 @@ use tokio::time::Duration;
use mithril_common::certificate_chain::MithrilCertificateVerifier;
use mithril_common::chain_observer::{CardanoCliRunner, ChainObserver};
use mithril_common::crypto_helper::ProtocolGenesisVerifier;
use mithril_common::database::{ApplicationNodeType, ApplicationVersionChecker};
use mithril_common::database::{ApplicationNodeType, DatabaseVersionChecker};
use mithril_common::digesters::{CardanoImmutableDigester, ImmutableFileSystemObserver};
use mithril_common::entities::{Epoch, HexEncodedGenesisSecretKey};
use mithril_common::store::adapter::SQLiteAdapter;
Expand All @@ -37,12 +37,7 @@ fn setup_genesis_dependencies(
config: &GenesisConfiguration,
) -> Result<GenesisToolsDependency, Box<dyn std::error::Error>> {
let sqlite_db_path = Some(config.get_sqlite_file());
ApplicationVersionChecker::new(
slog_scope::logger(),
ApplicationNodeType::Aggregator,
config.get_sqlite_file(),
)
.check(env!("CARGO_PKG_VERSION"))?;
check_database_migration(config.get_sqlite_file())?;

let chain_observer = Arc::new(
mithril_common::chain_observer::CardanoCliChainObserver::new(Box::new(
Expand Down Expand Up @@ -143,6 +138,17 @@ async fn do_first_launch_initialization_if_needed(
Ok(())
}

/// Database version checker.
/// This is the place where migrations are to be registered.
fn check_database_migration(sql_file_path: PathBuf) -> Result<(), Box<dyn Error>> {
DatabaseVersionChecker::new(
slog_scope::logger(),
ApplicationNodeType::Aggregator,
sql_file_path,
)
.apply()
}

/// Mithril Aggregator Node
#[derive(Parser, Debug, Clone)]
#[command(version)]
Expand Down Expand Up @@ -304,12 +310,7 @@ impl ServeCommand {
.map_err(|e| format!("configuration deserialize error: {}", e))?;
debug!("SERVE command"; "config" => format!("{:?}", config));
let sqlite_db_path = Some(config.get_sqlite_file());
ApplicationVersionChecker::new(
slog_scope::logger(),
ApplicationNodeType::Aggregator,
config.get_sqlite_file(),
)
.check(env!("CARGO_PKG_VERSION"))?;
check_database_migration(config.get_sqlite_file())?;

// Init dependencies
let snapshot_store = config.build_snapshot_store()?;
Expand Down

0 comments on commit 8c5557c

Please sign in to comment.