Skip to content

Commit 918e452

Browse files
billy1624tyt2y3
authored andcommitted
Bump sea-orm & sea-query
1 parent bcaeea2 commit 918e452

File tree

4 files changed

+72
-45
lines changed

4 files changed

+72
-45
lines changed

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ backtrace_printer = { version = "1.3.0" }
6262
# cli
6363
clap = { version = "4.4.7", features = ["derive"], optional = true }
6464
colored = { workspace = true }
65-
sea-orm = { version = "1.1.0", features = [
65+
sea-orm = { git = "https://github.com/SeaQL/sea-orm", branch = "master", version = "2.0.0-rc", features = [
6666
"sqlx-postgres", # `DATABASE_DRIVER` feature
6767
"sqlx-sqlite",
6868
"runtime-tokio-rustls",
@@ -144,7 +144,7 @@ english-to-cron = { version = "0.1.2" }
144144

145145
# bg_sqlt: sqlite workers
146146
# bg_pg: postgres workers
147-
sqlx = { version = "0.8.2", default-features = false, features = [
147+
sqlx = { version = "0.8.4", default-features = false, features = [
148148
"json",
149149
"postgres",
150150
"chrono",
@@ -187,7 +187,9 @@ duct = { version = "1.0.0" }
187187

188188
[dependencies.sea-orm-migration]
189189
optional = true
190-
version = "1.0.0"
190+
git = "https://github.com/SeaQL/sea-orm"
191+
branch = "master"
192+
version = "2.0.0-rc"
191193
features = [
192194
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
193195
# 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"] }
207209
tree-fs = { version = "0.3" }
208210
reqwest = { version = "0.12.7", features = ["json"] }
209211
tower = { workspace = true, features = ["util"] }
210-
sqlx = { version = "0.8.2", default-features = false, features = [
212+
sqlx = { version = "0.8.4", default-features = false, features = [
211213
"macros",
212214
"json",
213215
"postgres",

src/db.rs

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use chrono::{DateTime, Utc};
1414
use regex::Regex;
1515
use sea_orm::{
1616
ActiveModelTrait, ConnectOptions, ConnectionTrait, Database, DatabaseBackend,
17-
DatabaseConnection, DbBackend, DbConn, DbErr, EntityTrait, IntoActiveModel, Statement,
17+
DatabaseConnection, DbBackend, DbConn, DbErr, EntityTrait, ExprTrait, IntoActiveModel,
18+
Statement,
1819
};
1920
use sea_orm_migration::MigratorTrait;
2021
use std::fmt::Write as FmtWrites;
@@ -184,6 +185,13 @@ pub async fn connect(config: &config::Database) -> Result<DbConn, sea_orm::DbErr
184185
.await?;
185186
}
186187
}
188+
bk => {
189+
return Err(DbErr::BackendNotSupported {
190+
db: bk.as_str(),
191+
ctx: "connect",
192+
}
193+
.into())
194+
}
187195
}
188196

189197
Ok(db)
@@ -209,9 +217,11 @@ pub fn extract_db_name(conn_str: &str) -> AppResult<&str> {
209217
/// Returns a [`sea_orm::DbErr`] if an error occurs during run migration up.
210218
pub async fn create(db_uri: &str) -> AppResult<()> {
211219
if !db_uri.starts_with("postgres://") {
212-
return Err(Error::string(
213-
"Only Postgres databases are supported for table creation",
214-
));
220+
return Err(DbErr::BackendNotSupported {
221+
db: "Unknown",
222+
ctx: "Only Postgres databases are supported for table creation",
223+
}
224+
.into());
215225
}
216226
let db_name = extract_db_name(db_uri).map_err(|_| {
217227
Error::string("The specified table name was not found in the given Postgres database URI")
@@ -279,8 +289,10 @@ use serde_json::{json, Value};
279289
pub async fn seed<A>(db: &DatabaseConnection, path: &str) -> crate::Result<()>
280290
where
281291
<<A as ActiveModelTrait>::Entity as EntityTrait>::Model: IntoActiveModel<A>,
282-
for<'de> <<A as ActiveModelTrait>::Entity as EntityTrait>::Model: serde::de::Deserialize<'de>,
292+
for<'de> <<A as ActiveModelTrait>::Entity as EntityTrait>::Model:
293+
serde::de::Deserialize<'de> + serde::Serialize,
283294
A: ActiveModelTrait + Send + Sync,
295+
A: sea_orm::TryIntoModel<<<A as ActiveModelTrait>::Entity as EntityTrait>::Model>,
284296
sea_orm::Insert<A>: Send + Sync,
285297
<A as ActiveModelTrait>::Entity: EntityName,
286298
{
@@ -355,10 +367,12 @@ async fn has_id_column(
355367
.await?;
356368
result.is_some_and(|row| row.try_get::<i32>("", "count").unwrap_or(0) > 0)
357369
}
358-
DatabaseBackend::MySql => {
359-
return Err(Error::Message(
360-
"Unsupported database backend: MySQL".to_string(),
361-
));
370+
bk => {
371+
return Err(DbErr::BackendNotSupported {
372+
db: bk.as_str(),
373+
ctx: "has_id_column",
374+
}
375+
.into());
362376
}
363377
};
364378

@@ -397,10 +411,12 @@ async fn is_auto_increment(
397411
.is_ok_and(|sql| sql.to_lowercase().contains("autoincrement"))
398412
})
399413
}
400-
DatabaseBackend::MySql => {
401-
return Err(Error::Message(
402-
"Unsupported database backend: MySQL".to_string(),
403-
));
414+
bk => {
415+
return Err(DbErr::BackendNotSupported {
416+
db: bk.as_str(),
417+
ctx: "is_auto_increment",
418+
}
419+
.into());
404420
}
405421
};
406422
Ok(result)
@@ -450,10 +466,12 @@ pub async fn reset_autoincrement(
450466
))
451467
.await?;
452468
}
453-
DatabaseBackend::MySql => {
454-
return Err(Error::Message(
455-
"Unsupported database backend: MySQL".to_string(),
456-
));
469+
bk => {
470+
return Err(DbErr::BackendNotSupported {
471+
db: bk.as_str(),
472+
ctx: "reset_autoincrement",
473+
}
474+
.into());
457475
}
458476
}
459477
Ok(())
@@ -765,17 +783,19 @@ async fn create_postgres_database(
765783
/// unsupported database backend or a query execution issue.
766784
pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
767785
let query = match db.get_database_backend() {
768-
DatabaseBackend::MySql => {
769-
return Err(Error::Message(
770-
"Unsupported database backend: MySQL".to_string(),
771-
));
772-
}
773786
DatabaseBackend::Postgres => {
774787
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
775788
}
776789
DatabaseBackend::Sqlite => {
777790
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
778791
}
792+
bk => {
793+
return Err(DbErr::BackendNotSupported {
794+
db: bk.as_str(),
795+
ctx: "get_tables",
796+
}
797+
.into())
798+
}
779799
};
780800

781801
let result = db
@@ -789,10 +809,9 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
789809
.into_iter()
790810
.filter_map(|row| {
791811
let col = match db.get_database_backend() {
792-
sea_orm::DatabaseBackend::MySql | sea_orm::DatabaseBackend::Postgres => {
793-
"table_name"
794-
}
812+
sea_orm::DatabaseBackend::Postgres => "table_name",
795813
sea_orm::DatabaseBackend::Sqlite => "name",
814+
_ => unreachable!(),
796815
};
797816

798817
if let Ok(table_name) = row.try_get::<String>("", col) {
@@ -1058,6 +1077,13 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
10581077
})
10591078
.collect::<Result<Vec<serde_json::Value>, DbErr>>()? // Specify error type explicitly
10601079
}
1080+
db => {
1081+
return Err(DbErr::BackendNotSupported {
1082+
db: db.as_str(),
1083+
ctx: "dump_schema",
1084+
}
1085+
.into())
1086+
}
10611087
};
10621088
// Serialize schema info to JSON format
10631089
let schema_json = serde_json::to_string_pretty(&schema_info)?;

src/schema.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ pub async fn add_reference(
815815
.await?;
816816
*/
817817
}
818+
bk => {
819+
return Err(DbErr::BackendNotSupported {
820+
db: bk.as_str(),
821+
ctx: "add_reference",
822+
}
823+
.into())
824+
}
818825
}
819826
Ok(())
820827
}
@@ -862,6 +869,13 @@ pub async fn remove_reference(
862869
// sqlite will not allow it.
863870
// more: https://www.bigbinary.com/blog/rails-6-adds-add_foreign_key-and-remove_foreign_key-for-sqlite3
864871
}
872+
bk => {
873+
return Err(DbErr::BackendNotSupported {
874+
db: bk.as_str(),
875+
ctx: "remove_reference",
876+
}
877+
.into())
878+
}
865879
}
866880
Ok(())
867881
}

src/tests_cfg/db.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,13 @@ pub mod test_db {
8989
pub updated_at: DateTime,
9090
}
9191

92-
#[derive(Debug)]
92+
#[derive(Debug, DeriveIden)]
9393
pub enum Loco {
9494
Table,
9595
Id,
9696
Name,
9797
}
9898

99-
impl Iden for Loco {
100-
fn unquoted(&self, s: &mut dyn fmt::Write) {
101-
write!(
102-
s,
103-
"{}",
104-
match self {
105-
Self::Table => "loco",
106-
Self::Id => "id",
107-
Self::Name => "name",
108-
}
109-
)
110-
.unwrap();
111-
}
112-
}
113-
11499
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
115100
pub enum Relation {}
116101

0 commit comments

Comments
 (0)