From c568f4919baee9735ef8ed039369bde21bcb7f6d Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 20 May 2025 16:27:17 +0000 Subject: [PATCH 1/4] Bump sea-orm & sea-query --- Cargo.toml | 10 +++--- src/db.rs | 76 ++++++++++++++++++++++++++++++--------------- src/schema.rs | 14 +++++++++ src/tests_cfg/db.rs | 17 +--------- 4 files changed, 72 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 71626ad16..c677294b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ backtrace_printer = { version = "1.3.0" } # cli clap = { version = "4.4.7", features = ["derive"], optional = true } colored = { workspace = true } -sea-orm = { version = "1.1.0", features = [ +sea-orm = { git = "https://github.com/SeaQL/sea-orm", branch = "master", version = "2.0.0-rc", features = [ "sqlx-postgres", # `DATABASE_DRIVER` feature "sqlx-sqlite", "runtime-tokio-rustls", @@ -144,7 +144,7 @@ english-to-cron = { version = "0.1.2" } # bg_sqlt: sqlite workers # bg_pg: postgres workers -sqlx = { version = "0.8.2", default-features = false, features = [ +sqlx = { version = "0.8.4", default-features = false, features = [ "json", "postgres", "chrono", @@ -187,7 +187,9 @@ duct = { version = "1.0.0" } [dependencies.sea-orm-migration] optional = true -version = "1.0.0" +git = "https://github.com/SeaQL/sea-orm" +branch = "master" +version = "2.0.0-rc" 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. @@ -207,7 +209,7 @@ insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] } tree-fs = { version = "0.3" } reqwest = { version = "0.12.7", features = ["json"] } tower = { workspace = true, features = ["util"] } -sqlx = { version = "0.8.2", default-features = false, features = [ +sqlx = { version = "0.8.4", default-features = false, features = [ "macros", "json", "postgres", diff --git a/src/db.rs b/src/db.rs index 17494b982..e949052b1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -14,7 +14,8 @@ use chrono::{DateTime, Utc}; use regex::Regex; use sea_orm::{ ActiveModelTrait, ConnectOptions, ConnectionTrait, Database, DatabaseBackend, - DatabaseConnection, DbBackend, DbConn, DbErr, EntityTrait, IntoActiveModel, Statement, + DatabaseConnection, DbBackend, DbConn, DbErr, EntityTrait, ExprTrait, IntoActiveModel, + Statement, }; use sea_orm_migration::MigratorTrait; use std::fmt::Write as FmtWrites; @@ -184,6 +185,13 @@ pub async fn connect(config: &config::Database) -> Result { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "connect", + } + .into()) + } } Ok(db) @@ -209,9 +217,11 @@ pub fn extract_db_name(conn_str: &str) -> AppResult<&str> { /// Returns a [`sea_orm::DbErr`] if an error occurs during run migration up. pub async fn create(db_uri: &str) -> AppResult<()> { if !db_uri.starts_with("postgres://") { - return Err(Error::string( - "Only Postgres databases are supported for table creation", - )); + return Err(DbErr::BackendNotSupported { + db: "Unknown", + ctx: "Only Postgres databases are supported for table creation", + } + .into()); } let db_name = extract_db_name(db_uri).map_err(|_| { Error::string("The specified table name was not found in the given Postgres database URI") @@ -279,8 +289,10 @@ use serde_json::{json, Value}; pub async fn seed(db: &DatabaseConnection, path: &str) -> crate::Result<()> where <::Entity as EntityTrait>::Model: IntoActiveModel, - for<'de> <::Entity as EntityTrait>::Model: serde::de::Deserialize<'de>, + for<'de> <::Entity as EntityTrait>::Model: + serde::de::Deserialize<'de> + serde::Serialize, A: ActiveModelTrait + Send + Sync, + A: sea_orm::TryIntoModel<<::Entity as EntityTrait>::Model>, sea_orm::Insert: Send + Sync, ::Entity: EntityName, { @@ -353,10 +365,12 @@ async fn has_id_column( .await?; result.is_some_and(|row| row.try_get::("", "count").unwrap_or(0) > 0) } - DatabaseBackend::MySql => { - return Err(Error::Message( - "Unsupported database backend: MySQL".to_string(), - )) + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "has_id_column", + } + .into()); } }; @@ -395,10 +409,12 @@ async fn is_auto_increment( .is_ok_and(|sql| sql.to_lowercase().contains("autoincrement")) }) } - DatabaseBackend::MySql => { - return Err(Error::Message( - "Unsupported database backend: MySQL".to_string(), - )) + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "is_auto_increment", + } + .into()); } }; Ok(result) @@ -448,10 +464,12 @@ pub async fn reset_autoincrement( )) .await?; } - DatabaseBackend::MySql => { - return Err(Error::Message( - "Unsupported database backend: MySQL".to_string(), - )) + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "reset_autoincrement", + } + .into()); } } Ok(()) @@ -763,17 +781,19 @@ async fn create_postgres_database( /// unsupported database backend or a query execution issue. pub async fn get_tables(db: &DatabaseConnection) -> AppResult> { let query = match db.get_database_backend() { - DatabaseBackend::MySql => { - return Err(Error::Message( - "Unsupported database backend: MySQL".to_string(), - )) - } DatabaseBackend::Postgres => { "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'" } DatabaseBackend::Sqlite => { "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'" } + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "get_tables", + } + .into()) + } }; let result = db @@ -787,10 +807,9 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult> { .into_iter() .filter_map(|row| { let col = match db.get_database_backend() { - sea_orm::DatabaseBackend::MySql | sea_orm::DatabaseBackend::Postgres => { - "table_name" - } + sea_orm::DatabaseBackend::Postgres => "table_name", sea_orm::DatabaseBackend::Sqlite => "name", + _ => unreachable!(), }; if let Ok(table_name) = row.try_get::("", col) { @@ -990,6 +1009,13 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> { }) .collect::, DbErr>>()? // Specify error type explicitly } + db => { + return Err(DbErr::BackendNotSupported { + db: db.as_str(), + ctx: "dump_schema", + } + .into()) + } }; // Serialize schema info to JSON format let schema_json = serde_json::to_string_pretty(&schema_info)?; diff --git a/src/schema.rs b/src/schema.rs index f5f2b54c2..5f86af577 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -811,6 +811,13 @@ pub async fn add_reference( .await?; */ } + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "add_reference", + } + .into()) + } } Ok(()) } @@ -858,6 +865,13 @@ pub async fn remove_reference( // sqlite will not allow it. // more: https://www.bigbinary.com/blog/rails-6-adds-add_foreign_key-and-remove_foreign_key-for-sqlite3 } + bk => { + return Err(DbErr::BackendNotSupported { + db: bk.as_str(), + ctx: "remove_reference", + } + .into()) + } } Ok(()) } diff --git a/src/tests_cfg/db.rs b/src/tests_cfg/db.rs index 7eb77196c..7237d8862 100644 --- a/src/tests_cfg/db.rs +++ b/src/tests_cfg/db.rs @@ -89,28 +89,13 @@ pub mod test_db { pub updated_at: DateTime, } - #[derive(Debug)] + #[derive(Debug, DeriveIden)] pub enum Loco { Table, Id, Name, } - impl Iden for Loco { - fn unquoted(&self, s: &mut dyn fmt::Write) { - write!( - s, - "{}", - match self { - Self::Table => "loco", - Self::Id => "id", - Self::Name => "name", - } - ) - .unwrap(); - } - } - #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} From 25b3774e5796d726af8d765138c715418c85a490 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Tue, 22 Jul 2025 12:34:39 +0100 Subject: [PATCH 2/4] Bump sea-orm Use *_raw API --- Cargo.toml | 4 +- src/db.rs | 87 ++++++++++++++++++-------------------- src/model/query/dsl/mod.rs | 6 +-- src/schema.rs | 19 +++++++-- src/tests_cfg/db.rs | 4 +- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c677294b1..a9022fea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ backtrace_printer = { version = "1.3.0" } # cli clap = { version = "4.4.7", features = ["derive"], optional = true } colored = { workspace = true } -sea-orm = { git = "https://github.com/SeaQL/sea-orm", branch = "master", version = "2.0.0-rc", features = [ +sea-orm = { version = "2.0.0-rc", features = [ "sqlx-postgres", # `DATABASE_DRIVER` feature "sqlx-sqlite", "runtime-tokio-rustls", @@ -187,8 +187,6 @@ duct = { version = "1.0.0" } [dependencies.sea-orm-migration] optional = true -git = "https://github.com/SeaQL/sea-orm" -branch = "master" version = "2.0.0-rc" features = [ # Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI. diff --git a/src/db.rs b/src/db.rs index e949052b1..7611925c5 100644 --- a/src/db.rs +++ b/src/db.rs @@ -14,8 +14,8 @@ use chrono::{DateTime, Utc}; use regex::Regex; use sea_orm::{ ActiveModelTrait, ConnectOptions, ConnectionTrait, Database, DatabaseBackend, - DatabaseConnection, DbBackend, DbConn, DbErr, EntityTrait, ExprTrait, IntoActiveModel, - Statement, + DatabaseConnection, DatabaseConnectionType, DbBackend, DbConn, DbErr, EntityTrait, ExprTrait, + IntoActiveModel, Statement, }; use sea_orm_migration::MigratorTrait; use std::fmt::Write as FmtWrites; @@ -86,10 +86,10 @@ impl MultiDb { /// This function will return an error if IO fails #[allow(clippy::match_wildcard_for_single_variants)] pub async fn verify_access(db: &DatabaseConnection) -> AppResult<()> { - match db { - DatabaseConnection::SqlxPostgresPoolConnection(_) => { + match db.inner { + DatabaseConnectionType::SqlxPostgresPoolConnection(_) => { let res = db - .query_all(Statement::from_string( + .query_all_raw(Statement::from_string( DatabaseBackend::Postgres, "SELECT * FROM pg_catalog.pg_tables WHERE tableowner = current_user;", )) @@ -100,7 +100,7 @@ pub async fn verify_access(db: &DatabaseConnection) -> AppResult<()> { )); } } - DatabaseConnection::Disconnected => { + DatabaseConnectionType::Disconnected => { return Err(Error::string("connection to database has been closed")); } _ => {} @@ -159,7 +159,7 @@ pub async fn connect(config: &config::Database) -> Result { - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( DatabaseBackend::Sqlite, config.run_on_start.clone().unwrap_or_else(|| { " @@ -178,7 +178,7 @@ pub async fn connect(config: &config::Database) -> Result { if let Some(run_on_start) = &config.run_on_start { - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( db.get_database_backend(), run_on_start.clone(), )) @@ -350,7 +350,7 @@ async fn has_id_column( )" ); let result = db - .query_one(Statement::from_string(DatabaseBackend::Postgres, query)) + .query_one_raw(Statement::from_string(DatabaseBackend::Postgres, query)) .await?; result.is_some_and(|row| row.try_get::("", "exists").unwrap_or(false)) } @@ -361,7 +361,7 @@ async fn has_id_column( WHERE name = 'id'" ); let result = db - .query_one(Statement::from_string(DatabaseBackend::Sqlite, query)) + .query_one_raw(Statement::from_string(DatabaseBackend::Sqlite, query)) .await?; result.is_some_and(|row| row.try_get::("", "count").unwrap_or(0) > 0) } @@ -394,7 +394,7 @@ async fn is_auto_increment( "SELECT pg_get_serial_sequence('{table_name}', 'id') IS NOT NULL as is_serial" ); let result = db - .query_one(Statement::from_string(DatabaseBackend::Postgres, query)) + .query_one_raw(Statement::from_string(DatabaseBackend::Postgres, query)) .await?; result.is_some_and(|row| row.try_get::("", "is_serial").unwrap_or(false)) } @@ -402,7 +402,7 @@ async fn is_auto_increment( let query = format!("SELECT sql FROM sqlite_master WHERE type='table' AND name='{table_name}'"); let result = db - .query_one(Statement::from_string(DatabaseBackend::Sqlite, query)) + .query_one_raw(Statement::from_string(DatabaseBackend::Sqlite, query)) .await?; result.is_some_and(|row| { row.try_get::("", "sql") @@ -445,7 +445,7 @@ pub async fn reset_autoincrement( "SELECT setval(pg_get_serial_sequence('{table_name}', 'id'), COALESCE(MAX(id), 0) \ + 1, false) FROM {table_name}" ); - db.execute(Statement::from_sql_and_values( + db.execute_raw(Statement::from_sql_and_values( DatabaseBackend::Postgres, &query_str, vec![], @@ -457,7 +457,7 @@ pub async fn reset_autoincrement( "UPDATE sqlite_sequence SET seq = (SELECT MAX(id) FROM {table_name}) WHERE name = \ '{table_name}'" ); - db.execute(Statement::from_sql_and_values( + db.execute_raw(Statement::from_sql_and_values( DatabaseBackend::Sqlite, &query_str, vec![], @@ -750,10 +750,7 @@ async fn create_postgres_database( ) .limit(1); - let (sql, values) = select.build(sea_orm::sea_query::PostgresQueryBuilder); - let statement = Statement::from_sql_and_values(DatabaseBackend::Postgres, sql, values); - - if db.query_one(statement).await?.is_some() { + if db.query_one(&select).await?.is_some() { tracing::info!(db_name, "database already exists"); return Err(sea_orm::DbErr::Custom("database already exists".to_owned())); @@ -764,7 +761,7 @@ async fn create_postgres_database( let query = format!("CREATE DATABASE {db_name} WITH {with_options}"); tracing::info!(query, "creating postgres database"); - db.execute(sea_orm::Statement::from_string( + db.execute_raw(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, query, )) @@ -797,7 +794,7 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult> { }; let result = db - .query_all(Statement::from_string( + .query_all_raw(Statement::from_string( db.get_database_backend(), query.to_string(), )) @@ -855,7 +852,7 @@ pub async fn dump_tables( tracing::info!(table, "get table data"); let data_result = db - .query_all(Statement::from_string( + .query_all_raw(Statement::from_string( db.get_database_backend(), format!(r#"SELECT * FROM "{table}""#), )) @@ -958,7 +955,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> { ORDER BY table_name, ordinal_position; "; let stmt = Statement::from_string(DbBackend::Postgres, query.to_owned()); - let rows = db.query_all(stmt).await?; + let rows = db.query_all_raw(stmt).await?; rows.into_iter() .map(|row| { // Wrap the closure in a Result to handle errors properly @@ -978,7 +975,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> { ORDER BY TABLE_NAME, ORDINAL_POSITION; "; let stmt = Statement::from_string(DbBackend::MySql, query.to_owned()); - let rows = db.query_all(stmt).await?; + let rows = db.query_all_raw(stmt).await?; rows.into_iter() .map(|row| { // Wrap the closure in a Result to handle errors properly @@ -998,7 +995,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> { ORDER BY name; "; let stmt = Statement::from_string(DbBackend::Sqlite, query.to_owned()); - let rows = db.query_all(stmt).await?; + let rows = db.query_all_raw(stmt).await?; rows.into_iter() .map(|row| { // Wrap the closure in a Result to handle errors properly @@ -1277,7 +1274,7 @@ mod tests { let backend = db.get_database_backend(); let table_no_id = "test_table_no_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_no_id} (name TEXT);"), )) @@ -1293,7 +1290,7 @@ mod tests { ); let table_with_id = "test_table_with_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);"), )) @@ -1309,7 +1306,7 @@ mod tests { ); let table_with_serial_id = "test_table_with_serial_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);"), )) @@ -1334,7 +1331,7 @@ mod tests { assert_eq!(backend, DatabaseBackend::Sqlite); let table_no_id = "test_table_no_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_no_id} (name TEXT);"), )) @@ -1350,7 +1347,7 @@ mod tests { ); let table_with_id = "test_table_with_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, // SQLite uses INTEGER PRIMARY KEY for rowid alias format!("CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);"), @@ -1367,7 +1364,7 @@ mod tests { ); let table_with_auto_id = "test_table_with_auto_id"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, // AUTOINCREMENT keyword is important for SQLite's sequence behavior format!("CREATE TABLE {table_with_auto_id} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);"), @@ -1395,7 +1392,7 @@ mod tests { let backend = db.get_database_backend(); let table_no_id = "test_table_no_id_auto"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_no_id} (name TEXT);"), )) @@ -1417,7 +1414,7 @@ mod tests { ); let table_with_id_not_auto = "test_table_id_not_auto"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_with_id_not_auto} (id INTEGER PRIMARY KEY, name TEXT);"), )) @@ -1433,7 +1430,7 @@ mod tests { ); let table_with_serial_id = "test_table_serial_id_auto"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);"), )) @@ -1462,7 +1459,7 @@ mod tests { // Create test table with SERIAL id let table_name = "test_reset_sequence"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_name} (id SERIAL PRIMARY KEY, name TEXT);"), )) @@ -1470,7 +1467,7 @@ mod tests { .expect("Failed to create test table"); // Insert multiple rows in a single query - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');"), )) @@ -1478,7 +1475,7 @@ mod tests { .expect("Failed to insert test data"); // Delete all rows - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("DELETE FROM {table_name};"), )) @@ -1487,7 +1484,7 @@ mod tests { // Insert a new row and check ID (should be 4, continuing the sequence) let result = db - .query_one(Statement::from_string( + .query_one_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;"), )) @@ -1502,7 +1499,7 @@ mod tests { ); // Delete all rows again - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("DELETE FROM {table_name};"), )) @@ -1516,7 +1513,7 @@ mod tests { // Insert a new row and check ID (should be 1 after reset) let result = db - .query_one(Statement::from_string( + .query_one_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;"), )) @@ -1538,7 +1535,7 @@ mod tests { // Create test table with auto-incrementing id let table_name = "test_reset_sequence"; - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("CREATE TABLE {table_name} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);"), )) @@ -1546,7 +1543,7 @@ mod tests { .expect("Failed to create test table"); // Insert multiple rows in a single query - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');"), )) @@ -1554,7 +1551,7 @@ mod tests { .expect("Failed to insert test data"); // Delete all rows - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("DELETE FROM {table_name};"), )) @@ -1563,7 +1560,7 @@ mod tests { // Insert a new row and check ID (should be 4, continuing the sequence) let result = db - .query_one(Statement::from_string( + .query_one_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;"), )) @@ -1578,7 +1575,7 @@ mod tests { ); // Delete all rows again - db.execute(Statement::from_string( + db.execute_raw(Statement::from_string( backend, format!("DELETE FROM {table_name};"), )) @@ -1592,7 +1589,7 @@ mod tests { // Insert a new row and check ID (should be 1 after reset) let result = db - .query_one(Statement::from_string( + .query_one_raw(Statement::from_string( backend, format!("INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;"), )) diff --git a/src/model/query/dsl/mod.rs b/src/model/query/dsl/mod.rs index fa912c53a..fb30c56c9 100644 --- a/src/model/query/dsl/mod.rs +++ b/src/model/query/dsl/mod.rs @@ -164,9 +164,9 @@ pub fn date_range(col: T) -> date_range::DateRangeBuilder { date_range::DateRangeBuilder::new(condition(), col) } -impl IntoCondition for ConditionBuilder { - fn into_condition(self) -> Condition { - self.build() +impl From for Condition { + fn from(cond: ConditionBuilder) -> Condition { + cond.build() } } diff --git a/src/schema.rs b/src/schema.rs index 5f86af577..912a9a621 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -134,7 +134,7 @@ async fn check_enum_exists(m: &SchemaManager<'_>, enum_name: &str) -> Result, enum_name: &str) -> Result { + // Unknown database, do nothing + Ok(false) + } } } @@ -602,6 +606,9 @@ async fn create_table_impl( sea_orm::DatabaseBackend::MySql => { // MySql not supporting } + _ => { + // Unknown database, do nothing + } } } } @@ -907,7 +914,7 @@ pub async fn add_enum_values( sea_orm::DatabaseBackend::Postgres => { for value in new_values { m.get_connection() - .execute(sea_orm::Statement::from_string( + .execute_raw(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, format!("ALTER TYPE {enum_name} ADD VALUE '{value}'"), )) @@ -926,6 +933,12 @@ pub async fn add_enum_values( "MySQL: Enum values are handled by column definition. No action needed." ); } + db => { + tracing::info!( + "{}: Unsure how to handle Enum values, no action to be done.", + db.as_str() + ); + } } Ok(()) } @@ -951,7 +964,7 @@ pub async fn drop_enum_type(m: &SchemaManager<'_>, enum_name: &str) -> Result<() // Try to drop the enum type with CASCADE to handle any remaining references let query = format!("DROP TYPE IF EXISTS {enum_name} CASCADE"); m.get_connection() - .execute(sea_orm::Statement::from_string( + .execute_raw(sea_orm::Statement::from_string( sea_orm::DatabaseBackend::Postgres, query, )) diff --git a/src/tests_cfg/db.rs b/src/tests_cfg/db.rs index 7237d8862..84e6292e2 100644 --- a/src/tests_cfg/db.rs +++ b/src/tests_cfg/db.rs @@ -27,7 +27,7 @@ use crate::{ pub async fn get_value(conn: &sea_orm::DatabaseConnection, query: &str) -> String { // Execute query and get the result row let row = conn - .query_one(Statement::from_string( + .query_one_raw(Statement::from_string( conn.get_database_backend(), query.to_owned(), )) @@ -75,8 +75,6 @@ pub async fn fail_connection() -> sea_orm::DatabaseConnection { } pub mod test_db { - use std::fmt; - use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] From 07fde123a11355dc6a731ec2279a005d899fd0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E9=98=B3?= Date: Tue, 4 Nov 2025 16:43:23 +0800 Subject: [PATCH 3/4] Update minimum SeaORM CLI version to 2.0.0-rc --- src/doctor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doctor.rs b/src/doctor.rs index cd224da4d..6881af441 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -37,7 +37,7 @@ const QUEUE_CONN_FAILED: &str = "queue connection: failed"; const QUEUE_NOT_CONFIGURED: &str = "queue not configured?"; // versions health -const MIN_SEAORMCLI_VER: &str = "1.1.0"; +const MIN_SEAORMCLI_VER: &str = "2.0.0-rc"; static MIN_DEP_VERSIONS: OnceLock> = OnceLock::new(); static RE_CRATE_VERSION: OnceLock = OnceLock::new(); From 3e4a3af5c0152b0e1fba21bda33390ecfde8d440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E9=98=B3?= Date: Tue, 4 Nov 2025 16:50:00 +0800 Subject: [PATCH 4/4] Update minimum version for sea-orm to 2.0.0-rc --- src/doctor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doctor.rs b/src/doctor.rs index 6881af441..f3aaa92ce 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -50,7 +50,7 @@ fn get_min_dep_versions() -> &'static HashMap<&'static str, &'static str> { let mut min_vers = HashMap::new(); min_vers.insert("tokio", "1.33.0"); - min_vers.insert("sea-orm", "1.1.0"); + min_vers.insert("sea-orm", "2.0.0-rc"); min_vers.insert("validator", "0.20.0"); min_vers.insert("axum", "0.8.1");