use loco_rs::schema::*;
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
        create_table(
            m,
            "books",
            &[
                ("id", ColType::PkAuto),
                ("title", ColType::String),
                ("author", ColType::String),
                ("description", ColType::TextNull),
                ("cover", ColType::StringNull),
                ("content", ColType::Text),
            ],
            &[],
        )
        .await?;
        Ok(())
    }

    async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
        drop_table(m, "books").await?;
        Ok(())
    }
}
