Skip to content

Commit

Permalink
Merge pull request #3186 from weiznich/fix/allow_mysql_tables_with_da…
Browse files Browse the repository at this point in the history
…tetime_and_json_sql_types

Allow mysql schemas that contain either a json or a datatime field
  • Loading branch information
weiznich authored May 27, 2022
2 parents b51e658 + 5282adb commit ecd22fb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ fn mysql_diesel_types() -> HashSet<&'static str> {

types.insert("TinyInt");
types.insert("Tinyint");
types.insert("Datetime");
types.insert("Json");
types
}

Expand Down
6 changes: 6 additions & 0 deletions diesel_cli/tests/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[print_schema]
file = "src/schema.rs"
with_docs = true
Original file line number Diff line number Diff line change
@@ -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<Datetime>`.
///
/// (Automatically generated by Diesel.)
nullable_datetime -> Nullable<Datetime>,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE users (
id INTEGER PRIMARY KEY,
datetime DATETIME NOT NULL,
nullable_datetime DATETIME
);

0 comments on commit ecd22fb

Please sign in to comment.