use crate::{DbExecutor, DbResult};
use chrono::{DateTime, Utc};
use serde::Serialize;
use sqlx::prelude::FromRow;
#[derive(Debug, Clone, FromRow, Serialize)]
pub struct RootMigration {
pub name: String,
pub applied_at: DateTime<Utc>,
}
pub struct CreateRootMigration {
pub name: String,
pub applied_at: DateTime<Utc>,
}
impl RootMigration {
pub async fn create(db: impl DbExecutor<'_>, create: CreateRootMigration) -> DbResult<()> {
sqlx::query(
r#"
INSERT INTO "docbox_root_migrations" ("name", "applied_at")
VALUES ($1, $2)
"#,
)
.bind(create.name)
.bind(create.applied_at)
.execute(db)
.await?;
Ok(())
}
pub async fn all(db: impl DbExecutor<'_>) -> DbResult<Vec<RootMigration>> {
sqlx::query_as(r#"SELECT * FROM "docbox_root_migrations""#)
.fetch_all(db)
.await
}
}