Skip to content

Commit 3dde118

Browse files
billy1624tyt2y3
authored andcommitted
Bump sea-orm & sea-query
1 parent 02fec6c commit 3dde118

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
@@ -63,7 +63,7 @@ backtrace_printer = { version = "1.3.0" }
6363
# cli
6464
clap = { version = "4.4.7", features = ["derive"], optional = true }
6565
colored = { workspace = true }
66-
sea-orm = { version = "1.1.0", features = [
66+
sea-orm = { git = "https://github.com/SeaQL/sea-orm", branch = "master", version = "2.0.0-rc", features = [
6767
"sqlx-postgres", # `DATABASE_DRIVER` feature
6868
"sqlx-sqlite",
6969
"runtime-tokio-rustls",
@@ -145,7 +145,7 @@ english-to-cron = { version = "0.1.2" }
145145

146146
# bg_sqlt: sqlite workers
147147
# bg_pg: postgres workers
148-
sqlx = { version = "0.8.2", default-features = false, features = [
148+
sqlx = { version = "0.8.4", default-features = false, features = [
149149
"json",
150150
"postgres",
151151
"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
{
@@ -353,10 +365,12 @@ async fn has_id_column(
353365
.await?;
354366
result.is_some_and(|row| row.try_get::<i32>("", "count").unwrap_or(0) > 0)
355367
}
356-
DatabaseBackend::MySql => {
357-
return Err(Error::Message(
358-
"Unsupported database backend: MySQL".to_string(),
359-
))
368+
bk => {
369+
return Err(DbErr::BackendNotSupported {
370+
db: bk.as_str(),
371+
ctx: "has_id_column",
372+
}
373+
.into());
360374
}
361375
};
362376

@@ -395,10 +409,12 @@ async fn is_auto_increment(
395409
.is_ok_and(|sql| sql.to_lowercase().contains("autoincrement"))
396410
})
397411
}
398-
DatabaseBackend::MySql => {
399-
return Err(Error::Message(
400-
"Unsupported database backend: MySQL".to_string(),
401-
))
412+
bk => {
413+
return Err(DbErr::BackendNotSupported {
414+
db: bk.as_str(),
415+
ctx: "is_auto_increment",
416+
}
417+
.into());
402418
}
403419
};
404420
Ok(result)
@@ -448,10 +464,12 @@ pub async fn reset_autoincrement(
448464
))
449465
.await?;
450466
}
451-
DatabaseBackend::MySql => {
452-
return Err(Error::Message(
453-
"Unsupported database backend: MySQL".to_string(),
454-
))
467+
bk => {
468+
return Err(DbErr::BackendNotSupported {
469+
db: bk.as_str(),
470+
ctx: "reset_autoincrement",
471+
}
472+
.into());
455473
}
456474
}
457475
Ok(())
@@ -742,17 +760,19 @@ async fn create_postgres_database(
742760
/// unsupported database backend or a query execution issue.
743761
pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
744762
let query = match db.get_database_backend() {
745-
DatabaseBackend::MySql => {
746-
return Err(Error::Message(
747-
"Unsupported database backend: MySQL".to_string(),
748-
))
749-
}
750763
DatabaseBackend::Postgres => {
751764
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
752765
}
753766
DatabaseBackend::Sqlite => {
754767
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
755768
}
769+
bk => {
770+
return Err(DbErr::BackendNotSupported {
771+
db: bk.as_str(),
772+
ctx: "get_tables",
773+
}
774+
.into())
775+
}
756776
};
757777

758778
let result = db
@@ -766,10 +786,9 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
766786
.into_iter()
767787
.filter_map(|row| {
768788
let col = match db.get_database_backend() {
769-
sea_orm::DatabaseBackend::MySql | sea_orm::DatabaseBackend::Postgres => {
770-
"table_name"
771-
}
789+
sea_orm::DatabaseBackend::Postgres => "table_name",
772790
sea_orm::DatabaseBackend::Sqlite => "name",
791+
_ => unreachable!(),
773792
};
774793

775794
if let Ok(table_name) = row.try_get::<String>("", col) {
@@ -969,6 +988,13 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
969988
})
970989
.collect::<Result<Vec<serde_json::Value>, DbErr>>()? // Specify error type explicitly
971990
}
991+
db => {
992+
return Err(DbErr::BackendNotSupported {
993+
db: db.as_str(),
994+
ctx: "dump_schema",
995+
}
996+
.into())
997+
}
972998
};
973999
// Serialize schema info to JSON format
9741000
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
@@ -754,6 +754,13 @@ pub async fn add_reference(
754754
.await?;
755755
*/
756756
}
757+
bk => {
758+
return Err(DbErr::BackendNotSupported {
759+
db: bk.as_str(),
760+
ctx: "add_reference",
761+
}
762+
.into())
763+
}
757764
}
758765
Ok(())
759766
}
@@ -801,6 +808,13 @@ pub async fn remove_reference(
801808
// sqlite will not allow it.
802809
// more: https://www.bigbinary.com/blog/rails-6-adds-add_foreign_key-and-remove_foreign_key-for-sqlite3
803810
}
811+
bk => {
812+
return Err(DbErr::BackendNotSupported {
813+
db: bk.as_str(),
814+
ctx: "remove_reference",
815+
}
816+
.into())
817+
}
804818
}
805819
Ok(())
806820
}

src/tests_cfg/db.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,13 @@ pub mod test_db {
7474
pub updated_at: DateTime,
7575
}
7676

77-
#[derive(Debug)]
77+
#[derive(Debug, DeriveIden)]
7878
pub enum Loco {
7979
Table,
8080
Id,
8181
Name,
8282
}
8383

84-
impl Iden for Loco {
85-
fn unquoted(&self, s: &mut dyn fmt::Write) {
86-
write!(
87-
s,
88-
"{}",
89-
match self {
90-
Self::Table => "loco",
91-
Self::Id => "id",
92-
Self::Name => "name",
93-
}
94-
)
95-
.unwrap();
96-
}
97-
}
98-
9984
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
10085
pub enum Relation {}
10186

0 commit comments

Comments
 (0)