1use std::borrow::Cow;
2
3use thiserror::Error;
4
5use crate::MigrationError;
6
7#[derive(Debug, Error)]
9pub enum Error {
10 #[error("{0}")]
11 Database(sqlx::Error),
12 #[error(
13 "invalid version specified: {version} (available versions: {min_version}-{max_version})"
14 )]
15 InvalidVersion {
16 version: u64,
17 min_version: u64,
18 max_version: u64,
19 },
20 #[error("there were no local migrations found")]
21 NoMigrations,
22 #[error("missing migrations ({local_count} local, but {db_count} already applied)")]
23 MissingMigrations { local_count: usize, db_count: usize },
24 #[error("error applying migration: {error}")]
25 Migration {
26 name: Cow<'static, str>,
27 version: u64,
28 error: MigrationError,
29 },
30 #[error("error reverting migration: {error}")]
31 Revert {
32 name: Cow<'static, str>,
33 version: u64,
34 error: MigrationError,
35 },
36 #[error("expected migration {version} to be {local_name} but it was applied as {db_name}")]
37 NameMismatch {
38 version: u64,
39 local_name: Cow<'static, str>,
40 db_name: Cow<'static, str>,
41 },
42 #[error("invalid checksum for migration {version}")]
43 ChecksumMismatch {
44 version: u64,
45 local_checksum: Cow<'static, [u8]>,
46 db_checksum: Cow<'static, [u8]>,
47 },
48}
49
50impl From<sqlx::Error> for Error {
51 fn from(err: sqlx::Error) -> Self {
52 Self::Database(err)
53 }
54}