From 4b1cac7f354242dac9af2b9fa6698e9e30ef3f07 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 25 Oct 2021 17:05:27 +0800 Subject: [PATCH] Refactoring --- tests/common/features/schema.rs | 49 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/common/features/schema.rs b/tests/common/features/schema.rs index 0eeb5c04..f630ccb7 100644 --- a/tests/common/features/schema.rs +++ b/tests/common/features/schema.rs @@ -132,34 +132,31 @@ pub async fn create_active_enum_table(db: &DbConn) -> Result .col(&mut tea_col) .to_owned(); - match db_backend { - DbBackend::Postgres => { - let drop_type_stmt = Type::drop() - .name(tea_enum.clone()) - .cascade() - .if_exists() - .to_owned(); - let (sql, values) = drop_type_stmt.build(PostgresQueryBuilder); - let stmt = Statement::from_sql_and_values(db.get_database_backend(), &sql, values); - db.execute(stmt).await?; + if db_backend = DbBackend::Postgres { + let drop_type_stmt = Type::drop() + .name(tea_enum.clone()) + .cascade() + .if_exists() + .to_owned(); + let (sql, values) = drop_type_stmt.build(PostgresQueryBuilder); + let stmt = Statement::from_sql_and_values(db.get_database_backend(), &sql, values); + db.execute(stmt).await?; - let create_type_stmt = Type::create() - .as_enum(tea_enum) - .values(vec![Alias::new("EverydayTea"), Alias::new("BreakfastTea")]) - .to_owned(); - // FIXME: This is not working - { - let (sql, values) = create_type_stmt.build(PostgresQueryBuilder); - let _stmt = Statement::from_sql_and_values(db.get_database_backend(), &sql, values); - } - // But this is working... - let stmt = Statement::from_string( - db.get_database_backend(), - create_type_stmt.to_string(PostgresQueryBuilder), - ); - db.execute(stmt).await?; + let create_type_stmt = Type::create() + .as_enum(tea_enum) + .values(vec![Alias::new("EverydayTea"), Alias::new("BreakfastTea")]) + .to_owned(); + // FIXME: This is not working + { + let (sql, values) = create_type_stmt.build(PostgresQueryBuilder); + let _stmt = Statement::from_sql_and_values(db.get_database_backend(), &sql, values); } - _ => {} + // But this is working... + let stmt = Statement::from_string( + db.get_database_backend(), + create_type_stmt.to_string(PostgresQueryBuilder), + ); + db.execute(stmt).await?; } create_table(db, &stmt, ActiveEnum).await