Skip to content

Commit bfb6c3b

Browse files
authored
Shield SeaORM: Fix down migrations by cleaning up missing type (#13)
* fix: missing type cleanup in down migration * feat: improve migration tests for sea-orm * fix: migrations linting
1 parent e04b544 commit bfb6c3b

File tree

3 files changed

+60
-37
lines changed

3 files changed

+60
-37
lines changed

packages/storage/shield-sea-orm/src/migrations/providers/oauth/m20241211_095111_create_provider_oauth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ impl MigrationTrait for Migration {
218218
manager
219219
.drop_type(Type::drop().name(OauthProviderType::Table).to_owned())
220220
.await?;
221+
222+
manager
223+
.drop_type(
224+
Type::drop()
225+
.name(OauthProviderPkceCodeChallenge::Table)
226+
.to_owned(),
227+
)
228+
.await?;
221229
}
222230
}
223231

packages/storage/shield-sea-orm/src/migrations/providers/oidc/m20241211_184751_create_provider_oidc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ impl MigrationTrait for Migration {
217217
manager
218218
.drop_type(Type::drop().name(OidcProviderType::Table).to_owned())
219219
.await?;
220+
221+
manager
222+
.drop_type(
223+
Type::drop()
224+
.name(OidcProviderPkceCodeChallenge::Table)
225+
.to_owned(),
226+
)
227+
.await?;
220228
}
221229
}
222230

packages/storage/shield-sea-orm/tests/migration.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,51 @@ fn example_path() -> PathBuf {
88
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../examples/sea-orm")
99
}
1010

11-
#[test]
12-
pub fn mysql() {
13-
assert!(Command::new("sea-orm-cli")
14-
.arg("migrate")
15-
.arg("fresh")
16-
.arg("-u")
17-
.arg("mysql://shield:shield@localhost:13306/shield")
18-
.arg("-d")
19-
.arg(example_path())
20-
.status()
21-
.expect("MySQL migration should succeed.")
22-
.success());
23-
}
11+
const BACKENDS: &[(&str, &str)] = &[
12+
("mysql", "mysql://shield:shield@localhost:13306/shield"),
13+
(
14+
"postgresql",
15+
"postgres://shield:shield@localhost:15432/shield",
16+
),
17+
("sqlite", "sqlite:///tmp/shield-seaorm.sqlite?mode=rwc"),
18+
];
2419

2520
#[test]
26-
pub fn postgresql() {
27-
assert!(Command::new("sea-orm-cli")
28-
.arg("migrate")
29-
.arg("fresh")
30-
.arg("-u")
31-
.arg("postgres://shield:shield@localhost:15432/shield")
32-
.arg("-d")
33-
.arg(example_path())
34-
.status()
35-
.expect("MySQL migration should succeed.")
36-
.success());
37-
}
21+
pub fn migrations() {
22+
for (backend, url) in BACKENDS {
23+
assert!(Command::new("sea-orm-cli")
24+
.arg("migrate")
25+
.arg("fresh")
26+
.arg("-u")
27+
.arg(url)
28+
.arg("-d")
29+
.arg(example_path())
30+
.status()
31+
.unwrap_or_else(|_| panic!("{} initial migrations should succeed.", backend))
32+
.success());
3833

39-
#[test]
40-
pub fn sqlite() {
41-
assert!(Command::new("sea-orm-cli")
42-
.arg("migrate")
43-
.arg("fresh")
44-
.arg("-u")
45-
.arg("sqlite:///tmp/shield-seaorm.sqlite?mode=rwc")
46-
.arg("-d")
47-
.arg(example_path())
48-
.status()
49-
.expect("MySQL migration should succeed.")
50-
.success());
34+
// Check down migrations
35+
assert!(Command::new("sea-orm-cli")
36+
.arg("migrate")
37+
.arg("refresh")
38+
.arg("-u")
39+
.arg(url)
40+
.arg("-d")
41+
.arg(example_path())
42+
.status()
43+
.unwrap_or_else(|_| panic!("{} down migrations should succeed.", backend))
44+
.success());
45+
46+
// Cleanup
47+
assert!(Command::new("sea-orm-cli")
48+
.arg("migrate")
49+
.arg("reset")
50+
.arg("-u")
51+
.arg(url)
52+
.arg("-d")
53+
.arg(example_path())
54+
.status()
55+
.unwrap_or_else(|_| panic!("{} cleanup should succeed.", backend))
56+
.success());
57+
}
5158
}

0 commit comments

Comments
 (0)