Skip to content

Commit

Permalink
add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
eviefp committed Apr 26, 2023
1 parent ce4481d commit a6ea7b8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions schema-engine/connectors/schema-connector/src/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct Warnings {
pub non_default_index_null_sort_order: Vec<IndexedColumn>,
/// Warn about using row level security, which is currently unsupported.
pub row_level_security_tables: Vec<Model>,
/// Warn about using MySQL multi value indices.
pub mysql_multi_value_indices: Vec<Model>,
/// Warn about check constraints.
pub check_constraints: Vec<ModelAndConstraint>,
/// Warn about exclusion constraints.
Expand Down Expand Up @@ -277,6 +279,11 @@ impl fmt::Display for Warnings {
&self.row_level_security_tables,
f,
)?;
render_warnings(
"These tables contain multi-value indices, which are not yet fully supported. Read more: https://pris.ly/d/mysql-multi-row-index",
&self.mysql_multi_value_indices,
f,
)?;

render_warnings(
"These constraints are not supported by the Prisma Client, because Prisma currently does not fully support check constraints. Read more: https://pris.ly/d/postgres-check-constraints",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ impl<'a> ModelPair<'a> {
self.next.has_subclass()
}

/// Whether the model has MySQL multi value indices.
pub(crate) fn has_mysql_multi_value_indes(self) -> bool {
self.next
.indexes()
.any(|i| i.index_type() == sql::IndexType::MySQLMultiValueIndex)
}

/// True, if we add a new model with a subclass.
pub(crate) fn new_with_subclass(self) -> bool {
self.previous.is_none() && self.has_subclass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub(super) fn generate_warnings(model: ModelPair<'_>, warnings: &mut Warnings) {
});
}

if model.has_mysql_multi_value_indes() {
warnings.mysql_multi_value_indices.push(generators::Model {
model: model.name().to_string(),
});
}

if model.uses_duplicate_name() {
warnings.duplicate_names.push(generators::TopLevelItem {
r#type: generators::TopLevelType::Model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,47 @@ PARTITIONS 2; "#,

Ok(())
}

#[test_connector(tags(Mysql8))]
async fn mysql_multi_row_index_warning(api: &mut TestApi) -> TestResult {
api.raw_cmd(
r#"
CREATE TABLE customers (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
modified DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
custinfo JSON,
INDEX zips( (CAST(custinfo->'$.zipcode' AS UNSIGNED ARRAY)) )
); "#,
)
.await;

let expected = expect![[r#"
*** WARNING ***
These tables contain multi-value indices, which are not yet fully supported. Read more: https://pris.ly/d/mysql-multi-row-index
- "customers"
"#]];

api.expect_warnings(&expected).await;

let expected = expect![[r#"
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = "env(TEST_DATABASE_URL)"
}
model customers {
id BigInt @id @default(autoincrement())
modified DateTime? @default(now()) @db.DateTime(0)
custinfo Json?
}
"#]];

api.expect_datamodel(&expected).await;

Ok(())
}

0 comments on commit a6ea7b8

Please sign in to comment.