1.1 KiB · text History 263b40b
//! Reactions per category: on (all the active types, or only some) or off.
//!
//! * `reactions_enabled` — off hides reactions in the category and refuses
//!   new ones; existing rows are kept, so turning it back on restores them.
//! * `reaction_keys` — NULL: every active reaction type; else the
//!   comma-separated `reaction_types.key`s offered here.
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = r#"
ALTER TABLE categories
    ADD COLUMN reactions_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    ADD COLUMN reaction_keys TEXT NULL;
"#;

const DOWN: &str = r#"
ALTER TABLE categories
    DROP COLUMN IF EXISTS reaction_keys,
    DROP COLUMN IF EXISTS reactions_enabled;
"#;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.get_connection().execute_unprepared(UP).await.map(|_| ())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.get_connection().execute_unprepared(DOWN).await.map(|_| ())
    }
}