Skip to content

Commit

Permalink
Restructure sea-query dependency (#41)
Browse files Browse the repository at this point in the history
* Migrator use reexported `sea_orm::sea_query`

* Bump sea-query version to 0.21.0

* Migrator test case use reexported `sea_orm::sea_query`

* Reexport `sea_orm::sea_query`
  • Loading branch information
billy1624 authored Feb 5, 2022
1 parent 764f2aa commit 42283f9
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ path = "src/lib.rs"
[dependencies]
futures = { version = "0.3", optional = true }
sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" }
sea-query = { version = "^0.20.0" }
sea-query = { version = "^0.21.0" }
sea-orm = { git = "https://github.com/SeaQL/sea-orm.git", branch = "migration", default-features = false, features = ["macros"], optional = true }
clap = { version = "^2.33.3", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }
Expand Down
4 changes: 2 additions & 2 deletions src/migration/manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use sea_orm::{Condition, ConnectionTrait, DbBackend, DbErr, Statement, StatementBuilder};
use sea_query::{
use sea_orm::sea_query::{
extension::postgres::{TypeAlterStatement, TypeCreateStatement, TypeDropStatement},
Alias, Expr, ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement,
IndexDropStatement, Query, TableAlterStatement, TableCreateStatement, TableDropStatement,
TableRenameStatement, TableTruncateStatement,
};
use sea_orm::{Condition, ConnectionTrait, DbBackend, DbErr, Statement, StatementBuilder};

use super::query_tables;

Expand Down
4 changes: 3 additions & 1 deletion src/migration/migrator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::{seaql_migrations, MigrationTrait, SchemaManager};
use sea_orm::sea_query::{
Alias, Expr, ForeignKey, IntoTableRef, Query, SelectStatement, SimpleExpr, Table,
};
use sea_orm::{
ActiveModelTrait, ActiveValue, ColumnTrait, Condition, ConnectionTrait, DbBackend, DbErr,
EntityTrait, QueryFilter, QueryOrder, Schema, Statement,
};
use sea_query::{Alias, Expr, ForeignKey, IntoTableRef, Query, SelectStatement, SimpleExpr, Table};
use std::fmt::Display;
use std::time::SystemTime;
use tracing::info;
Expand Down
1 change: 1 addition & 0 deletions src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use migrator::*;
pub use async_std;
pub use async_trait;
pub use sea_orm;
pub use sea_orm::sea_query;
pub use sea_orm::DbErr;

pub trait MigrationName {
Expand Down
4 changes: 2 additions & 2 deletions src/postgres/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::postgres::def::{ColumnInfo, Type};
use sea_query::{Alias, ColumnDef, IntervalField};
use sea_query::{Alias, ColumnDef, PgInterval};
use std::{convert::TryFrom, fmt::Write};

impl ColumnInfo {
Expand Down Expand Up @@ -131,7 +131,7 @@ impl ColumnInfo {
}
Type::Interval(interval_attr) => {
let field = match &interval_attr.field {
Some(field) => IntervalField::try_from(field).ok(),
Some(field) => PgInterval::try_from(field).ok(),
None => None,
};
let precision = interval_attr.precision.map(Into::into);
Expand Down
36 changes: 18 additions & 18 deletions tests/live/sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,27 +277,27 @@ async fn test_002() -> DiscoveryResult<()> {
};
let expected_sql = if tbl_name.as_str() == "order" {
vec![
"CREATE TABLE `order` (",
"`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,",
"`total` real,",
"`bakery_id` integer NOT NULL,",
"`customer_id` integer NOT NULL,",
"`placed_at` text NOT NULL,",
"FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,",
"FOREIGN KEY (`bakery_id`) REFERENCES `bakery` (`id`) ON DELETE CASCADE ON UPDATE CASCADE",
")",
r#"CREATE TABLE "order" ("#,
r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#,
r#""total" real,"#,
r#""bakery_id" integer NOT NULL,"#,
r#""customer_id" integer NOT NULL,"#,
r#""placed_at" text NOT NULL,"#,
r#"FOREIGN KEY ("customer_id") REFERENCES "customer" ("id") ON DELETE CASCADE ON UPDATE CASCADE,"#,
r#"FOREIGN KEY ("bakery_id") REFERENCES "bakery" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#,
r#")"#,
].join(" ")
} else if tbl_name.as_str() == "lineitem" {
vec![
"CREATE TABLE `lineitem` (",
"`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,",
"`price` real,",
"`quantity` integer,",
"`order_id` integer NOT NULL,",
"`cake_id` integer NOT NULL,",
"FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,",
"FOREIGN KEY (`cake_id`) REFERENCES `cake` (`id`) ON DELETE CASCADE ON UPDATE CASCADE",
")",
r#"CREATE TABLE "lineitem" ("#,
r#""id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"#,
r#""price" real,"#,
r#""quantity" integer,"#,
r#""order_id" integer NOT NULL,"#,
r#""cake_id" integer NOT NULL,"#,
r#"FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON DELETE CASCADE ON UPDATE CASCADE,"#,
r#"FOREIGN KEY ("cake_id") REFERENCES "cake" ("id") ON DELETE CASCADE ON UPDATE CASCADE"#,
r#")"#,
].join(" ")
} else {
tbl_create_stmt.to_string(SqliteQueryBuilder)
Expand Down
4 changes: 2 additions & 2 deletions tests/migration/src/m20220118_000001_create_cake_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_schema::{
migration::*,
use sea_schema::migration::{
sea_query::{self, *},
*,
};

pub struct Migration;
Expand Down
5 changes: 3 additions & 2 deletions tests/migration/src/m20220118_000002_create_fruit_table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::m20220118_000001_create_cake_table::Cake;
use sea_schema::{
migration::{sea_orm::DbBackend, *},
use sea_schema::migration::{
sea_orm::DbBackend,
sea_query::{self, *},
*,
};

pub struct Migration;
Expand Down

0 comments on commit 42283f9

Please sign in to comment.