use std::hash::Hash;
use crate::operation::Operation;
#[allow(clippy::module_name_repetitions)]
pub trait Migration<DB>: Send + Sync {
fn app(&self) -> &str;
fn name(&self) -> &str;
fn parents(&self) -> Vec<Box<dyn Migration<DB>>>;
fn operations(&self) -> Vec<Box<dyn Operation<DB>>>;
fn replaces(&self) -> Vec<Box<dyn Migration<DB>>> {
vec![]
}
fn run_before(&self) -> Vec<Box<dyn Migration<DB>>> {
vec![]
}
fn is_atomic(&self) -> bool {
true
}
}
impl<DB> PartialEq for dyn Migration<DB>
where
DB: sqlx::Database,
{
fn eq(&self, other: &Self) -> bool {
self.app() == other.app() && self.name() == other.name()
}
}
impl<DB> Eq for dyn Migration<DB> where DB: sqlx::Database {}
impl<DB> Hash for dyn Migration<DB>
where
DB: sqlx::Database,
{
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.app().hash(state);
self.name().hash(state);
}
}
#[derive(sqlx::FromRow, Clone)]
pub struct AppliedMigrationSqlRow {
id: i32,
app: String,
name: String,
applied_time: String,
}
impl AppliedMigrationSqlRow {
#[must_use]
pub fn id(&self) -> i32 {
self.id
}
#[must_use]
pub fn applied_time(&self) -> &str {
&self.applied_time
}
}
impl<DB> PartialEq<Box<dyn Migration<DB>>> for AppliedMigrationSqlRow
where
DB: sqlx::Database,
{
fn eq(&self, other: &Box<dyn Migration<DB>>) -> bool {
self.app == other.app() && self.name == other.name()
}
}