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,
            "reading_records",
            &[
                ("id", ColType::PkAuto),
                ("user_id", ColType::Integer),
                ("book_id", ColType::Integer),
                ("last_read_chapter", ColType::StringNull),
                ("last_read_position", ColType::IntegerNull),
                ("read_percentage", ColType::DoubleNull),
            ],
            &[],
        )
        .await?;
        Ok(())
    }

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