Skip to content

Commit

Permalink
My sql case insensitivity during Introspection (#1850)
Browse files Browse the repository at this point in the history
* test case

* don't run re-introspection when previous datamodel is empty

* make sure table and column names are handled case sensitive during distinct and ordering
  • Loading branch information
do4gr committed Apr 14, 2021
1 parent 40a9cd7 commit 5ae5d7a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ pub fn calculate_datamodel(
deduplicate_relation_field_names(&mut data_model);

let mut warnings = vec![];
warnings.append(&mut enrich(previous_data_model, &mut data_model, family));
tracing::debug!("Enriching datamodel is done: {:?}", data_model);
if !previous_data_model.is_empty() {
warnings.append(&mut enrich(previous_data_model, &mut data_model, family));
tracing::debug!("Enriching datamodel is done: {:?}", data_model);
}

// commenting out models, fields, enums, enum values
warnings.append(&mut commenting_out_guardrails(&mut data_model, family));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,46 @@ async fn partial_indexes_should_be_ignored_on_mysql(api: &TestApi) -> crate::Tes

Ok(())
}

#[test_each_connector(tags("mysql"))]
async fn casing_should_not_lead_to_mix_ups(api: &TestApi) -> crate::TestResult {
api.barrel()
.execute_with_schema(
|migration| {
migration.create_table("address", move |t| {
t.inject_custom("addressid INT NOT NULL");
t.inject_custom("PRIMARY KEY(addressid)");
});

migration.create_table("ADDRESS", move |t| {
t.inject_custom("ADDRESSID INT NOT NULL");
t.inject_custom("PRIMARY KEY(ADDRESSID)");
});
migration.create_table("Address", move |t| {
t.inject_custom("AddressID INT NOT NULL AUTO_INCREMENT");
t.inject_custom("PRIMARY KEY(AddressID)");
});
},
api.schema_name(),
)
.await?;

let dm = indoc! {r##"
model ADDRESS {
ADDRESSID Int @id
}
model Address {
AddressID Int @id @default(autoincrement())
}
model address {
addressid Int @id
}
"##};

let result = &api.introspect().await?;
api.assert_eq_datamodels(&dm, result);

Ok(())
}
6 changes: 3 additions & 3 deletions libs/sql-schema-describer/src/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl SqlSchemaDescriber {
WHERE table_schema = ?
-- Views are not supported yet
AND table_type = 'BASE TABLE'
ORDER BY table_name";
ORDER BY Binary table_name";
let rows = self.conn.query_raw(sql, &[schema.into()]).await?;
let names = rows
.into_iter()
Expand Down Expand Up @@ -437,9 +437,9 @@ impl SqlSchemaDescriber {
SELECT DISTINCT
index_name AS index_name,
non_unique AS non_unique,
column_name AS column_name,
Binary column_name AS column_name,
seq_in_index AS seq_in_index,
table_name AS table_name,
Binary table_name AS table_name,
sub_part AS partial
FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_schema = ?
Expand Down

0 comments on commit 5ae5d7a

Please sign in to comment.