forked from prisma/prisma-engines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unnest migration_core module structure
We probably also would want JSON-RPC on wasm (wasi).
- Loading branch information
Showing
5 changed files
with
190 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//! Query Engine test setup. | ||
use crate::SqlMigrationConnector; | ||
#[cfg(feature = "mongodb")] | ||
use datamodel::common::provider_names::MONGODB_SOURCE_NAME; | ||
use datamodel::common::provider_names::{ | ||
COCKROACHDB_SOURCE_NAME, MSSQL_SOURCE_NAME, MYSQL_SOURCE_NAME, POSTGRES_SOURCE_NAME, SQLITE_SOURCE_NAME, | ||
}; | ||
use migration_connector::{ConnectorResult, DiffTarget, MigrationConnector}; | ||
#[cfg(feature = "mongodb")] | ||
use mongodb_migration_connector::MongoDbMigrationConnector; | ||
|
||
/// Database setup for connector-test-kit-rs. | ||
pub async fn setup(prisma_schema: &str) -> ConnectorResult<()> { | ||
let (source, url, preview_features, _shadow_database_url) = super::parse_configuration(prisma_schema)?; | ||
|
||
match &source.active_provider { | ||
provider | ||
if [ | ||
MYSQL_SOURCE_NAME, | ||
POSTGRES_SOURCE_NAME, | ||
SQLITE_SOURCE_NAME, | ||
MSSQL_SOURCE_NAME, | ||
COCKROACHDB_SOURCE_NAME, | ||
] | ||
.contains(&provider.as_str()) => | ||
{ | ||
// 1. creates schema & database | ||
SqlMigrationConnector::qe_setup(&url).await?; | ||
let api = SqlMigrationConnector::new(url, preview_features, None)?; | ||
|
||
// 2. create the database schema for given Prisma schema | ||
{ | ||
let (config, schema) = crate::parse_schema(prisma_schema).unwrap(); | ||
let migration = api | ||
.diff(DiffTarget::Empty, DiffTarget::Datamodel((&config, &schema))) | ||
.await | ||
.unwrap(); | ||
api.database_migration_step_applier() | ||
.apply_migration(&migration) | ||
.await | ||
.unwrap(); | ||
}; | ||
} | ||
|
||
#[cfg(feature = "mongodb")] | ||
provider if provider == MONGODB_SOURCE_NAME => { | ||
let connector = MongoDbMigrationConnector::new(url, preview_features); | ||
// Drop database. Creation is automatically done when collections are created. | ||
connector.drop_database().await?; | ||
let (_, schema) = crate::parse_schema(prisma_schema).unwrap(); | ||
connector.create_collections(&schema).await?; | ||
} | ||
|
||
x => unimplemented!("Connector {} is not supported yet", x), | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Database teardown for connector-test-kit-rs. | ||
pub async fn teardown(prisma_schema: &str) -> ConnectorResult<()> { | ||
let (source, url, _, _) = super::parse_configuration(prisma_schema)?; | ||
|
||
match &source.active_provider { | ||
provider | ||
if [ | ||
MYSQL_SOURCE_NAME, | ||
POSTGRES_SOURCE_NAME, | ||
SQLITE_SOURCE_NAME, | ||
MSSQL_SOURCE_NAME, | ||
COCKROACHDB_SOURCE_NAME, | ||
] | ||
.contains(&provider.as_str()) => | ||
{ | ||
SqlMigrationConnector::qe_teardown(&url).await?; | ||
} | ||
|
||
#[cfg(feature = "mongodb")] | ||
provider if provider == MONGODB_SOURCE_NAME => {} | ||
|
||
x => unimplemented!("Connector {} is not supported yet", x), | ||
}; | ||
|
||
Ok(()) | ||
} |
File renamed without changes.