use std::hash::Hash;
use chrono::{DateTime, Utc};
use crate::operation::OperationTrait;
#[allow(clippy::module_name_repetitions)]
pub trait MigrationTrait<DB>: Send + Sync {
fn app(&self) -> &str;
fn name(&self) -> &str;
fn parents(&self) -> Vec<Box<dyn MigrationTrait<DB>>> {
vec![]
}
fn operations(&self) -> Vec<Box<dyn OperationTrait<DB>>> {
vec![]
}
fn replaces(&self) -> Vec<Box<dyn MigrationTrait<DB>>> {
vec![]
}
fn run_before(&self) -> Vec<Box<dyn MigrationTrait<DB>>> {
vec![]
}
fn is_atomic(&self) -> bool {
true
}
}
impl<DB> PartialEq for dyn MigrationTrait<DB>
where
DB: sqlx::Database,
{
fn eq(&self, other: &Self) -> bool {
self.app() == other.app() && self.name() == other.name()
}
}
impl<DB> Eq for dyn MigrationTrait<DB> where DB: sqlx::Database {}
impl<DB> Hash for dyn MigrationTrait<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: DateTime<Utc>,
}
impl AppliedMigrationSqlRow {
#[must_use]
pub fn id(&self) -> i32 {
self.id
}
#[must_use]
pub fn applied_time(&self) -> DateTime<Utc> {
self.applied_time
}
}
impl<DB> PartialEq<Box<dyn MigrationTrait<DB>>> for AppliedMigrationSqlRow
where
DB: sqlx::Database,
{
fn eq(&self, other: &Box<dyn MigrationTrait<DB>>) -> bool {
self.app == other.app() && self.name == other.name()
}
}