Skip to main content

toolu_orm_cli/migrate/
error.rs

1//! MigrateError enum for migration runner failures.
2
3use thiserror::Error;
4use toolu_orm_connection::DbError;
5
6#[derive(Debug, Error)]
7pub enum MigrateError {
8  #[error("database error: {0}")]
9  Database(String),
10
11  #[error("failed to read migrations directory: {0}")]
12  ReadDir(String),
13
14  #[error("failed to read migration file: {0}")]
15  ReadFile(String),
16
17  #[error("migration {file} has been modified (expected {expected}, got {actual})")]
18  HashMismatch {
19    file: String,
20    expected: String,
21    actual: String,
22  },
23
24  /// A baseline named a migration the journal does not list, so there is no
25  /// hash to record for it.
26  #[error("no journal entry for migration(s): {0}")]
27  NotInJournal(String),
28
29  /// An embedded migration list names the same migration more than once, so
30  /// there is no single SQL body for that name.
31  #[error("duplicate migration name(s) in the embedded list: {0}")]
32  DuplicateMigration(String),
33}
34
35pub(crate) fn map_db(err: &DbError) -> MigrateError {
36  MigrateError::Database(err.to_string())
37}