use thiserror::Error;
#[derive(Debug, Error)]
pub enum MigratromError {
#[error("{0}")]
Config(String),
#[error("duplicate migration id: {0}")]
DuplicateMigrationId(i64),
#[error("no root migration (parent_id = None) in an empty history")]
MissingRoot,
#[error("multiple root migrations: {0:?}")]
MultipleRoots(Vec<i64>),
#[error("migration {id} references missing parent {parent}")]
MissingParent {
id: i64,
parent: i64,
},
#[error("cycle detected in migration graph: {0:?}")]
CycleDetected(Vec<i64>),
#[error("precheck failed for operation \"{operation}\": {description}")]
PrecheckFailed {
operation: String,
description: String,
},
#[error("postcheck failed for operation \"{operation}\": {description}")]
PostcheckFailed {
operation: String,
description: String,
},
#[error("operation \"{0}\" has no postcheck")]
EmptyPostcheck(String),
#[error("migration {id} failed: {cause}")]
MigrationFailed {
id: i64,
#[source]
cause: Box<MigratromError>,
},
#[error(
"migration {id} checksum mismatch (applied body was edited): expected {expected}, got {actual}"
)]
ChecksumMismatch {
id: i64,
expected: String,
actual: String,
},
#[error("{message}{}", .row_preview.as_deref().map(|r| format!(" — row: {r}")).unwrap_or_default())]
CheckShape {
message: String,
row_preview: Option<String>,
},
#[error("{feature} is not supported by the {dialect} dialect")]
Unsupported {
feature: String,
dialect: String,
},
#[error("database error: {0}")]
Db(String),
}
pub type Result<T> = std::result::Result<T, MigratromError>;