Skip to content

Commit

Permalink
Test all PK types on mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Mar 19, 2020
1 parent 5b1e76a commit fd1fb1d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
75 changes: 74 additions & 1 deletion query-engine/prisma/src/tests/type_mappings/mysql_types.rs
Expand Up @@ -273,7 +273,7 @@ async fn mysql_bit_columns_are_properly_mapped_to_signed_integers(api: &TestApi)
Ok(())
}

#[test_each_connector(tags("mysql"), log = "debug")]
#[test_each_connector(tags("mysql"))]
async fn mysql_floats_do_not_lose_precision(api: &TestApi) -> TestResult {
api.execute_sql(CREATE_TYPES_TABLE).await?;

Expand Down Expand Up @@ -313,3 +313,76 @@ async fn mysql_floats_do_not_lose_precision(api: &TestApi) -> TestResult {

Ok(())
}

#[test_each_connector(tags("mysql"), log = "debug")]
async fn all_mysql_identifier_types_work(api: &TestApi) -> TestResult {
let identifier_types = &[
("tinyint", "12", ""),
("smallint", "350", ""),
("int", "9002", ""),
("bigint", "30000", ""),
("decimal(4, 2)", "3.1", ""),
// ("float", "2.8", ""),
("double", "0.1", ""),
("real", "12.1", ""),
("bit(32)", "4", ""),
("boolean", "true", ""),
("date", "\"2020-02-27T00:00:00.000Z\"", ""),
("datetime", "\"2020-02-27T19:10:22.000Z\"", ""),
("timestamp", "\"2020-02-27T19:11:22.000Z\"", ""),
// ("time", "\"1970-01-01T12:50:01.000Z\"", ""),
("year", "2091", ""),
("char(18)", "\"make dolphins easy\"", ""),
("varchar(200)", "\"dolphins of varying characters\"", ""),
("tinytext", "\"tiny dolphins\"", "(20)"),
("text", "\"dolphins\"", "(100)"),
("mediumtext", "\"medium dolphins\"", "(100)"),
("longtext", "\"long dolphins\"", "(100)"),
(
"enum('pollicle_dogs','jellicle_cats')",
"\"jellicle_cats\"",
"",
),
// ("json", "\"{\\\"name\\\": null}\"", ""),
];

let drop_table = r#"DROP TABLE IF EXISTS `pk_test`"#;

for (identifier_type, identifier_value, prefix) in identifier_types {
for index_type in &["PRIMARY KEY", "CONSTRAINT UNIQUE INDEX"] {
let create_pk_table = format!(
r#"CREATE TABLE `pk_test` (id {} NOT NULL, {} (id{}))"#,
identifier_type, index_type, prefix
);
api.execute_sql(drop_table).await?;
api.execute_sql(&create_pk_table).await?;

let (_datamodel, engine) = api.introspect_and_start_query_engine().await?;

let query = format!(
r#"
mutation {{
createOnepk_test(
data: {{
id: {}
}}
) {{
id
}}
}}
"#,
identifier_value
);

let response = engine.request(query).await;

let expected_response = format!(
r#"{{"data":{{"createOnepk_test":{{"id":{}}}}}}}"#,
identifier_value
);
assert_eq!(response.to_string(), expected_response);
}
}

Ok(())
}
Expand Up @@ -497,7 +497,7 @@ async fn all_postgres_id_types_work(api: &TestApi) -> TestResult {
("boolean", "true"),
("inet", "\"127.0.0.4\""),
// ("json", "\"{ \\\"isThisPrimaryKeyReallyJSON\\\": true }\""),
// ("jsonb", "\"{ \\\"isThisPrimaryKeyReallyJSON\\\": true }\""),
("jsonb", "\"{ \\\"isThisPrimaryKeyReallyJSON\\\": true }\""),
];

let drop_table = r#"DROP TABLE IF EXISTS "prisma-tests"."pk_test""#;
Expand Down
4 changes: 4 additions & 0 deletions query-engine/prisma/src/tests/type_mappings/test_api.rs
Expand Up @@ -12,6 +12,10 @@ pub struct TestApi {
}

impl TestApi {
pub fn connection(&self) -> &Quaint {
&self.connection
}

fn datasource(&self) -> String {
format!(
r#"
Expand Down

0 comments on commit fd1fb1d

Please sign in to comment.