use sea_orm_migration::prelude::*;

/// Defensive migration: adds columns that may be missing on `repos` if the table
/// already existed before the sea_orm migration ran.
#[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();

        let _ = db
            .execute_unprepared("ALTER TABLE repos ADD COLUMN token TEXT NOT NULL DEFAULT ''")
            .await;

        Ok(())
    }

    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
        Ok(())
    }
}
