Skip to content

Commit

Permalink
Workaround for issues I hit. For some reason diesel_cli suddenly stop…
Browse files Browse the repository at this point in the history
…ped being able to find the PK in one of my tables. Confirmed the PK is there and even confirmed the SQL query it tries running returns no results... replacing the subquery with a simple string equals check makes it work as expected.
  • Loading branch information
berserkguard committed Aug 10, 2021
1 parent 6e46d08 commit a64295c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
29 changes: 29 additions & 0 deletions diesel_cli/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'diesel'",
"cargo": {
"args": [
"build",
"--bin=diesel",
"--package=diesel_cli",
"--no-default-features",
"--features",
"mysql",
],
"filter": {
"name": "diesel",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
]
}
17 changes: 3 additions & 14 deletions diesel_cli/src/infer_schema_internals/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use diesel::pg::Pg;
use diesel::query_builder::{QueryFragment, QueryId};
use diesel::*;

use self::information_schema::{columns, key_column_usage, table_constraints, tables};
use self::information_schema::{columns, key_column_usage, tables};
use super::data_structures::*;
use super::inference;
use super::table_data::TableName;
Expand Down Expand Up @@ -238,13 +238,7 @@ where
Filter<
Filter<
Select<key_column_usage::table, key_column_usage::column_name>,
EqAny<
key_column_usage::constraint_name,
Filter<
Select<table_constraints::table, table_constraints::constraint_name>,
Eq<table_constraints::constraint_type, &'static str>,
>,
>,
Eq<key_column_usage::constraint_name, &'a str>,
>,
Eq<key_column_usage::table_name, &'a String>,
>,
Expand All @@ -255,11 +249,6 @@ where
Conn::Backend: QueryMetadata<sql_types::Text>,
{
use self::information_schema::key_column_usage::dsl::*;
use self::information_schema::table_constraints::constraint_type;

let pk_query = table_constraints::table
.select(table_constraints::constraint_name)
.filter(constraint_type.eq("PRIMARY KEY"));

let schema_name = match table.schema {
Some(ref name) => Cow::Borrowed(name),
Expand All @@ -268,7 +257,7 @@ where

key_column_usage
.select(column_name)
.filter(constraint_name.eq_any(pk_query))
.filter(constraint_name.eq("PRIMARY"))
.filter(table_name.eq(&table.sql_name))
.filter(table_schema.eq(schema_name))
.order(ordinal_position)
Expand Down
1 change: 1 addition & 0 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn common_diesel_types(types: &mut HashSet<&str>) {
types.insert("Timestamp");
types.insert("Date");
types.insert("Time");
types.insert("Datetime");

// hidden type defs
types.insert("Float4");
Expand Down

0 comments on commit a64295c

Please sign in to comment.