mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
Use MIGRATIONS.len() and fix compile errors
This commit is contained in:
@@ -187,7 +187,7 @@ impl Init {
|
|||||||
Some(s) => {
|
Some(s) => {
|
||||||
let _ = std::fs::create_dir_all(s)
|
let _ = std::fs::create_dir_all(s)
|
||||||
.map_err(|e| anyhow::anyhow!("{e}"))
|
.map_err(|e| anyhow::anyhow!("{e}"))
|
||||||
.with_context(|| anyhow::anyhow!("{s}"))?;
|
.with_context(|| anyhow::anyhow!("{}", s.display()))?;
|
||||||
let package_name = self
|
let package_name = self
|
||||||
.package_name
|
.package_name
|
||||||
.clone()
|
.clone()
|
||||||
@@ -486,8 +486,12 @@ fn parse_cargo_toml(manifest_path: &PathBuf) -> Result<MiniCargoTomlPackage, any
|
|||||||
metadata.no_deps();
|
metadata.no_deps();
|
||||||
metadata.features(CargoOpt::AllFeatures);
|
metadata.features(CargoOpt::AllFeatures);
|
||||||
|
|
||||||
let metadata = metadata.exec()
|
let metadata = metadata.exec().with_context(|| {
|
||||||
.with_context(|| format!("Unable to load metadata from \"{}\"", manifest_path.display()))?;
|
format!(
|
||||||
|
"Unable to load metadata from \"{}\"",
|
||||||
|
manifest_path.display()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let package = metadata
|
let package = metadata
|
||||||
.root_package()
|
.root_package()
|
||||||
|
|||||||
@@ -11,7 +11,13 @@ use time::{self, OffsetDateTime};
|
|||||||
use wasmer_registry::publish::SignArchiveResult;
|
use wasmer_registry::publish::SignArchiveResult;
|
||||||
use wasmer_registry::{PartialWapmConfig, PACKAGE_TOML_FALLBACK_NAME};
|
use wasmer_registry::{PartialWapmConfig, PACKAGE_TOML_FALLBACK_NAME};
|
||||||
|
|
||||||
const CURRENT_DATA_VERSION: i32 = 3;
|
const MIGRATIONS: &[(i32, &'static str)] = &[
|
||||||
|
(0, include_str!("../../sql/migrations/0000.sql")),
|
||||||
|
(1, include_str!("../../sql/migrations/0001.sql")),
|
||||||
|
(2, include_str!("../../sql/migrations/0002.sql")),
|
||||||
|
];
|
||||||
|
|
||||||
|
const CURRENT_DATA_VERSION: usize = MIGRATIONS.len();
|
||||||
|
|
||||||
/// CLI options for the `wasmer publish` command
|
/// CLI options for the `wasmer publish` command
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
@@ -302,9 +308,7 @@ pub fn sign_compressed_archive(
|
|||||||
log::warn!("Active key does not have a private key location registered with it!");
|
log::warn!("Active key does not have a private key location registered with it!");
|
||||||
return Err(anyhow!("Cannot sign package, no private key"));
|
return Err(anyhow!("Cannot sign package, no private key"));
|
||||||
};
|
};
|
||||||
let public_key = minisign::PublicKey::from_base64(
|
let public_key = minisign::PublicKey::from_base64(&personal_key.public_key_value)?;
|
||||||
&personal_key.public_key_value,
|
|
||||||
)?;
|
|
||||||
let signature = minisign::sign(
|
let signature = minisign::sign(
|
||||||
Some(&public_key),
|
Some(&public_key),
|
||||||
&private_key,
|
&private_key,
|
||||||
@@ -339,7 +343,7 @@ pub fn apply_migrations(conn: &mut Connection) -> anyhow::Result<()> {
|
|||||||
let user_version = conn.pragma_query_value(None, "user_version", |val| val.get(0))?;
|
let user_version = conn.pragma_query_value(None, "user_version", |val| val.get(0))?;
|
||||||
for data_version in user_version..CURRENT_DATA_VERSION {
|
for data_version in user_version..CURRENT_DATA_VERSION {
|
||||||
log::debug!("Applying migration {}", data_version);
|
log::debug!("Applying migration {}", data_version);
|
||||||
apply_migration(conn, data_version)?;
|
apply_migration(conn, data_version as i32)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -363,13 +367,7 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M
|
|||||||
.transaction_with_behavior(TransactionBehavior::Immediate)
|
.transaction_with_behavior(TransactionBehavior::Immediate)
|
||||||
.map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?;
|
.map_err(|e| MigrationError::TransactionFailed(migration_number, format!("{}", e)))?;
|
||||||
|
|
||||||
let migrations = &[
|
let migration_to_apply = MIGRATIONS
|
||||||
(0, include_str!("../../sql/migrations/0000.sql")),
|
|
||||||
(1, include_str!("../../sql/migrations/0001.sql")),
|
|
||||||
(2, include_str!("../../sql/migrations/0002.sql")),
|
|
||||||
];
|
|
||||||
|
|
||||||
let migration_to_apply = migrations
|
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|(number, sql)| {
|
.find_map(|(number, sql)| {
|
||||||
if *number == migration_number {
|
if *number == migration_number {
|
||||||
@@ -379,7 +377,10 @@ fn apply_migration(conn: &mut Connection, migration_number: i32) -> Result<(), M
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ok_or({
|
.ok_or({
|
||||||
MigrationError::MigrationNumberDoesNotExist(migration_number, CURRENT_DATA_VERSION)
|
MigrationError::MigrationNumberDoesNotExist(
|
||||||
|
migration_number,
|
||||||
|
CURRENT_DATA_VERSION as i32,
|
||||||
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
tx.execute_batch(migration_to_apply)
|
tx.execute_batch(migration_to_apply)
|
||||||
|
|||||||
Reference in New Issue
Block a user