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, "products",
            &[
            
            ("id", ColType::PkAuto),
            
            ("name", ColType::String),
            ("slug", ColType::StringUniq),
            ("description", ColType::TextNull),
            ("price_cents", ColType::BigInteger),
            ("currency", ColType::StringWithDefault("EUR".to_string())),
            ("sku", ColType::StringNull),
            ("stock", ColType::IntegerWithDefault(0)),
            ("view_count", ColType::IntegerWithDefault(0)),
            ("published", ColType::BooleanWithDefault(false)),
            ("published_at", ColType::TimestampWithTimeZoneNull),
            ],
            &[
            ("category?", ""),
            ]
        ).await
    }

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