Skip to content

Commit

Permalink
migration: schema helper (#2099)
Browse files Browse the repository at this point in the history
* Adapted loco-rs/schema.rs

* avoid `&mut ColumnDef` after upgraded to sea-query 0.31.0

* refactoring

* rewrite schema.rs

* revert

* fmt

* fix

* loco_example: pin loco-rs version

* refactor
  • Loading branch information
billy1624 authored Feb 6, 2024
1 parent cef380b commit 94403b5
Show file tree
Hide file tree
Showing 21 changed files with 1,076 additions and 577 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,15 +11,9 @@ impl MigrationTrait for Migration {
Table::create()
.table(Posts::Table)
.if_not_exists()
.col(
ColumnDef::new(Posts::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Posts::Title).string().not_null())
.col(ColumnDef::new(Posts::Text).string().not_null())
.col(pk_auto(Posts::Id))
.col(string(Posts::Title))
.col(string(Posts::Text))
.to_owned(),
)
.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,15 +11,9 @@ impl MigrationTrait for Migration {
Table::create()
.table(Posts::Table)
.if_not_exists()
.col(
ColumnDef::new(Posts::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Posts::Title).string().not_null())
.col(ColumnDef::new(Posts::Text).string().not_null())
.col(pk_auto(Posts::Id))
.col(string(Posts::Title))
.col(string(Posts::Text))
.to_owned(),
)
.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,15 +11,9 @@ impl MigrationTrait for Migration {
Table::create()
.table(Posts::Table)
.if_not_exists()
.col(
ColumnDef::new(Posts::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Posts::Title).string().not_null())
.col(ColumnDef::new(Posts::Text).string().not_null())
.col(pk_auto(Posts::Id))
.col(string(Posts::Title))
.col(string(Posts::Text))
.to_owned(),
)
.await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -9,31 +9,25 @@ impl MigrationTrait for Migration {
manager
.create_table(
Table::create()
.table(Notes::Table)
.table(Posts::Table)
.if_not_exists()
.col(
ColumnDef::new(Notes::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Notes::Title).string().not_null())
.col(ColumnDef::new(Notes::Text).string().not_null())
.col(pk_auto(Posts::Id))
.col(string(Posts::Title))
.col(string(Posts::Text))
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Notes::Table).to_owned())
.drop_table(Table::drop().table(Posts::Table).to_owned())
.await
}
}

#[derive(DeriveIden)]
enum Notes {
enum Posts {
Table,
Id,
Title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,15 +11,9 @@ impl MigrationTrait for Migration {
Table::create()
.table(Posts::Table)
.if_not_exists()
.col(
ColumnDef::new(Posts::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Posts::Title).string().not_null())
.col(ColumnDef::new(Posts::Text).string().not_null())
.col(pk_auto(Posts::Id))
.col(string(Posts::Title))
.col(string(Posts::Text))
.to_owned(),
)
.await
Expand Down
Loading

0 comments on commit 94403b5

Please sign in to comment.