Skip to content

Commit f73e653

Browse files
authored
Merge pull request diesel-rs#2624 from weiznich/fix/2623
Fix diesel-rs#2623
2 parents 75f2515 + 789f58f commit f73e653

9 files changed

Lines changed: 112 additions & 0 deletions

File tree

diesel_cli/src/infer_schema_internals/mysql.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn load_foreign_key_constraints(
5353
let constraints = tc::table
5454
.filter(tc::constraint_type.eq("FOREIGN KEY"))
5555
.filter(tc::table_schema.eq(schema_name))
56+
.filter(kcu::referenced_column_name.is_not_null())
5657
.inner_join(
5758
kcu::table.on(tc::constraint_schema
5859
.eq(kcu::constraint_schema)

diesel_cli/tests/print_schema.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ fn print_schema_with_unmappable_names_and_schema_name() {
153153
)
154154
}
155155

156+
#[test]
157+
fn print_schema_with_seperate_unique_constraint_and_foreign_key() {
158+
test_print_schema("print_schema_regression_test_for_2623", vec![])
159+
}
160+
156161
#[test]
157162
fn schema_file_is_relative_to_project_root() {
158163
let p = project("schema_file_is_relative_to_project_root")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[print_schema]
2+
file = "src/schema.rs"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @generated automatically by Diesel CLI.
2+
3+
diesel::table! {
4+
tab_key1 (id) {
5+
id -> Bigint,
6+
}
7+
}
8+
9+
diesel::table! {
10+
tab_problem (id) {
11+
id -> Bigint,
12+
key1 -> Bigint,
13+
}
14+
}
15+
16+
diesel::joinable!(tab_problem -> tab_key1 (key1));
17+
18+
diesel::allow_tables_to_appear_in_same_query!(
19+
tab_key1,
20+
tab_problem,
21+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE tab_key1(
2+
id bigint NOT NULL auto_increment,
3+
PRIMARY KEY (id)
4+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5+
6+
7+
CREATE TABLE tab_problem (
8+
id bigint NOT NULL auto_increment,
9+
key1 bigint NOT NULL,
10+
11+
PRIMARY KEY (id),
12+
UNIQUE (key1),
13+
CONSTRAINT `key1` FOREIGN KEY (key1) REFERENCES tab_key1(id)
14+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @generated automatically by Diesel CLI.
2+
3+
diesel::table! {
4+
tab1 (id) {
5+
id -> Int8,
6+
}
7+
}
8+
9+
diesel::table! {
10+
tab_problem (id) {
11+
id -> Int8,
12+
key1 -> Int8,
13+
}
14+
}
15+
16+
diesel::joinable!(tab_problem -> tab1 (key1));
17+
18+
diesel::allow_tables_to_appear_in_same_query!(
19+
tab1,
20+
tab_problem,
21+
);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE tab1(
2+
id bigserial NOT NULL,
3+
PRIMARY KEY (id)
4+
);
5+
6+
CREATE TABLE tab_problem (
7+
id bigserial NOT NULL,
8+
key1 bigint NOT NULL,
9+
10+
PRIMARY KEY (id),
11+
UNIQUE (key1),
12+
CONSTRAINT "key1" FOREIGN KEY (key1) REFERENCES tab1(id)
13+
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @generated automatically by Diesel CLI.
2+
3+
diesel::table! {
4+
tab_key1 (id) {
5+
id -> Integer,
6+
}
7+
}
8+
9+
diesel::table! {
10+
tab_problem (id) {
11+
id -> Integer,
12+
key1 -> BigInt,
13+
}
14+
}
15+
16+
diesel::joinable!(tab_problem -> tab_key1 (key1));
17+
18+
diesel::allow_tables_to_appear_in_same_query!(
19+
tab_key1,
20+
tab_problem,
21+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE tab_key1(
2+
id integer NOT NULL,
3+
PRIMARY KEY (id)
4+
);
5+
6+
7+
CREATE TABLE tab_problem (
8+
id integer NOT NULL,
9+
key1 bigint NOT NULL,
10+
11+
PRIMARY KEY (id),
12+
UNIQUE (key1),
13+
CONSTRAINT `key1` FOREIGN KEY (key1) REFERENCES tab_key1(id)
14+
);

0 commit comments

Comments
 (0)