This commit is contained in:
pavel 2026-02-10 18:34:43 +01:00
commit 0fa627ca6d
18 changed files with 6192 additions and 0 deletions

11
migration/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "migration"
version = "0.1.0"
edition = "2021"
[dependencies]
sea-orm-migration = "1.1"
[lib]
name = "migration"
path = "src/lib.rs"

16
migration/src/lib.rs Normal file
View file

@ -0,0 +1,16 @@
pub use sea_orm_migration::prelude::*;
mod m20220101_000001_create_table;
mod m20260210_000002_add_answer_column;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220101_000001_create_table::Migration),
Box::new(m20260210_000002_add_answer_column::Migration),
]
}
}

View file

@ -0,0 +1,43 @@
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> {
manager
.create_table(
Table::create()
.table(Tasks::Table)
.if_not_exists()
.col(ColumnDef::new(Tasks::Id).uuid().not_null().primary_key())
.col(ColumnDef::new(Tasks::Goal).string().not_null())
.col(ColumnDef::new(Tasks::Status).string().not_null())
.col(ColumnDef::new(Tasks::Logs).text().not_null())
.col(
ColumnDef::new(Tasks::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Tasks::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Tasks {
Table,
Id,
Goal,
Status,
Logs,
CreatedAt,
}

View file

@ -0,0 +1,35 @@
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> {
manager
.alter_table(
Table::alter()
.table(Tasks::Table)
.add_column(ColumnDef::new(Tasks::Answer).text().null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Tasks::Table)
.drop_column(Tasks::Answer)
.to_owned(),
)
.await
}
}
#[derive(DeriveIden)]
enum Tasks {
Table,
Answer,
}