test
This commit is contained in:
parent
6a1cddbb47
commit
0fa627ca6d
18 changed files with 6192 additions and 0 deletions
16
migration/src/lib.rs
Normal file
16
migration/src/lib.rs
Normal 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),
|
||||
]
|
||||
}
|
||||
}
|
||||
43
migration/src/m20220101_000001_create_table.rs
Normal file
43
migration/src/m20220101_000001_create_table.rs
Normal 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,
|
||||
}
|
||||
35
migration/src/m20260210_000002_add_answer_column.rs
Normal file
35
migration/src/m20260210_000002_add_answer_column.rs
Normal 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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue