-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs
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,119 @@ | ||
use std::sync::Arc; | ||
|
||
use migration_core::{ | ||
commands::{ApplyMigrationsInput, CreateMigrationInput}, | ||
GenericApi, | ||
}; | ||
use tempfile::TempDir; | ||
use test_macros::test_each_connector; | ||
use test_setup::TestAPIArgs; | ||
|
||
type TestResult = Result<(), anyhow::Error>; | ||
|
||
struct TestApi { | ||
args: TestAPIArgs, | ||
source: String, | ||
url: String, | ||
} | ||
|
||
impl TestApi { | ||
/// Create a temporary directory to serve as a test migrations directory. | ||
pub fn create_migrations_directory(&self) -> anyhow::Result<TempDir> { | ||
Ok(tempfile::tempdir()?) | ||
} | ||
|
||
async fn new_engine(&self) -> anyhow::Result<Arc<dyn GenericApi>> { | ||
Ok(migration_core::migration_api(&self.source).await?) | ||
} | ||
|
||
async fn initialize(&self) -> anyhow::Result<()> { | ||
test_setup::create_postgres_database(&self.url.parse()?).await.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
async fn postgres9_test_api(args: TestAPIArgs) -> TestApi { | ||
TestApi { | ||
source: test_setup::postgres_9_test_config(&args.test_function_name), | ||
url: test_setup::postgres_9_url(&args.test_function_name), | ||
args, | ||
} | ||
} | ||
|
||
async fn postgres_test_api(args: TestAPIArgs) -> TestApi { | ||
TestApi { | ||
source: test_setup::postgres_10_test_config(&args.test_function_name), | ||
url: test_setup::postgres_10_url(&args.test_function_name), | ||
args, | ||
} | ||
} | ||
|
||
async fn postgres11_test_api(args: TestAPIArgs) -> TestApi { | ||
TestApi { | ||
source: test_setup::postgres_11_test_config(&args.test_function_name), | ||
url: test_setup::postgres_11_url(&args.test_function_name), | ||
args, | ||
} | ||
} | ||
|
||
async fn postgres12_test_api(args: TestAPIArgs) -> TestApi { | ||
TestApi { | ||
source: test_setup::postgres_12_test_config(&args.test_function_name), | ||
url: test_setup::postgres_12_url(&args.test_function_name), | ||
args, | ||
} | ||
} | ||
|
||
async fn postgres13_test_api(args: TestAPIArgs) -> TestApi { | ||
TestApi { | ||
source: test_setup::postgres_13_test_config(&args.test_function_name), | ||
url: test_setup::postgres_13_url(&args.test_function_name), | ||
args, | ||
} | ||
} | ||
|
||
#[test_each_connector(tags("postgres"), log = "debug")] | ||
async fn advisory_locking_works(api: &TestApi) -> TestResult { | ||
api.initialize().await?; | ||
|
||
let first_me = api.new_engine().await?; | ||
let migrations_directory = api.create_migrations_directory()?; | ||
let p = migrations_directory.path().to_string_lossy().into_owned(); | ||
|
||
let dm = r#" | ||
model Cat { | ||
id Int @id | ||
inBox Boolean | ||
} | ||
"#; | ||
|
||
let output = first_me | ||
.create_migration(&CreateMigrationInput { | ||
migrations_directory_path: p.clone(), | ||
prisma_schema: dm.into(), | ||
migration_name: "01initial".into(), | ||
draft: true, | ||
}) | ||
.await?; | ||
|
||
let migration_name = output.generated_migration_name.expect("generated no migration"); | ||
|
||
let second_me = api.new_engine().await?; | ||
let third_me = api.new_engine().await?; | ||
|
||
let input = ApplyMigrationsInput { | ||
migrations_directory_path: p, | ||
}; | ||
|
||
let (result_1, result_2, result_3) = tokio::join!( | ||
second_me.apply_migrations(&input), | ||
first_me.apply_migrations(&input), | ||
third_me.apply_migrations(&input), | ||
); | ||
|
||
panic!("here"); | ||
dbg!(result_1, result_2, result_3); | ||
|
||
Ok(()) | ||
} |
1 change: 1 addition & 0 deletions
1
migration-engine/migration-engine-tests/tests/migrations/mod.rs
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,3 +1,4 @@ | ||
mod advisory_locking; | ||
mod apply_script_tests; | ||
mod dev_diagnostic_tests; | ||
mod enums; | ||
|