diff --git a/libs/test-setup/src/lib.rs b/libs/test-setup/src/lib.rs index a4261c38e317..7382d720b8f6 100644 --- a/libs/test-setup/src/lib.rs +++ b/libs/test-setup/src/lib.rs @@ -30,10 +30,10 @@ type AnyError = Box; #[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( diff --git a/migration-engine/connectors/sql-migration-connector/src/flavour.rs b/migration-engine/connectors/sql-migration-connector/src/flavour.rs index 7eaf0f23b794..d27832e1ef67 100644 --- a/migration-engine/connectors/sql-migration-connector/src/flavour.rs +++ b/migration-engine/connectors/sql-migration-connector/src/flavour.rs @@ -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>; diff --git a/migration-engine/connectors/sql-migration-connector/src/flavour/mysql.rs b/migration-engine/connectors/sql-migration-connector/src/flavour/mysql.rs index 3ae6d310ad5f..ad624214c0cd 100644 --- a/migration-engine/connectors/sql-migration-connector/src/flavour/mysql.rs +++ b/migration-engine/connectors/sql-migration-connector/src/flavour/mysql.rs @@ -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() diff --git a/migration-engine/connectors/sql-migration-connector/src/lib.rs b/migration-engine/connectors/sql-migration-connector/src/lib.rs index 669bda3cdb78..552693488e4d 100644 --- a/migration-engine/connectors/sql-migration-connector/src/lib.rs +++ b/migration-engine/connectors/sql-migration-connector/src/lib.rs @@ -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(), diff --git a/migration-engine/core/src/commands/schema_push.rs b/migration-engine/core/src/commands/schema_push.rs index 1cefc59597c2..2673d42f1eae 100644 --- a/migration-engine/core/src/commands/schema_push.rs +++ b/migration-engine/core/src/commands/schema_push.rs @@ -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); @@ -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); diff --git a/migration-engine/migration-engine-tests/tests/schema_push/mod.rs b/migration-engine/migration-engine-tests/tests/schema_push/mod.rs index 64816ddb41af..53ca39e31284 100644 --- a/migration-engine/migration-engine-tests/tests/schema_push/mod.rs +++ b/migration-engine/migration-engine-tests/tests/schema_push/mod.rs @@ -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()); +}