use crate::app::context::AppContext;
use async_trait::async_trait;
use axum_core::extract::FromRef;
use serde_derive::Serialize;
use strum_macros::{EnumString, IntoStaticStr};
#[cfg(feature = "db-diesel")]
pub mod diesel;
pub mod registry;
#[cfg(feature = "db-sea-orm")]
pub mod sea_orm;
#[serde_with::skip_serializing_none]
#[derive(Debug, Serialize, bon::Builder)]
#[cfg_attr(feature = "cli", derive(clap::Parser))]
#[non_exhaustive]
pub struct UpArgs {
#[cfg_attr(feature = "cli", clap(short = 'n', long))]
pub steps: Option<usize>,
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Serialize, bon::Builder)]
#[cfg_attr(feature = "cli", derive(clap::Parser))]
#[non_exhaustive]
pub struct DownArgs {
#[cfg_attr(feature = "cli", clap(short = 'n', long))]
pub steps: Option<usize>,
}
#[serde_with::skip_serializing_none]
#[derive(Debug, Serialize, bon::Builder)]
pub struct MigrationInfo {
pub name: String,
pub status: MigrationStatus,
}
#[derive(Debug, Serialize, EnumString, IntoStaticStr)]
pub enum MigrationStatus {
Applied,
Pending,
}
#[cfg_attr(test, mockall::automock(type Error = crate::error::Error;))]
#[async_trait]
pub trait Migrator<S>: Send + Sync
where
S: 'static + Send + Sync + Clone,
AppContext: FromRef<S>,
{
type Error: Send + Sync + std::error::Error;
async fn up(&self, state: &S, args: &UpArgs) -> Result<usize, Self::Error>;
async fn down(&self, state: &S, args: &DownArgs) -> Result<usize, Self::Error>;
async fn status(&self, state: &S) -> Result<Vec<MigrationInfo>, Self::Error>;
}