From 4067ddbbb06dcfdb71389da7a7187e9bf6dc0d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABlle=20Huisman?= Date: Sun, 31 Aug 2025 13:13:34 +0200 Subject: [PATCH] feat(sea-orm): remove Sea ORM CLI from migration tests --- .github/workflows/ci.yml | 6 -- Cargo.lock | 1 + examples/axum/Cargo.toml | 2 +- examples/dioxus-axum/Cargo.toml | 5 +- examples/leptos-axum/Cargo.toml | 5 +- examples/workos/Cargo.toml | 5 +- packages/storage/shield-sea-orm/Cargo.toml | 7 ++ .../storage/shield-sea-orm/tests/migration.rs | 69 ++++++------------- 8 files changed, 41 insertions(+), 59 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68e5fcd..60a4c09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,11 +82,5 @@ jobs: components: clippy, rustfmt target: wasm32-unknown-unknown - - name: Install Cargo Binary Install - uses: cargo-bins/cargo-binstall@main - - - name: Install crates - run: cargo binstall -y sea-orm-cli - - name: Test run: cargo test --locked --release diff --git a/Cargo.lock b/Cargo.lock index 69e9261..8ab53a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5785,6 +5785,7 @@ dependencies = [ "shield", "shield-oauth", "shield-oidc", + "tokio", "utoipa", ] diff --git a/examples/axum/Cargo.toml b/examples/axum/Cargo.toml index 440531e..ecced05 100644 --- a/examples/axum/Cargo.toml +++ b/examples/axum/Cargo.toml @@ -16,7 +16,7 @@ shield-axum = { workspace = true, features = ["utoipa"] } shield-memory = { workspace = true, features = ["method-oidc"] } shield-oidc = { workspace = true, features = ["native-tls"] } time = "0.3.37" -tokio = { workspace = true, features = ["rt-multi-thread"] } +tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } tower-sessions.workspace = true tracing.workspace = true tracing-subscriber.workspace = true diff --git a/examples/dioxus-axum/Cargo.toml b/examples/dioxus-axum/Cargo.toml index 6ef10ff..3d120dd 100644 --- a/examples/dioxus-axum/Cargo.toml +++ b/examples/dioxus-axum/Cargo.toml @@ -35,6 +35,9 @@ shield-dioxus.workspace = true shield-dioxus-axum = { workspace = true, optional = true } shield-memory = { workspace = true, optional = true } shield-oidc = { workspace = true, features = ["native-tls"], optional = true } -tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } +tokio = { workspace = true, features = [ + "macros", + "rt-multi-thread", +], optional = true } tower-sessions = { workspace = true, optional = true } tracing.workspace = true diff --git a/examples/leptos-axum/Cargo.toml b/examples/leptos-axum/Cargo.toml index 28781c3..c6d05ed 100644 --- a/examples/leptos-axum/Cargo.toml +++ b/examples/leptos-axum/Cargo.toml @@ -54,7 +54,10 @@ shield-leptos-axum = { workspace = true, features = [ shield-memory = { workspace = true, optional = true } shield-oidc = { workspace = true, features = ["native-tls"], optional = true } time = "0.3.37" -tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } +tokio = { workspace = true, features = [ + "macros", + "rt-multi-thread", +], optional = true } tower-sessions = { workspace = true, optional = true } tracing.workspace = true tracing-subscriber.workspace = true diff --git a/examples/workos/Cargo.toml b/examples/workos/Cargo.toml index 706cd6b..ef694d7 100644 --- a/examples/workos/Cargo.toml +++ b/examples/workos/Cargo.toml @@ -34,6 +34,9 @@ shield-dioxus.workspace = true shield-dioxus-axum = { workspace = true, optional = true } shield-memory = { workspace = true, optional = true } shield-workos = { workspace = true, optional = true } -tokio = { workspace = true, features = ["rt-multi-thread"], optional = true } +tokio = { workspace = true, features = [ + "macros", + "rt-multi-thread", +], optional = true } tower-sessions = { workspace = true, optional = true } tracing.workspace = true diff --git a/packages/storage/shield-sea-orm/Cargo.toml b/packages/storage/shield-sea-orm/Cargo.toml index 44c7144..226fa9d 100644 --- a/packages/storage/shield-sea-orm/Cargo.toml +++ b/packages/storage/shield-sea-orm/Cargo.toml @@ -42,3 +42,10 @@ shield-oauth = { workspace = true, optional = true } shield-oidc = { workspace = true, optional = true } # shield-webauthn = { workspace = true, optional = true } utoipa = { workspace = true, optional = true } + +[dev-dependencies] +tokio = { workspace = true, features = [ + "macros", + "rt-multi-thread", + "test-util", +] } diff --git a/packages/storage/shield-sea-orm/tests/migration.rs b/packages/storage/shield-sea-orm/tests/migration.rs index 77d1f9e..7d64ae4 100644 --- a/packages/storage/shield-sea-orm/tests/migration.rs +++ b/packages/storage/shield-sea-orm/tests/migration.rs @@ -1,12 +1,6 @@ -use std::{ - env, - path::{Path, PathBuf}, - process::Command, -}; - -fn example_path() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../examples/sea-orm") -} +use sea_orm::Database; +use sea_orm_migration::migrator::MigratorTrait; +use shield_sea_orm::migrations::Migrator; const BACKENDS: &[(&str, &str)] = &[ ("mysql", "mysql://shield:shield@localhost:13306/shield"), @@ -17,49 +11,26 @@ const BACKENDS: &[(&str, &str)] = &[ ("sqlite", "sqlite:///tmp/shield-seaorm.sqlite?mode=rwc"), ]; -#[test] -pub fn migrations() { +#[tokio::test] +async fn migrations() { for (backend, url) in BACKENDS { - // Check up migrations - assert!( - Command::new("sea-orm-cli") - .arg("migrate") - .arg("fresh") - .arg("-u") - .arg(url) - .arg("-d") - .arg(example_path()) - .status() - .unwrap_or_else(|_| panic!("{backend} up migrations should succeed.")) - .success() - ); + let database = Database::connect(url.to_owned()) + .await + .unwrap_or_else(|err| panic!("Connect to backend `{backend}` failed: {err}")); + + // Up migrations + Migrator::fresh(&database) + .await + .unwrap_or_else(|err| panic!("Up migrations for backend `{backend}` failed: {err}")); - // Check down migrations - assert!( - Command::new("sea-orm-cli") - .arg("migrate") - .arg("refresh") - .arg("-u") - .arg(url) - .arg("-d") - .arg(example_path()) - .status() - .unwrap_or_else(|_| panic!("{backend} down migrations should succeed.")) - .success() - ); + // Down migrations + Migrator::refresh(&database) + .await + .unwrap_or_else(|err| panic!("Down migrations for backend `{backend}` failed: {err}")); // Cleanup - assert!( - Command::new("sea-orm-cli") - .arg("migrate") - .arg("reset") - .arg("-u") - .arg(url) - .arg("-d") - .arg(example_path()) - .status() - .unwrap_or_else(|_| panic!("{backend} cleanup should succeed.")) - .success() - ); + Migrator::reset(&database) + .await + .unwrap_or_else(|err| panic!("Cleanup for backend `{backend}` failed: {err}")); } }