-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure migration progress is not lost for PG, mysql and sqlite (#…
…1991) * fix: ensure migration progress is not lost for PG Fixes #1966. * fix: ensure migration progress is not lost for sqlite This is similar to #1966. * fix: ensure reverse migration progress is not lost for PG See #1966. * fix: ensure reverse migration progress is not lost for sqlite See #1966. * fix: ensure migration progress is not lost for mysql This is similar to #1966. * fix: ensure reverse migration progress is not lost for mysql See #1966. * test: check migration type as well * test: extend migrations testing * fix: work around MySQL implicit commits * refactor: simplify migration testing
- Loading branch information
1 parent
ddffaa7
commit 5e56da8
Showing
35 changed files
with
612 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
use sqlx::migrate::Migrator; | ||
use std::path::Path; | ||
|
||
static EMBEDDED: Migrator = sqlx::migrate!("tests/migrate/migrations"); | ||
static EMBEDDED_SIMPLE: Migrator = sqlx::migrate!("tests/migrate/migrations_simple"); | ||
static EMBEDDED_REVERSIBLE: Migrator = sqlx::migrate!("tests/migrate/migrations_reversible"); | ||
|
||
#[sqlx_macros::test] | ||
async fn same_output() -> anyhow::Result<()> { | ||
let runtime = Migrator::new(Path::new("tests/migrate/migrations")).await?; | ||
let runtime_simple = Migrator::new(Path::new("tests/migrate/migrations_simple")).await?; | ||
let runtime_reversible = | ||
Migrator::new(Path::new("tests/migrate/migrations_reversible")).await?; | ||
|
||
assert_eq!(runtime.migrations.len(), EMBEDDED.migrations.len()); | ||
assert_same(&EMBEDDED_SIMPLE, &runtime_simple); | ||
assert_same(&EMBEDDED_REVERSIBLE, &runtime_reversible); | ||
|
||
for (e, r) in EMBEDDED.iter().zip(runtime.iter()) { | ||
Ok(()) | ||
} | ||
|
||
fn assert_same(embedded: &Migrator, runtime: &Migrator) { | ||
assert_eq!(runtime.migrations.len(), embedded.migrations.len()); | ||
|
||
for (e, r) in embedded.iter().zip(runtime.iter()) { | ||
assert_eq!(e.version, r.version); | ||
assert_eq!(e.description, r.description); | ||
assert_eq!(e.migration_type, r.migration_type); | ||
assert_eq!(e.sql, r.sql); | ||
assert_eq!(e.checksum, r.checksum); | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/migrate/migrations_reversible/20220721124650_add_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE migrations_reversible_test; |
7 changes: 7 additions & 0 deletions
7
tests/migrate/migrations_reversible/20220721124650_add_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE migrations_reversible_test ( | ||
some_id BIGINT NOT NULL PRIMARY KEY, | ||
some_payload BIGINT NOT NUll | ||
); | ||
|
||
INSERT INTO migrations_reversible_test (some_id, some_payload) | ||
VALUES (1, 100); |
2 changes: 2 additions & 0 deletions
2
tests/migrate/migrations_reversible/20220721125033_modify_column.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UPDATE migrations_reversible_test | ||
SET some_payload = some_payload - 1; |
2 changes: 2 additions & 0 deletions
2
tests/migrate/migrations_reversible/20220721125033_modify_column.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UPDATE migrations_reversible_test | ||
SET some_payload = some_payload + 1; |
Oops, something went wrong.