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> {
// Where each repository counts its tickets from. The number comes
// from the repository rather than from counting the tickets that
// still exist, because a deleted ticket is still talked about by its
// number: the number cannot come to mean another ticket.
//
// `NOT NULL DEFAULT 1` is written as one statement rather than added
// in two, so the column is never there without a number to hand the
// first ticket.
manager
.get_connection()
.execute_unprepared(
"ALTER TABLE repositories \
ADD COLUMN next_ticket_number integer NOT NULL DEFAULT 1",
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Nothing of the column is indexed or depended on, so SQLite can
// take it away again; the tickets that were numbered with it go with
// the tables `m20261018_000005` drops.
manager
.get_connection()
.execute_unprepared("ALTER TABLE repositories DROP COLUMN next_ticket_number")
.await?;
Ok(())
}
}