Skip to content

Commit 57f9dd2

Browse files
committed
Make sea-orm-cli & sea-orm-migration dependencies optional #2320
1 parent a9eb30d commit 57f9dd2

File tree

6 files changed

+282
-116
lines changed

6 files changed

+282
-116
lines changed

sea-orm-cli/Cargo.toml

+16-13
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
3838
dotenvy = { version = "0.15", default-features = false, optional = true }
3939
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true }
4040
sea-orm-codegen = { version = "=1.1.8", path = "../sea-orm-codegen", default-features = false, optional = true }
41-
sea-schema = { version = "0.16.0" }
42-
sqlx = { version = "0.8.2", default-features = false, features = ["mysql", "postgres"], optional = true }
41+
sea-schema = { version = "0.16.0", default-features = false, features = ["discovery", "writer", "probe"], optional = true }
42+
sqlx = { version = "0.8.2", default-features = false, optional = true }
4343
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
4444
tracing = { version = "0.1", default-features = false }
4545
url = { version = "2.2", default-features = false }
@@ -51,16 +51,19 @@ glob = { version = "0.3", default-features = false }
5151
smol = "1.2.5"
5252

5353
[features]
54-
default = ["codegen", "cli", "runtime-async-std-native-tls", "async-std"]
55-
codegen = ["sea-schema/sqlx-all", "sea-orm-codegen"]
54+
default = ["codegen", "sqlx-mysql", "sqlx-postgres", "sqlx-sqlite", "runtime-async-std-native-tls", "async-std"]
55+
codegen = ["cli", "sqlx", "sea-schema", "sea-orm-codegen"]
5656
cli = ["clap", "dotenvy"]
57+
sqlx-mysql = ["sqlx?/sqlx-mysql", "sea-schema?/sqlx-mysql", "sea-schema?/mysql"]
58+
sqlx-postgres = ["sqlx?/sqlx-postgres", "sea-schema?/sqlx-postgres", "sea-schema?/postgres"]
59+
sqlx-sqlite = ["sqlx?/sqlx-sqlite", "sea-schema?/sqlx-sqlite", "sea-schema?/sqlite"]
5760
postgres-vector = ["sea-schema/postgres-vector"]
58-
runtime-actix = ["sqlx/runtime-tokio", "sea-schema/runtime-actix"]
59-
runtime-async-std = ["sqlx/runtime-async-std", "sea-schema/runtime-async-std"]
60-
runtime-tokio = ["sqlx/runtime-tokio", "sea-schema/runtime-tokio"]
61-
runtime-actix-native-tls = ["sqlx/runtime-tokio-native-tls", "sea-schema/runtime-actix-native-tls"]
62-
runtime-async-std-native-tls = ["sqlx/runtime-async-std-native-tls", "sea-schema/runtime-async-std-native-tls"]
63-
runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls", "sea-schema/runtime-tokio-native-tls"]
64-
runtime-actix-rustls = ["sqlx/runtime-tokio-rustls", "sea-schema/runtime-actix-rustls"]
65-
runtime-async-std-rustls = ["sqlx/runtime-async-std-rustls", "sea-schema/runtime-async-std-rustls"]
66-
runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls", "sea-schema/runtime-tokio-rustls"]
61+
runtime-actix = ["sqlx?/runtime-tokio", "sea-schema?/runtime-actix"]
62+
runtime-async-std = ["sqlx?/runtime-async-std", "sea-schema?/runtime-async-std"]
63+
runtime-tokio = ["sqlx?/runtime-tokio", "sea-schema?/runtime-tokio"]
64+
runtime-actix-native-tls = ["sqlx?/runtime-tokio-native-tls", "sea-schema?/runtime-actix-native-tls"]
65+
runtime-async-std-native-tls = ["sqlx?/runtime-async-std-native-tls", "sea-schema?/runtime-async-std-native-tls"]
66+
runtime-tokio-native-tls = ["sqlx?/runtime-tokio-native-tls", "sea-schema?/runtime-tokio-native-tls"]
67+
runtime-actix-rustls = ["sqlx?/runtime-tokio-rustls", "sea-schema?/runtime-actix-rustls"]
68+
runtime-async-std-rustls = ["sqlx?/runtime-async-std-rustls", "sea-schema?/runtime-async-std-rustls"]
69+
runtime-tokio-rustls = ["sqlx?/runtime-tokio-rustls", "sea-schema?/runtime-tokio-rustls"]

