Migration shouldn't depends on symbol provided by entity crate (#785)
* Migration shouldn't depends on symbol provided by entity crate * Add docs
This commit is contained in:
parent
5cf4d6022b
commit
9b41f1c1b1
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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: EntityTrait>(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: EntityTrait>(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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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"] }
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 = "<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
|
||||
]
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user