//! SeaORM migration: add push subscription fields to user_notification

use sea_orm_migration::prelude::*;

pub struct Migration;

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

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let sql = include_str!("sql/m20260420_000002_add_push_subscription.sql");
        super::execute_sql(manager, sql).await
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .get_connection()
            .execute_raw(sea_orm::Statement::from_string(
                sea_orm::DbBackend::Postgres,
                r#"
                ALTER TABLE user_notification
                    DROP COLUMN IF EXISTS push_subscription_endpoint,
                    DROP COLUMN IF EXISTS push_subscription_keys_p256dh,
                    DROP COLUMN IF EXISTS push_subscription_keys_auth;
                "#.to_string(),
            ))
            .await?;
        Ok(())
    }
}