sea-orm-cli/src/commands/generate.rs

+95-72
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub async fn run_generate_command(
8181

8282
let filter_skip_tables = |table: &String| -> bool { !ignore_tables.contains(table) };
8383

84-
let database_name = if !is_sqlite {
84+
let _database_name = if !is_sqlite {
8585
// The database name should be the first element of the path string
8686
//
8787
// Throwing an error if there is no database name since it might be
@@ -113,81 +113,104 @@ pub async fn run_generate_command(
113113

114114
let (schema_name, table_stmts) = match url.scheme() {
115115
"mysql" => {
116-
use sea_schema::mysql::discovery::SchemaDiscovery;
117-
use sqlx::MySql;
118-
119-
println!("Connecting to MySQL ...");
120-
let connection =
121-
sqlx_connect::<MySql>(max_connections, acquire_timeout, url.as_str(), None)
122-
.await?;
123-
124-
println!("Discovering schema ...");
125-
let schema_discovery = SchemaDiscovery::new(connection, database_name);
126-
let schema = schema_discovery.discover().await?;
127-
let table_stmts = schema
128-
.tables
129-
.into_iter()
130-
.filter(|schema| filter_tables(&schema.info.name))
131-
.filter(|schema| filter_hidden_tables(&schema.info.name))
132-
.filter(|schema| filter_skip_tables(&schema.info.name))
133-
.map(|schema| schema.write())
134-
.collect();
135-
(None, table_stmts)
116+
#[cfg(not(feature = "sqlx-mysql"))]
117+
{
118+
panic!("mysql feature is off")
119+
}
120+
#[cfg(feature = "sqlx-mysql")]
121+
{
122+
use sea_schema::mysql::discovery::SchemaDiscovery;
123+
use sqlx::MySql;
124+
125+
println!("Connecting to MySQL ...");
126+
let connection = sqlx_connect::<MySql>(
127+
max_connections,
128+
acquire_timeout,
129+
url.as_str(),
130+
None,
131+
)
132+
.await?;
133+
println!("Discovering schema ...");
134+
let schema_discovery = SchemaDiscovery::new(connection, _database_name);
135+
let schema = schema_discovery.discover().await?;
136+
let table_stmts = schema
137+
.tables
138+
.into_iter()
139+
.filter(|schema| filter_tables(&schema.info.name))
140+
.filter(|schema| filter_hidden_tables(&schema.info.name))
141+
.filter(|schema| filter_skip_tables(&schema.info.name))
142+
.map(|schema| schema.write())
143+
.collect();
144+
(None, table_stmts)
145+
}
136146
}
137147
"sqlite" => {
138-
use sea_schema::sqlite::discovery::SchemaDiscovery;
139-
use sqlx::Sqlite;
140-
141-
println!("Connecting to SQLite ...");
142-
let connection = sqlx_connect::<Sqlite>(
143-
max_connections,
144-
acquire_timeout,
145-
url.as_str(),
146-
None,
147-
)
148-
.await?;
149-
150-
println!("Discovering schema ...");
151-
let schema_discovery = SchemaDiscovery::new(connection);
152-
let schema = schema_discovery
153-
.discover()
154-
.await?
155-
.merge_indexes_into_table();
156-
let table_stmts = schema
157-
.tables
158-
.into_iter()
159-
.filter(|schema| filter_tables(&schema.name))
160-
.filter(|schema| filter_hidden_tables(&schema.name))
161-
.filter(|schema| filter_skip_tables(&schema.name))
162-
.map(|schema| schema.write())
163-
.collect();
164-
(None, table_stmts)
148+
#[cfg(not(feature = "sqlx-sqlite"))]
149+
{
150+
panic!("sqlite feature is off")
151+
}
152+
#[cfg(feature = "sqlx-sqlite")]
153+
{
154+
use sea_schema::sqlite::discovery::SchemaDiscovery;
155+
use sqlx::Sqlite;
156+
157+
println!("Connecting to SQLite ...");
158+
let connection = sqlx_connect::<Sqlite>(
159+
max_connections,
160+
acquire_timeout,
161+
url.as_str(),
162+
None,
163+
)
164+
.await?;
165+
println!("Discovering schema ...");
166+
let schema_discovery = SchemaDiscovery::new(connection);
167+
let schema = schema_discovery
168+
.discover()
169+
.await?
170+
.merge_indexes_into_table();
171+
let table_stmts = schema
172+
.tables
173+
.into_iter()
174+
.filter(|schema| filter_tables(&schema.name))
175+
.filter(|schema| filter_hidden_tables(&schema.name))
176+
.filter(|schema| filter_skip_tables(&schema.name))
177+
.map(|schema| schema.write())
178+
.collect();
179+
(None, table_stmts)
180+
}
165181
}
166182
"postgres" | "postgresql" => {
167-
use sea_schema::postgres::discovery::SchemaDiscovery;
168-
use sqlx::Postgres;
169-
170-
println!("Connecting to Postgres ...");
171-
let schema = database_schema.as_deref().unwrap_or("public");
172-
let connection = sqlx_connect::<Postgres>(
173-
max_connections,
174-
acquire_timeout,
175-
url.as_str(),
176-
Some(schema),
177-
)
178-
.await?;
179-
println!("Discovering schema ...");
180-
let schema_discovery = SchemaDiscovery::new(connection, schema);
181-
let schema = schema_discovery.discover().await?;
182-
let table_stmts = schema
183-
.tables
184-
.into_iter()
185-
.filter(|schema| filter_tables(&schema.info.name))
186-
.filter(|schema| filter_hidden_tables(&schema.info.name))
187-
.filter(|schema| filter_skip_tables(&schema.info.name))
188-
.map(|schema| schema.write())
189-
.collect();
190-
(database_schema, table_stmts)
183+
#[cfg(not(feature = "sqlx-postgres"))]
184+
{
185+
panic!("postgres feature is off")
186+
}
187+
#[cfg(feature = "sqlx-postgres")]
188+
{
189+
use sea_schema::postgres::discovery::SchemaDiscovery;
190+
use sqlx::Postgres;
191+
192+
println!("Connecting to Postgres ...");
193+
let schema = database_schema.as_deref().unwrap_or("public");
194+
let connection = sqlx_connect::<Postgres>(
195+
max_connections,
196+
acquire_timeout,
197+
url.as_str(),
198+
Some(schema),
199+
)
200+
.await?;
201+
println!("Discovering schema ...");
202+
let schema_discovery = SchemaDiscovery::new(connection, schema);
203+
let schema = schema_discovery.discover().await?;
204+
let table_stmts = schema
205+
.tables
206+
.into_iter()
207+
.filter(|schema| filter_tables(&schema.info.name))
208+
.filter(|schema| filter_hidden_tables(&schema.info.name))
209+
.filter(|schema| filter_skip_tables(&schema.info.name))
210+
.map(|schema| schema.write())
211+
.collect();
212+
(database_schema, table_stmts)
213+
}
191214
}
192215
_ => unimplemented!("{} is not supported", url.scheme()),
193216
};

sea-orm-macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ proc-macro-crate = { version = "3.2.0", optional = true }
2727
unicode-ident = { version = "1" }
2828

2929
[dev-dependencies]
30-
sea-orm = { path = "../", features = ["macros", "tests-cfg"] }
30+
sea-orm = { path = "../", default-features = false, features = ["macros", "tests-cfg"] }
3131
serde = { version = "1.0", features = ["derive"] }
3232

3333
[features]

sea-orm-migration/Cargo.toml

+13-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ clap = { version = "4.3", features = ["env", "derive"], optional = true }
2525
dotenvy = { version = "0.15", default-features = false, optional = true }
2626
sea-orm = { version = "~1.1.8", path = "../", default-features = false, features = ["macros"] }
2727
sea-orm-cli = { version = "~1.1.8", path = "../sea-orm-cli", default-features = false, optional = true }
28-
sea-schema = { version = "0.16.0" }
28+
sea-schema = { version = "0.16.0", default-features = false, features = ["discovery", "writer", "probe"] }
2929
tracing = { version = "0.1", default-features = false, features = ["log"] }
3030
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"] }
3131

@@ -35,19 +35,19 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
3535
[features]
3636
default = ["cli"]
3737
cli = ["clap", "dotenvy", "sea-orm-cli/cli"]
38-
sqlx-mysql = ["sea-orm/sqlx-mysql"]
39-
sqlx-postgres = ["sea-orm/sqlx-postgres"]
40-
sqlx-sqlite = ["sea-orm/sqlx-sqlite"]
38+
sqlx-mysql = ["sea-orm/sqlx-mysql", "sea-schema/sqlx-mysql", "sea-schema/mysql", "sea-orm-cli?/sqlx-mysql"]
39+
sqlx-postgres = ["sea-orm/sqlx-postgres", "sea-schema/sqlx-postgres", "sea-schema/postgres", "sea-orm-cli?/sqlx-postgres"]
40+
sqlx-sqlite = ["sea-orm/sqlx-sqlite", "sea-schema/sqlx-sqlite", "sea-schema/sqlite", "sea-orm-cli?/sqlx-sqlite"]
4141
sqlite-use-returning-for-3_35 = ["sea-orm/sqlite-use-returning-for-3_35"]
42-
runtime-actix = ["sea-orm/runtime-actix"]
43-
runtime-async-std = ["sea-orm/runtime-async-std"]
44-
runtime-tokio = ["sea-orm/runtime-tokio"]
45-
runtime-actix-native-tls = ["sea-orm/runtime-actix-native-tls"]
46-
runtime-async-std-native-tls = ["sea-orm/runtime-async-std-native-tls"]
47-
runtime-tokio-native-tls = ["sea-orm/runtime-tokio-native-tls"]
48-
runtime-actix-rustls = ["sea-orm/runtime-actix-rustls"]
49-
runtime-async-std-rustls = ["sea-orm/runtime-async-std-rustls"]
50-
runtime-tokio-rustls = ["sea-orm/runtime-tokio-rustls"]
42+
runtime-actix = ["sea-orm/runtime-actix", "sea-schema/runtime-actix", "sea-orm-cli?/runtime-actix"]
43+
runtime-async-std = ["sea-orm/runtime-async-std", "sea-schema/runtime-async-std", "sea-orm-cli?/runtime-async-std"]
44+
runtime-tokio = ["sea-orm/runtime-tokio", "sea-schema/runtime-tokio", "sea-orm-cli?/runtime-tokio"]
45+
runtime-actix-native-tls = ["sea-orm/runtime-actix-native-tls", "sea-schema/runtime-actix-native-tls", "sea-orm-cli?/runtime-actix-native-tls"]
46+
runtime-async-std-native-tls = ["sea-orm/runtime-async-std-native-tls", "sea-schema/runtime-async-std-native-tls", "sea-orm-cli?/runtime-async-std-native-tls"]
47+
runtime-tokio-native-tls = ["sea-orm/runtime-tokio-native-tls", "sea-schema/runtime-tokio-native-tls", "sea-orm-cli?/runtime-tokio-native-tls"]
48+
runtime-actix-rustls = ["sea-orm/runtime-actix-rustls", "sea-schema/runtime-actix-rustls", "sea-orm-cli?/runtime-actix-rustls"]
49+
runtime-async-std-rustls = ["sea-orm/runtime-async-std-rustls", "sea-schema/runtime-async-std-rustls", "sea-orm-cli?/runtime-async-std-rustls"]
50+
runtime-tokio-rustls = ["sea-orm/runtime-tokio-rustls", "sea-schema/runtime-tokio-rustls", "sea-orm-cli?/runtime-tokio-rustls"]
5151
with-json = ["sea-orm/with-json"]
5252
with-chrono = ["sea-orm/with-chrono"]
5353
with-rust_decimal = ["sea-orm/with-rust_decimal"]

0 commit comments

Comments
 (0)