Skip to content

Commit 9337858

Browse files
committed
Actually output Unsigned types in print-schema
This got missed in the original PR. Fixes diesel-rs#1642.
1 parent d0fdb7e commit 9337858

6 files changed

Lines changed: 60 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
1212

1313
[record-1-3-0]: http://docs.diesel.rs/diesel/pg/types/sql_types/struct.Record.html
1414

15+
### Fixed
16+
17+
* `diesel print-schema` and `infer_schema!` now properly handle unsigned types
18+
in MySQL
19+
1520
## [1.2.2] - 2018-04-12
1621

1722
### Changed

diesel_cli/tests/print_schema.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ fn print_schema_column_renaming() {
6969
test_print_schema("print_schema_column_renaming", vec!["--with-docs"]);
7070
}
7171

72+
#[test]
73+
#[cfg(feature = "mysql")]
74+
fn print_schema_unsigned() {
75+
test_print_schema("print_schema_unsigned", vec!["--with-docs"]);
76+
}
77+
7278
#[cfg(feature = "sqlite")]
7379
const BACKEND: &str = "sqlite";
7480
#[cfg(feature = "postgres")]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[print_schema]
2+
file = "src/schema.rs"
3+
with_docs = true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
table! {
2+
/// Representation of the `users1` table.
3+
///
4+
/// (Automatically generated by Diesel.)
5+
users1 (id) {
6+
/// The `id` column of the `users1` table.
7+
///
8+
/// Its SQL type is `Unsigned<Integer>`.
9+
///
10+
/// (Automatically generated by Diesel.)
11+
id -> Unsigned<Integer>,
12+
/// The `x` column of the `users1` table.
13+
///
14+
/// Its SQL type is `Nullable<Unsigned<Integer>>`.
15+
///
16+
/// (Automatically generated by Diesel.)
17+
x -> Nullable<Unsigned<Integer>>,
18+
}
19+
}
20+
21+
table! {
22+
/// Representation of the `users2` table.
23+
///
24+
/// (Automatically generated by Diesel.)
25+
users2 (id) {
26+
/// The `id` column of the `users2` table.
27+
///
28+
/// Its SQL type is `Integer`.
29+
///
30+
/// (Automatically generated by Diesel.)
31+
id -> Integer,
32+
}
33+
}
34+
35+
allow_tables_to_appear_in_same_query!(
36+
users1,
37+
users2,
38+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE users1 (id INTEGER UNSIGNED PRIMARY KEY, x INTEGER UNSIGNED);
2+
CREATE TABLE users2 (id INTEGER PRIMARY KEY);

diesel_infer_schema/infer_schema_internals/src/data_structures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ impl fmt::Display for ColumnType {
3434
if self.is_array {
3535
write!(out, "Array<")?;
3636
}
37+
if self.is_unsigned {
38+
write!(out, "Unsigned<")?;
39+
}
3740
write!(out, "{}", self.rust_name)?;
41+
if self.is_unsigned {
42+
write!(out, ">")?;
43+
}
3844
if self.is_array {
3945
write!(out, ">")?;
4046
}

0 commit comments

Comments
 (0)