diff --git a/examples/actix3_example/migration/Cargo.toml b/examples/actix3_example/migration/Cargo.toml index 883afc81..2ba5e0a1 100644 --- a/examples/actix3_example/migration/Cargo.toml +++ b/examples/actix3_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix3_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/actix_example/migration/Cargo.toml b/examples/actix_example/migration/Cargo.toml index 2655a479..c113ac97 100644 --- a/examples/actix_example/migration/Cargo.toml +++ b/examples/actix_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/actix_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/axum_example/migration/Cargo.toml b/examples/axum_example/migration/Cargo.toml index d22b708a..d816bce1 100644 --- a/examples/axum_example/migration/Cargo.toml +++ b/examples/axum_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/axum_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/graphql_example/migration/Cargo.toml b/examples/graphql_example/migration/Cargo.toml index 78729b11..8101cb8b 100644 --- a/examples/graphql_example/migration/Cargo.toml +++ b/examples/graphql_example/migration/Cargo.toml @@ -10,7 +10,6 @@ path = "src/lib.rs" [dependencies] dotenv = "0.15.0" -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs index 9a69fe7a..2bb20e11 100644 --- a/examples/graphql_example/migration/src/m20220101_000001_create_table.rs +++ b/examples/graphql_example/migration/src/m20220101_000001_create_table.rs @@ -1,22 +1,7 @@ -use entity::note; -use sea_orm::{DbBackend, EntityTrait, Schema}; use sea_orm_migration::prelude::*; pub struct Migration; -fn get_seaorm_create_stmt(e: E) -> TableCreateStatement { - let schema = Schema::new(DbBackend::Sqlite); - - schema - .create_table_from_entity(e) - .if_not_exists() - .to_owned() -} - -fn get_seaorm_drop_stmt(e: E) -> TableDropStatement { - Table::drop().table(e).if_exists().to_owned() -} - impl MigrationName for Migration { fn name(&self) -> &str { "m20220101_000001_create_table" @@ -26,22 +11,42 @@ impl MigrationName for Migration { #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - let stmts = vec![get_seaorm_create_stmt(note::Entity)]; - - for stmt in stmts { - manager.create_table(stmt.to_owned()).await?; - } - - Ok(()) + manager + .create_table( + Table::create() + .table(Notes::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()) + .to_owned(), + ) + .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - let stmts = vec![get_seaorm_drop_stmt(note::Entity)]; - - for stmt in stmts { - manager.drop_table(stmt.to_owned()).await?; - } - - Ok(()) + manager + .drop_table(Table::drop().table(Notes::Table).to_owned()) + .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Notes { + Table, + Id, + Title, + Text, +} diff --git a/examples/jsonrpsee_example/migration/Cargo.toml b/examples/jsonrpsee_example/migration/Cargo.toml index 82e155f9..d860e7e3 100644 --- a/examples/jsonrpsee_example/migration/Cargo.toml +++ b/examples/jsonrpsee_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/jsonrpsee_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/poem_example/migration/Cargo.toml b/examples/poem_example/migration/Cargo.toml index 82e155f9..d860e7e3 100644 --- a/examples/poem_example/migration/Cargo.toml +++ b/examples/poem_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/poem_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/rocket_example/migration/Cargo.toml b/examples/rocket_example/migration/Cargo.toml index 8e51eed6..757b5f29 100644 --- a/examples/rocket_example/migration/Cargo.toml +++ b/examples/rocket_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } rocket = { version = "0.5.0-rc.1" } async-std = { version = "^1", features = ["attributes", "tokio1"] } diff --git a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/rocket_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/examples/tonic_example/migration/Cargo.toml b/examples/tonic_example/migration/Cargo.toml index a78ca8eb..b3b55c13 100644 --- a/examples/tonic_example/migration/Cargo.toml +++ b/examples/tonic_example/migration/Cargo.toml @@ -9,7 +9,6 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] diff --git a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs index 097c2267..034cd9f6 100644 --- a/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs +++ b/examples/tonic_example/migration/src/m20220120_000001_create_post_table.rs @@ -1,4 +1,3 @@ -use entity::post::*; use sea_orm_migration::prelude::*; pub struct Migration; @@ -15,17 +14,17 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Entity) + .table(Post::Table) .if_not_exists() .col( - ColumnDef::new(Column::Id) + ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) - .col(ColumnDef::new(Column::Title).string().not_null()) - .col(ColumnDef::new(Column::Text).string().not_null()) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) .to_owned(), ) .await @@ -33,7 +32,21 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Entity).to_owned()) + .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/sea-orm-cli/template/migration/_Cargo.toml b/sea-orm-cli/template/migration/_Cargo.toml index 70817c3c..61a6f6b5 100644 --- a/sea-orm-cli/template/migration/_Cargo.toml +++ b/sea-orm-cli/template/migration/_Cargo.toml @@ -9,7 +9,14 @@ name = "migration" path = "src/lib.rs" [dependencies] -entity = { path = "../entity" } +async-std = { version = "^1", features = ["attributes", "tokio1"] } [dependencies.sea-orm-migration] version = "" +features = [ + # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. + # View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime. + # e.g. + # "runtime-tokio-rustls", # `ASYNC_RUNTIME` featrure + # "sqlx-postgres", # `DATABASE_DRIVER` feature +] diff --git a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs index b4dc891e..c114f9a8 100644 --- a/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs +++ b/sea-orm-cli/template/migration/src/m20220101_000001_create_table.rs @@ -11,10 +11,48 @@ impl MigrationName for Migration { #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - todo!() + // Replace the sample below with your own migration scripts + todo!(); + + manager + .create_table( + Table::create() + .table(Post::Table) + .if_not_exists() + .col( + ColumnDef::new(Post::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Post::Title).string().not_null()) + .col(ColumnDef::new(Post::Text).string().not_null()) + .to_owned(), + ) + .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - todo!() + // Replace the sample below with your own migration scripts + todo!(); + + manager + .drop_table(Table::drop().table(Post::Table).to_owned()) + .await } } + +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Post { + Table, + Id, + Title, + Text, +} diff --git a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs index bc70ba3b..044fa264 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000001_create_cake_table.rs @@ -35,6 +35,12 @@ impl MigrationTrait for Migration { } } +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Cake { Table, diff --git a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs index 51c21321..65a0857a 100644 --- a/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs +++ b/sea-orm-migration/tests/migrator/m20220118_000002_create_fruit_table.rs @@ -54,6 +54,12 @@ impl MigrationTrait for Migration { } } +/// `Iden` is a trait for identifiers used in any query statement. +/// +/// Commonly implemented by Enum where each Enum represents a table found in a database, +/// and its variants include table name and column name. +/// +/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] pub enum Fruit { Table,