Testing & fixup
This commit is contained in:
parent
31fae07bc1
commit
36886e74cd
@ -170,11 +170,11 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{sea_query::*, tests_cfg::*, DbBackend, Schema};
|
||||
use crate::{sea_query::*, tests_cfg::*, DbBackend, EntityName, Schema};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_create_table_from_entity() {
|
||||
fn test_mysql_create_table_from_entity() {
|
||||
let schema = Schema::new(DbBackend::MySql);
|
||||
assert_eq!(
|
||||
schema
|
||||
@ -217,4 +217,94 @@ mod tests {
|
||||
.to_string(MysqlQueryBuilder)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_postgres_create_table_from_entity() {
|
||||
let schema = Schema::new(DbBackend::Postgres);
|
||||
assert_eq!(
|
||||
schema
|
||||
.create_table_from_entity(CakeFillingPrice)
|
||||
.to_string(PostgresQueryBuilder),
|
||||
Table::create()
|
||||
.table(CakeFillingPrice.table_ref())
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::CakeId)
|
||||
.integer()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::FillingId)
|
||||
.integer()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::Price)
|
||||
.decimal()
|
||||
.not_null()
|
||||
)
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.name("pk-cake_filling_price")
|
||||
.col(cake_filling_price::Column::CakeId)
|
||||
.col(cake_filling_price::Column::FillingId)
|
||||
.primary()
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKeyCreateStatement::new()
|
||||
.name("fk-cake_filling_price-cake_filling")
|
||||
.from_tbl(CakeFillingPrice)
|
||||
.from_col(cake_filling_price::Column::CakeId)
|
||||
.from_col(cake_filling_price::Column::FillingId)
|
||||
.to_tbl(CakeFilling)
|
||||
.to_col(cake_filling::Column::CakeId)
|
||||
.to_col(cake_filling::Column::FillingId)
|
||||
)
|
||||
.to_string(PostgresQueryBuilder)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sqlite_create_table_from_entity() {
|
||||
let schema = Schema::new(DbBackend::Sqlite);
|
||||
assert_eq!(
|
||||
schema
|
||||
.create_table_from_entity(CakeFillingPrice)
|
||||
.to_string(SqliteQueryBuilder),
|
||||
Table::create()
|
||||
.table(CakeFillingPrice)
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::CakeId)
|
||||
.integer()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::FillingId)
|
||||
.integer()
|
||||
.not_null()
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(cake_filling_price::Column::Price)
|
||||
.decimal()
|
||||
.not_null()
|
||||
)
|
||||
.primary_key(
|
||||
Index::create()
|
||||
.name("pk-cake_filling_price")
|
||||
.col(cake_filling_price::Column::CakeId)
|
||||
.col(cake_filling_price::Column::FillingId)
|
||||
.primary()
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKeyCreateStatement::new()
|
||||
.name("fk-cake_filling_price-cake_filling")
|
||||
.from_tbl(CakeFillingPrice)
|
||||
.from_col(cake_filling_price::Column::CakeId)
|
||||
.from_col(cake_filling_price::Column::FillingId)
|
||||
.to_tbl(CakeFilling)
|
||||
.to_col(cake_filling::Column::CakeId)
|
||||
.to_col(cake_filling::Column::FillingId)
|
||||
)
|
||||
.to_string(SqliteQueryBuilder)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "active_enum")]
|
||||
#[sea_orm(schema_name = "public", table_name = "active_enum")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
|
@ -3,7 +3,8 @@ pub use super::super::bakery_chain::*;
|
||||
use super::*;
|
||||
use crate::common::setup::{create_enum, create_table, create_table_without_asserts};
|
||||
use sea_orm::{
|
||||
error::*, sea_query, ConnectionTrait, DatabaseConnection, DbBackend, DbConn, ExecResult,
|
||||
error::*, sea_query, ConnectionTrait, DatabaseConnection, DbBackend, DbConn, EntityName,
|
||||
ExecResult,
|
||||
};
|
||||
use sea_query::{extension::postgres::Type, Alias, ColumnDef, ForeignKeyCreateStatement};
|
||||
|
||||
@ -146,7 +147,7 @@ pub async fn create_active_enum_table(db: &DbConn) -> Result<ExecResult, DbErr>
|
||||
DbBackend::Postgres => tea_col.custom(tea_enum),
|
||||
};
|
||||
let create_table_stmt = sea_query::Table::create()
|
||||
.table(active_enum::Entity)
|
||||
.table(active_enum::Entity.table_ref())
|
||||
.col(
|
||||
ColumnDef::new(active_enum::Column::Id)
|
||||
.integer()
|
||||
|
Loading…
x
Reference in New Issue
Block a user