Skip to main content

hiver_flyway/
error.rs

1//! Flyway error types
2//! Flyway 错误类型
3
4use std::path::PathBuf;
5use thiserror::Error;
6
7/// Flyway error type
8/// Flyway 错误类型
9#[derive(Error, Debug)]
10pub enum FlywayError {
11    /// Configuration error
12    /// 配置错误
13    #[error("Configuration error: {0}")]
14    ConfigError(String),
15
16    /// Database connection error
17    /// 数据库连接错误
18    #[error("Database connection error: {0}")]
19    ConnectionError(#[from] sqlx::Error),
20
21    /// Migration script error
22    /// 迁移脚本错误
23    #[error("Migration script error: {0}")]
24    MigrationError(String),
25
26    /// Validation error
27    /// 校验错误
28    #[error("Validation error: {0}")]
29    ValidationError(String),
30
31    /// Migration file not found
32    /// 迁移文件未找到
33    #[error("Migration file not found: {0}")]
34    FileNotFound(PathBuf),
35
36    /// Invalid migration version
37    /// 无效的迁移版本
38    #[error("Invalid migration version: {0}")]
39    InvalidVersion(String),
40
41    /// Checksum mismatch
42    /// 校验和不匹配
43    #[error("Checksum mismatch for version {version}: expected {expected}, got {actual}")]
44    ChecksumMismatch {
45        version: String,
46        expected: i64,
47        actual: i64,
48    },
49
50    /// Migration already applied
51    /// 迁移已应用
52    #[error("Migration {version} already applied")]
53    AlreadyApplied { version: String },
54
55    /// Out of order migration
56    /// 无序迁移
57    #[error("Out of order migration: {0}")]
58    OutOfOrder(String),
59
60    /// IO error
61    /// IO 错误
62    #[error("IO error: {0}")]
63    Io(#[from] std::io::Error),
64}
65
66/// Flyway result type
67/// Flyway 结果类型
68pub type Result<T> = std::result::Result<T, FlywayError>;