fix migration, add logging (#1674)

* fix migration, add logging

* change stack overflow to runtime error
This commit is contained in:
Aiden McClelland
2022-07-20 16:00:25 -06:00
committed by GitHub
parent 5fa743755d
commit 40d446ba32
4 changed files with 25 additions and 3 deletions

View File

@@ -9,6 +9,8 @@ Type=oneshot
Environment=RUST_LOG=embassy_init=debug,embassy=debug,js_engine=debug
ExecStart=/usr/local/bin/embassy-init
RemainAfterExit=true
StandardOutput=file:/var/log/embassy-init.out.log
StandardError=file:/var/log/embassy-init.error.log
[Install]
WantedBy=embassyd.service

View File

@@ -160,6 +160,8 @@ pub async fn init(cfg: &RpcContextConfig, product_key: &str) -> Result<(), Error
}
if warn_time_not_synced {
tracing::warn!("Timed out waiting for system time to synchronize");
} else {
tracing::info!("Syncronized system clock");
}
crate::version::init(&mut handle, &receipts).await?;
@@ -168,5 +170,7 @@ pub async fn init(cfg: &RpcContextConfig, product_key: &str) -> Result<(), Error
tokio::fs::remove_file(SYSTEM_REBUILD_PATH).await?;
}
tracing::info!("System initialized.");
Ok(())
}

View File

@@ -97,10 +97,18 @@ where
receipts: &InitReceipts,
) -> Result<(), Error> {
let previous = Self::Previous::new();
if version.semver() != previous.semver() {
if version.semver() < previous.semver() {
previous
.migrate_from_unchecked(version, db, receipts)
.await?;
} else if version.semver() > previous.semver() {
return Err(Error::new(
eyre!(
"NO PATH FROM {}, THIS IS LIKELY A MISTAKE IN THE VERSION DEFINITION",
version.semver()
),
crate::ErrorKind::MigrationFailed,
));
}
tracing::info!("{} -> {}", previous.semver(), self.semver(),);
self.up(db).await?;
@@ -117,10 +125,18 @@ where
tracing::info!("{} -> {}", self.semver(), previous.semver(),);
self.down(db).await?;
previous.commit(db, receipts).await?;
if version.semver() != previous.semver() {
if version.semver() < previous.semver() {
previous
.rollback_to_unchecked(version, db, receipts)
.await?;
} else if version.semver() > previous.semver() {
return Err(Error::new(
eyre!(
"NO PATH TO {}, THIS IS LIKELY A MISTAKE IN THE VERSION DEFINITION",
version.semver()
),
crate::ErrorKind::MigrationFailed,
));
}
Ok(())
}

View File

@@ -8,7 +8,7 @@ const V0_3_1_1: emver::Version = emver::Version::new(0, 3, 1, 1);
pub struct Version;
#[async_trait]
impl VersionT for Version {
type Previous = v0_3_0_3::Version;
type Previous = v0_3_1::Version;
fn new() -> Self {
Version
}