Test suite: drop table if exists, instead of create table if not exists
This commit is contained in:
parent
fc769a89df
commit
558cf5904a
@ -116,7 +116,7 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.table(entity).if_not_exists().take()
|
stmt.table(entity).take()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -130,7 +130,6 @@ mod tests {
|
|||||||
Schema::create_table_from_entity(CakeFillingPrice).to_string(MysqlQueryBuilder),
|
Schema::create_table_from_entity(CakeFillingPrice).to_string(MysqlQueryBuilder),
|
||||||
Table::create()
|
Table::create()
|
||||||
.table(CakeFillingPrice)
|
.table(CakeFillingPrice)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(cake_filling_price::Column::CakeId)
|
ColumnDef::new(cake_filling_price::Column::CakeId)
|
||||||
.integer()
|
.integer()
|
||||||
|
@ -1,18 +1,28 @@
|
|||||||
pub use super::super::bakery_chain::*;
|
pub use super::super::bakery_chain::*;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use sea_orm::{error::*, sea_query, DbConn, EntityTrait, ExecResult, Schema};
|
use sea_orm::{error::*, sea_query, DbConn, EntityTrait, ExecResult, Schema};
|
||||||
use sea_query::{ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement};
|
use sea_query::{
|
||||||
|
Alias, ColumnDef, ForeignKey, ForeignKeyAction, Index, Table, TableCreateStatement,
|
||||||
|
};
|
||||||
|
|
||||||
async fn create_table<E>(
|
async fn create_table<E>(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
stmt: &TableCreateStatement,
|
create: &TableCreateStatement,
|
||||||
entity: E,
|
entity: E,
|
||||||
) -> Result<ExecResult, DbErr>
|
) -> Result<ExecResult, DbErr>
|
||||||
where
|
where
|
||||||
E: EntityTrait,
|
E: EntityTrait,
|
||||||
{
|
{
|
||||||
let builder = db.get_database_backend();
|
let builder = db.get_database_backend();
|
||||||
let stmt = builder.build(stmt);
|
let stmt = builder.build(
|
||||||
|
Table::drop()
|
||||||
|
.table(Alias::new(create.get_table_name().unwrap().as_ref()))
|
||||||
|
.if_exists()
|
||||||
|
.cascade(),
|
||||||
|
);
|
||||||
|
db.execute(stmt).await?;
|
||||||
|
|
||||||
|
let stmt = builder.build(create);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
builder.build(&Schema::create_table_from_entity(entity)),
|
builder.build(&Schema::create_table_from_entity(entity)),
|
||||||
stmt
|
stmt
|
||||||
@ -23,7 +33,6 @@ where
|
|||||||
pub async fn create_bakery_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_bakery_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(bakery::Entity)
|
.table(bakery::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(bakery::Column::Id)
|
ColumnDef::new(bakery::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -45,7 +54,6 @@ pub async fn create_bakery_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(baker::Entity)
|
.table(baker::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(baker::Column::Id)
|
ColumnDef::new(baker::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -76,7 +84,6 @@ pub async fn create_baker_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_customer_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_customer_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(customer::Entity)
|
.table(customer::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(customer::Column::Id)
|
ColumnDef::new(customer::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -94,7 +101,6 @@ pub async fn create_customer_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(order::Entity)
|
.table(order::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(order::Column::Id)
|
ColumnDef::new(order::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -142,7 +148,6 @@ pub async fn create_order_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(lineitem::Entity)
|
.table(lineitem::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(lineitem::Column::Id)
|
ColumnDef::new(lineitem::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -194,7 +199,6 @@ pub async fn create_lineitem_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(cakes_bakers::Entity)
|
.table(cakes_bakers::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(cakes_bakers::Column::CakeId)
|
ColumnDef::new(cakes_bakers::Column::CakeId)
|
||||||
.integer()
|
.integer()
|
||||||
@ -235,7 +239,6 @@ pub async fn create_cakes_bakers_table(db: &DbConn) -> Result<ExecResult, DbErr>
|
|||||||
pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = Table::create()
|
let stmt = Table::create()
|
||||||
.table(cake::Entity)
|
.table(cake::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(cake::Column::Id)
|
ColumnDef::new(cake::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
@ -272,7 +275,6 @@ pub async fn create_cake_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = sea_query::Table::create()
|
let stmt = sea_query::Table::create()
|
||||||
.table(metadata::Entity)
|
.table(metadata::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(metadata::Column::Uuid)
|
ColumnDef::new(metadata::Column::Uuid)
|
||||||
.uuid()
|
.uuid()
|
||||||
@ -290,7 +292,6 @@ pub async fn create_metadata_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
|||||||
pub async fn create_log_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
pub async fn create_log_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||||
let stmt = sea_query::Table::create()
|
let stmt = sea_query::Table::create()
|
||||||
.table(applog::Entity)
|
.table(applog::Entity)
|
||||||
.if_not_exists()
|
|
||||||
.col(
|
.col(
|
||||||
ColumnDef::new(applog::Column::Id)
|
ColumnDef::new(applog::Column::Id)
|
||||||
.integer()
|
.integer()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user