Skip to content

Commit d334cc5

Browse files
feat(sea-orm): remove Sea ORM CLI from migration tests (#174)
1 parent 05ad4a0 commit d334cc5

8 files changed

Lines changed: 41 additions & 59 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,5 @@ jobs:
8282
components: clippy, rustfmt
8383
target: wasm32-unknown-unknown
8484

85-
- name: Install Cargo Binary Install
86-
uses: cargo-bins/cargo-binstall@main
87-
88-
- name: Install crates
89-
run: cargo binstall -y sea-orm-cli
90-
9185
- name: Test
9286
run: cargo test --locked --release

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/axum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ shield-axum = { workspace = true, features = ["utoipa"] }
1616
shield-memory = { workspace = true, features = ["method-oidc"] }
1717
shield-oidc = { workspace = true, features = ["native-tls"] }
1818
time = "0.3.37"
19-
tokio = { workspace = true, features = ["rt-multi-thread"] }
19+
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
2020
tower-sessions.workspace = true
2121
tracing.workspace = true
2222
tracing-subscriber.workspace = true

examples/dioxus-axum/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ shield-dioxus.workspace = true
3535
shield-dioxus-axum = { workspace = true, optional = true }
3636
shield-memory = { workspace = true, optional = true }
3737
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
38-
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
38+
tokio = { workspace = true, features = [
39+
"macros",
40+
"rt-multi-thread",
41+
], optional = true }
3942
tower-sessions = { workspace = true, optional = true }
4043
tracing.workspace = true

examples/leptos-axum/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ shield-leptos-axum = { workspace = true, features = [
5454
shield-memory = { workspace = true, optional = true }
5555
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
5656
time = "0.3.37"
57-
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
57+
tokio = { workspace = true, features = [
58+
"macros",
59+
"rt-multi-thread",
60+
], optional = true }
5861
tower-sessions = { workspace = true, optional = true }
5962
tracing.workspace = true
6063
tracing-subscriber.workspace = true

examples/workos/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ shield-dioxus.workspace = true
3434
shield-dioxus-axum = { workspace = true, optional = true }
3535
shield-memory = { workspace = true, optional = true }
3636
shield-workos = { workspace = true, optional = true }
37-
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
37+
tokio = { workspace = true, features = [
38+
"macros",
39+
"rt-multi-thread",
40+
], optional = true }
3841
tower-sessions = { workspace = true, optional = true }
3942
tracing.workspace = true

packages/storage/shield-sea-orm/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ shield-oauth = { workspace = true, optional = true }
4242
shield-oidc = { workspace = true, optional = true }
4343
# shield-webauthn = { workspace = true, optional = true }
4444
utoipa = { workspace = true, optional = true }
45+
46+
[dev-dependencies]
47+
tokio = { workspace = true, features = [
48+
"macros",
49+
"rt-multi-thread",
50+
"test-util",
51+
] }
Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
use std::{
2-
env,
3-
path::{Path, PathBuf},
4-
process::Command,
5-
};
6-
7-
fn example_path() -> PathBuf {
8-
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../examples/sea-orm")
9-
}
1+
use sea_orm::Database;
2+
use sea_orm_migration::migrator::MigratorTrait;
3+
use shield_sea_orm::migrations::Migrator;
104

115
const BACKENDS: &[(&str, &str)] = &[
126
("mysql", "mysql://shield:shield@localhost:13306/shield"),
@@ -17,49 +11,26 @@ const BACKENDS: &[(&str, &str)] = &[
1711
("sqlite", "sqlite:///tmp/shield-seaorm.sqlite?mode=rwc"),
1812
];
1913

20-
#[test]
21-
pub fn migrations() {
14+
#[tokio::test]
15+
async fn migrations() {
2216
for (backend, url) in BACKENDS {
23-
// Check up migrations
24-
assert!(
25-
Command::new("sea-orm-cli")
26-
.arg("migrate")
27-
.arg("fresh")
28-
.arg("-u")
29-
.arg(url)
30-
.arg("-d")
31-
.arg(example_path())
32-
.status()
33-
.unwrap_or_else(|_| panic!("{backend} up migrations should succeed."))
34-
.success()
35-
);
17+
let database = Database::connect(url.to_owned())
18+
.await
19+
.unwrap_or_else(|err| panic!("Connect to backend `{backend}` failed: {err}"));
20+
21+
// Up migrations
22+
Migrator::fresh(&database)
23+
.await
24+
.unwrap_or_else(|err| panic!("Up migrations for backend `{backend}` failed: {err}"));
3625

37-
// Check down migrations
38-
assert!(
39-
Command::new("sea-orm-cli")
40-
.arg("migrate")
41-
.arg("refresh")
42-
.arg("-u")
43-
.arg(url)
44-
.arg("-d")
45-
.arg(example_path())
46-
.status()
47-
.unwrap_or_else(|_| panic!("{backend} down migrations should succeed."))
48-
.success()
49-
);
26+
// Down migrations
27+
Migrator::refresh(&database)
28+
.await
29+
.unwrap_or_else(|err| panic!("Down migrations for backend `{backend}` failed: {err}"));
5030

5131
// Cleanup
52-
assert!(
53-
Command::new("sea-orm-cli")
54-
.arg("migrate")
55-
.arg("reset")
56-
.arg("-u")
57-
.arg(url)
58-
.arg("-d")
59-
.arg(example_path())
60-
.status()
61-
.unwrap_or_else(|_| panic!("{backend} cleanup should succeed."))
62-
.success()
63-
);
32+
Migrator::reset(&database)
33+
.await
34+
.unwrap_or_else(|err| panic!("Cleanup for backend `{backend}` failed: {err}"));
6435
}
6536
}

0 commit comments

Comments
 (0)