diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index f0643856..6bfb65a9 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -33,14 +33,7 @@ clap = { version = "^2.33.3" } dotenv = { version = "^0.15" } async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] } sea-orm-codegen = { version = "^0.7.0", path = "../sea-orm-codegen", optional = true } -sea-schema = { git = "https://github.com/SeaQL/sea-schema", branch = "master", default-features = false, features = [ - "debug-print", - "sqlx-mysql", - "sqlx-sqlite", - "sqlx-postgres", - "discovery", - "writer", -], optional = true } +sea-schema = { git = "https://github.com/SeaQL/sea-schema", branch = "master" } sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ], optional = true } tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing = { version = "0.1" } @@ -51,7 +44,7 @@ smol = "1.2.5" [features] default = [ "codegen", "runtime-async-std-native-tls" ] -codegen = [ "sea-schema", "sea-orm-codegen" ] +codegen = [ "sea-schema/sqlx-all", "sea-orm-codegen" ] runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls", "sea-schema/runtime-actix-native-tls" ] runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls", "sea-schema/runtime-async-std-native-tls" ] runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sea-schema/runtime-tokio-native-tls" ] diff --git a/sea-orm-migration/Cargo.toml b/sea-orm-migration/Cargo.toml index 672871b7..5b4ed006 100644 --- a/sea-orm-migration/Cargo.toml +++ b/sea-orm-migration/Cargo.toml @@ -24,6 +24,7 @@ clap = { version = "^2.33" } dotenv = { version = "^0.15" } sea-orm = { path = "../", default-features = false, features = ["macros"] } sea-orm-cli = { path = "../sea-orm-cli", default-features = false } +sea-schema = { git = "https://github.com/SeaQL/sea-schema", branch = "master" } tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/sea-orm-migration/src/migrator.rs b/sea-orm-migration/src/migrator.rs index 6c3d5386..f5e12b05 100644 --- a/sea-orm-migration/src/migrator.rs +++ b/sea-orm-migration/src/migrator.rs @@ -1,14 +1,15 @@ -use super::{seaql_migrations, MigrationTrait, SchemaManager}; -use sea_orm::sea_query::{ - Alias, Expr, ForeignKey, IntoTableRef, Query, SelectStatement, SimpleExpr, Table, -}; +use std::fmt::Display; +use std::time::SystemTime; +use tracing::info; + +use sea_orm::sea_query::{Alias, Expr, ForeignKey, Query, SelectStatement, SimpleExpr, Table}; use sea_orm::{ ActiveModelTrait, ActiveValue, ColumnTrait, Condition, ConnectionTrait, DbBackend, DbConn, DbErr, EntityTrait, QueryFilter, QueryOrder, Schema, Statement, }; -use std::fmt::Display; -use std::time::SystemTime; -use tracing::info; +use sea_schema::{mysql::MySql, postgres::Postgres, probe::SchemaProbe, sqlite::Sqlite}; + +use super::{seaql_migrations, MigrationTrait, SchemaManager}; #[derive(Debug, PartialEq)] /// Status of migration @@ -291,44 +292,17 @@ pub trait MigratorTrait: Send { } pub(crate) fn query_tables(db: &DbConn) -> SelectStatement { - let mut stmt = Query::select(); - let (expr, tbl_ref, condition) = match db.get_database_backend() { - DbBackend::MySql => ( - Expr::col(Alias::new("table_name")), - (Alias::new("information_schema"), Alias::new("tables")).into_table_ref(), - Condition::all().add( - Expr::expr(get_current_schema(db)) - .equals(Alias::new("tables"), Alias::new("table_schema")), - ), - ), - DbBackend::Postgres => ( - Expr::col(Alias::new("table_name")), - (Alias::new("information_schema"), Alias::new("tables")).into_table_ref(), - Condition::all() - .add( - Expr::expr(get_current_schema(db)) - .equals(Alias::new("tables"), Alias::new("table_schema")), - ) - .add(Expr::col(Alias::new("table_type")).eq("BASE TABLE")), - ), - DbBackend::Sqlite => ( - Expr::col(Alias::new("name")), - Alias::new("sqlite_master").into_table_ref(), - Condition::all() - .add(Expr::col(Alias::new("type")).eq("table")) - .add(Expr::col(Alias::new("name")).ne("sqlite_sequence")), - ), - }; - stmt.expr_as(expr, Alias::new("table_name")) - .from(tbl_ref) - .cond_where(condition); - stmt + match db.get_database_backend() { + DbBackend::MySql => MySql::query_tables(), + DbBackend::Postgres => Postgres::query_tables(), + DbBackend::Sqlite => Sqlite::query_tables(), + } } pub(crate) fn get_current_schema(db: &DbConn) -> SimpleExpr { match db.get_database_backend() { - DbBackend::MySql => Expr::cust("DATABASE()"), - DbBackend::Postgres => Expr::cust("CURRENT_SCHEMA()"), + DbBackend::MySql => MySql::get_current_schema(), + DbBackend::Postgres => Postgres::get_current_schema(), DbBackend::Sqlite => unimplemented!(), } }