Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

me: temporarily refuse to handle mysql multi-schema schemas #3493

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/test-setup/src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}