Skip to content

Commit

Permalink
me: temporarily refuse to handle mysql multi-schema schemas
Browse files Browse the repository at this point in the history
Until it is implemented.

closes prisma/prisma#16274
  • Loading branch information
tomhoule committed Dec 15, 2022
1 parent 2eeed5b commit 504db18
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libs/test-setup/src/lib.rs
Expand Up @@ -30,10 +30,10 @@ type AnyError = Box<dyn std::error::Error + Send + Sync + 'static>;
#[macro_export]
macro_rules! only {
($($tag:ident),*) => {
::test_setup::only!($($tag,)* ; exclude: )
::test_setup::only!($($tag),* ; exclude: )
};

($($tag:ident,)* ; exclude: $($excludeTag:ident),*) => {
($($tag:ident),* ; exclude: $($excludeTag:ident),*) => {
{
use ::test_setup::Tags;
let (skip, db) = ::test_setup::only_impl(
Expand Down
Expand Up @@ -124,6 +124,11 @@ pub(crate) trait SqlFlavour:
None
}

/// Check a schema for preview features not implemented in migrate/introspection.
fn check_schema_features(&self, _schema: &psl::ValidatedSchema) -> ConnectorResult<()> {
Ok(())
}

/// The connection string received in set_params().
fn connection_string(&self) -> Option<&str>;

Expand Down
Expand Up @@ -139,6 +139,21 @@ impl SqlFlavour for MysqlFlavour {
}
}

fn check_schema_features(&self, schema: &psl::ValidatedSchema) -> ConnectorResult<()> {
let has_namespaces = schema
.configuration
.datasources
.first()
.map(|ds| !ds.namespaces.is_empty());
if let Some(true) = has_namespaces {
Err(ConnectorError::from_msg(
"multiSchema migrations and introspection are not implemented on MySQL yet".to_owned(),
))
} else {
Ok(())
}
}

fn connection_string(&self) -> Option<&str> {
self.state
.params()
Expand Down
Expand Up @@ -123,6 +123,7 @@ impl SqlMigrationConnector {
match target {
DiffTarget::Datamodel(schema) => {
let schema = psl::parse_schema(schema).map_err(ConnectorError::new_schema_parser_error)?;
self.flavour.check_schema_features(&schema)?;
Ok(sql_schema_calculator::calculate_sql_schema(
&schema,
self.flavour.as_ref(),
Expand Down
4 changes: 2 additions & 2 deletions migration-engine/core/src/commands/schema_push.rs
Expand Up @@ -33,7 +33,7 @@ pub async fn schema_push(

let to = connector
.database_schema_from_diff_target(DiffTarget::Datamodel(source), None, None)
.instrument(tracing::debug_span!("Calculate `to`"))
.instrument(tracing::info_span!("Calculate `to`"))
.await?;

let namespaces = connector.extract_namespaces(&to);
Expand All @@ -43,7 +43,7 @@ pub async fn schema_push(
// particulalry if it's not correctly setting the preview features flags.
let from = connector
.database_schema_from_diff_target(DiffTarget::Database, None, namespaces)
.instrument(tracing::debug_span!("Calculate `from`"))
.instrument(tracing::info_span!("Calculate `from`"))
.await?;
let database_migration = connector.diff(from, to);

Expand Down
40 changes: 40 additions & 0 deletions migration-engine/migration-engine-tests/tests/schema_push/mod.rs
Expand Up @@ -454,3 +454,43 @@ fn issue_repro_extended_indexes(api: TestApi) {
api.schema_push_w_datasource(dm).send().assert_executable();
api.schema_push_w_datasource(dm).send().assert_green().assert_no_steps();
}

#[test]
fn multi_schema_not_implemented_on_mysql() {
test_setup::only!(Mysql ; exclude: Vitess);

if cfg!(windows) {
return;
}

let schema = r#"
generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}
datasource db {
provider = "mysql"
url = env("TEST_DATABASE_URL")
schemas = ["s1", "s2"]
}
model m1 {
id Int @id
@@schema("s2")
}
"#;

let api = migration_core::migration_api(Some(schema.to_owned()), None).unwrap();
let err = tok(api.schema_push(migration_core::json_rpc::types::SchemaPushInput {
force: false,
schema: schema.to_owned(),
}))
.unwrap_err();

let expected = expect_test::expect![[r#"
The `mysql` database is a system database, it should not be altered with prisma migrate. Please connect to another database.
0: migration_core::state::SchemaPush
at migration-engine/core/src/state.rs:398"#]];
expected.assert_eq(&err.to_string());
}

0 comments on commit 504db18

Please sign in to comment.