Use sea-schema's SchemaProbe
This commit is contained in:
parent
c466e46ae0
commit
07c8af2b3a
@ -33,14 +33,7 @@ clap = { version = "^2.33.3" }
|
|||||||
dotenv = { version = "^0.15" }
|
dotenv = { version = "^0.15" }
|
||||||
async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] }
|
async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] }
|
||||||
sea-orm-codegen = { version = "^0.7.0", path = "../sea-orm-codegen", optional = true }
|
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 = [
|
sea-schema = { git = "https://github.com/SeaQL/sea-schema", branch = "master" }
|
||||||
"debug-print",
|
|
||||||
"sqlx-mysql",
|
|
||||||
"sqlx-sqlite",
|
|
||||||
"sqlx-postgres",
|
|
||||||
"discovery",
|
|
||||||
"writer",
|
|
||||||
], optional = true }
|
|
||||||
sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ], optional = true }
|
sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ], optional = true }
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
tracing = { version = "0.1" }
|
tracing = { version = "0.1" }
|
||||||
@ -51,7 +44,7 @@ smol = "1.2.5"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "codegen", "runtime-async-std-native-tls" ]
|
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-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-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" ]
|
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls", "sea-schema/runtime-tokio-native-tls" ]
|
||||||
|
@ -24,6 +24,7 @@ clap = { version = "^2.33" }
|
|||||||
dotenv = { version = "^0.15" }
|
dotenv = { version = "^0.15" }
|
||||||
sea-orm = { path = "../", default-features = false, features = ["macros"] }
|
sea-orm = { path = "../", default-features = false, features = ["macros"] }
|
||||||
sea-orm-cli = { path = "../sea-orm-cli", default-features = false }
|
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 = { version = "0.1", features = ["log"] }
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
use super::{seaql_migrations, MigrationTrait, SchemaManager};
|
use std::fmt::Display;
|
||||||
use sea_orm::sea_query::{
|
use std::time::SystemTime;
|
||||||
Alias, Expr, ForeignKey, IntoTableRef, Query, SelectStatement, SimpleExpr, Table,
|
use tracing::info;
|
||||||
};
|
|
||||||
|
use sea_orm::sea_query::{Alias, Expr, ForeignKey, Query, SelectStatement, SimpleExpr, Table};
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait, ActiveValue, ColumnTrait, Condition, ConnectionTrait, DbBackend, DbConn,
|
ActiveModelTrait, ActiveValue, ColumnTrait, Condition, ConnectionTrait, DbBackend, DbConn,
|
||||||
DbErr, EntityTrait, QueryFilter, QueryOrder, Schema, Statement,
|
DbErr, EntityTrait, QueryFilter, QueryOrder, Schema, Statement,
|
||||||
};
|
};
|
||||||
use std::fmt::Display;
|
use sea_schema::{mysql::MySql, postgres::Postgres, probe::SchemaProbe, sqlite::Sqlite};
|
||||||
use std::time::SystemTime;
|
|
||||||
use tracing::info;
|
use super::{seaql_migrations, MigrationTrait, SchemaManager};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
/// Status of migration
|
/// Status of migration
|
||||||
@ -291,44 +292,17 @@ pub trait MigratorTrait: Send {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn query_tables(db: &DbConn) -> SelectStatement {
|
pub(crate) fn query_tables(db: &DbConn) -> SelectStatement {
|
||||||
let mut stmt = Query::select();
|
match db.get_database_backend() {
|
||||||
let (expr, tbl_ref, condition) = match db.get_database_backend() {
|
DbBackend::MySql => MySql::query_tables(),
|
||||||
DbBackend::MySql => (
|
DbBackend::Postgres => Postgres::query_tables(),
|
||||||
Expr::col(Alias::new("table_name")),
|
DbBackend::Sqlite => Sqlite::query_tables(),
|
||||||
(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_current_schema(db: &DbConn) -> SimpleExpr {
|
pub(crate) fn get_current_schema(db: &DbConn) -> SimpleExpr {
|
||||||
match db.get_database_backend() {
|
match db.get_database_backend() {
|
||||||
DbBackend::MySql => Expr::cust("DATABASE()"),
|
DbBackend::MySql => MySql::get_current_schema(),
|
||||||
DbBackend::Postgres => Expr::cust("CURRENT_SCHEMA()"),
|
DbBackend::Postgres => Postgres::get_current_schema(),
|
||||||
DbBackend::Sqlite => unimplemented!(),
|
DbBackend::Sqlite => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user