From 5282adbdc76087f1cc5538319bec0e1e77fea397 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Tue, 24 May 2022 23:20:20 +0200 Subject: [PATCH] Allow mysql schemas that contain either a json or a datatime field Unfortunately we cannot add a test for json, as the behaviour there diverges between mariadb and mysql. --- diesel_cli/src/print_schema.rs | 2 ++ diesel_cli/tests/print_schema.rs | 6 +++++ .../diesel.toml | 3 +++ .../mysql/expected.rs | 27 +++++++++++++++++++ .../mysql/schema.sql | 5 ++++ 5 files changed, 43 insertions(+) create mode 100644 diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/diesel.toml create mode 100644 diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/expected.rs create mode 100644 diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/schema.sql diff --git a/diesel_cli/src/print_schema.rs b/diesel_cli/src/print_schema.rs index a4b5a9694015..0e59f4846069 100644 --- a/diesel_cli/src/print_schema.rs +++ b/diesel_cli/src/print_schema.rs @@ -144,6 +144,8 @@ fn mysql_diesel_types() -> HashSet<&'static str> { types.insert("TinyInt"); types.insert("Tinyint"); + types.insert("Datetime"); + types.insert("Json"); types } diff --git a/diesel_cli/tests/print_schema.rs b/diesel_cli/tests/print_schema.rs index fdaa90f9b72b..34c98aa9f980 100644 --- a/diesel_cli/tests/print_schema.rs +++ b/diesel_cli/tests/print_schema.rs @@ -123,6 +123,12 @@ fn print_schema_unsigned() { test_print_schema("print_schema_unsigned", vec!["--with-docs"]); } +#[test] +#[cfg(feature = "mysql")] +fn print_schema_datetime_for_mysql() { + test_print_schema("print_schema_datetime_for_mysql", vec!["--with-docs"]); +} + #[test] #[cfg(not(windows))] fn print_schema_patch_file() { diff --git a/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/diesel.toml b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/diesel.toml new file mode 100644 index 000000000000..750e5ba85830 --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/diesel.toml @@ -0,0 +1,3 @@ +[print_schema] +file = "src/schema.rs" +with_docs = true diff --git a/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/expected.rs b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/expected.rs new file mode 100644 index 000000000000..3d8b74e74a4c --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/expected.rs @@ -0,0 +1,27 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + /// Representation of the `users` table. + /// + /// (Automatically generated by Diesel.) + users (id) { + /// The `id` column of the `users` table. + /// + /// Its SQL type is `Integer`. + /// + /// (Automatically generated by Diesel.) + id -> Integer, + /// The `datetime` column of the `users` table. + /// + /// Its SQL type is `Datetime`. + /// + /// (Automatically generated by Diesel.) + datetime -> Datetime, + /// The `nullable_datetime` column of the `users` table. + /// + /// Its SQL type is `Nullable`. + /// + /// (Automatically generated by Diesel.) + nullable_datetime -> Nullable, + } +} diff --git a/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/schema.sql b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/schema.sql new file mode 100644 index 000000000000..0b6f2d2e5e38 --- /dev/null +++ b/diesel_cli/tests/print_schema/print_schema_datetime_for_mysql/mysql/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE users ( + id INTEGER PRIMARY KEY, + datetime DATETIME NOT NULL, + nullable_datetime DATETIME +);