1.8 KiB · text History d9460a8
use sea_orm::sea_query::{ColumnDef, Index, Table};
use sea_orm::{DbErr, DeriveIden};
use sea_orm_migration::{MigrationName, MigrationTrait, SchemaManager};

pub struct Migration;

impl MigrationName for Migration {
    fn name(&self) -> &str {
        "m_20261019_000013_create_calendar"
    }
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(Calendar::Table)
                    .col(
                        ColumnDef::new(Calendar::Id)
                            .integer()
                            .not_null()
                            .auto_increment()
                            .primary_key(),
                    )
                    .col(ColumnDef::new(Calendar::Key).string().not_null())
                    .col(ColumnDef::new(Calendar::Enabled).boolean().not_null())
                    .col(ColumnDef::new(Calendar::DateIns).date().not_null())
                    .col(ColumnDef::new(Calendar::DateUp).date().not_null())
                    .to_owned(),
            )
            .await?;
        manager
            .create_index(
                Index::create()
                    .name("idx_calendar_key")
                    .table(Calendar::Table)
                    .col(Calendar::Key)
                    .unique()
                    .to_owned(),
            )
            .await
    }
    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(Table::drop().table(Calendar::Table).to_owned())
            .await
    }
}

/// Which built-in holiday calendars are switched on, keyed like "us" or "us-ny"
#[derive(DeriveIden)]
pub enum Calendar {
    Table,
    Id,
    Key,
    Enabled,

    DateIns,
    DateUp,
}