1007 B · text History 0c61284
//! The layouts are called Classic and Focus: store `classic` instead of
//! `list` (the app still reads `list` as an alias).
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let db = manager.get_connection();
        db.execute_unprepared("UPDATE users SET preferred_view = 'classic' WHERE preferred_view IN ('list', '')").await?;
        db.execute_unprepared("ALTER TABLE users ALTER COLUMN preferred_view SET DEFAULT 'classic'").await?;
        Ok(())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let db = manager.get_connection();
        db.execute_unprepared("UPDATE users SET preferred_view = 'list' WHERE preferred_view = 'classic'").await?;
        db.execute_unprepared("ALTER TABLE users ALTER COLUMN preferred_view SET DEFAULT 'list'").await?;
        Ok(())
    }
}