Refactoring
This commit is contained in:
parent
cef51ddd3f
commit
0f904e02f0
@ -368,9 +368,7 @@ impl From<ColumnType> for sea_query::ColumnType {
|
||||
sea_query::ColumnType::Custom(sea_query::SeaRc::new(sea_query::Alias::new(&s)))
|
||||
}
|
||||
ColumnType::Uuid => sea_query::ColumnType::Uuid,
|
||||
ColumnType::Enum(name, variants) => {
|
||||
sea_query::ColumnType::Enum(name, variants)
|
||||
}
|
||||
ColumnType::Enum(name, variants) => sea_query::ColumnType::Enum(name, variants),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,24 +127,17 @@ pub async fn create_byte_primary_key_table(db: &DbConn) -> Result<ExecResult, Db
|
||||
|
||||
pub async fn create_active_enum_table(db: &DbConn) -> Result<ExecResult, DbErr> {
|
||||
let db_backend = db.get_database_backend();
|
||||
let tea_enum = Alias::new("tea");
|
||||
|
||||
let create_enum_stmts = match db_backend {
|
||||
DbBackend::MySql | DbBackend::Sqlite => Vec::new(),
|
||||
DbBackend::Postgres => vec![Type::create()
|
||||
.as_enum(tea_enum.clone())
|
||||
.as_enum(Alias::new("tea"))
|
||||
.values(vec![Alias::new("EverydayTea"), Alias::new("BreakfastTea")])
|
||||
.to_owned()],
|
||||
};
|
||||
|
||||
create_enum(db, &create_enum_stmts, ActiveEnum).await?;
|
||||
|
||||
let mut tea_col = ColumnDef::new(active_enum::Column::Tea);
|
||||
match db_backend {
|
||||
DbBackend::MySql => tea_col.custom(Alias::new("ENUM('EverydayTea', 'BreakfastTea')")),
|
||||
DbBackend::Sqlite => tea_col.text(),
|
||||
DbBackend::Postgres => tea_col.custom(tea_enum),
|
||||
};
|
||||
let create_table_stmt = sea_query::Table::create()
|
||||
.table(active_enum::Entity)
|
||||
.col(
|
||||
@ -156,7 +149,10 @@ pub async fn create_active_enum_table(db: &DbConn) -> Result<ExecResult, DbErr>
|
||||
)
|
||||
.col(ColumnDef::new(active_enum::Column::Category).string_len(1))
|
||||
.col(ColumnDef::new(active_enum::Column::Color).integer())
|
||||
.col(&mut tea_col)
|
||||
.col(
|
||||
ColumnDef::new(active_enum::Column::Tea)
|
||||
.enumeration("tea", vec!["EverydayTea", "BreakfastTea"]),
|
||||
)
|
||||
.to_owned();
|
||||
|
||||
create_table(db, &create_table_stmt, ActiveEnum).await
|
||||
|
Loading…
x
Reference in New Issue
Block a user