Repository: diesel-rs/diesel (language: rust)

Issue:
bin/test fails in master
## Setup
checkout master

### Versions

- **Rust:** rustc 1.48.0 (7eac88abb 2020-11-16)
- **Diesel:** bada4ad305d279049d0f9716ecde4735144c795c
- **Database:** postgres 13.2.1 mysql 5.5.62 sqlite3
- **Operating System**: debian buster

### Feature Flags

- **diesel:** the issue seems to be caused when both the postgres and sqlite features are enabled at the same time

## Problem Description
Right now bin/test fails on master out of the box.  It appears to trace back to https://github.com/diesel-rs/diesel/commit/11f4369ca

```
failures:

---- src/sqlite/expression/expression_methods.rs - sqlite::expression::expression_methods::SqliteExpressionMethods::is (line 20) stdout ----
error[E0271]: type mismatch resolving `<diesel::PgConnection as diesel::Connection>::Backend == Sqlite`
  --> src/sqlite/expression/expression_methods.rs:33:6
   |
14 |     .get_results::<Option<String>>(&connection)?;
   |      ^^^^^^^^^^^ expected struct `Pg`, found struct `Sqlite`
   |
   = note: required because of the requirements on the impl of `LoadQuery<diesel::PgConnection, Option<String>>` for `SelectStatement<schema::animals::table, diesel::query_builder::select_clause::SelectClause<schema::animals::columns::name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<Grouped<sqlite::expression::operators::Is<schema::animals::columns::species, diesel::expression::bound::Bound<diesel::sql_types::Text, &str>>>>>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
Couldn't compile the test.
---- src/sqlite/expression/expression_methods.rs - sqlite::expression::expression_methods::SqliteExpressionMethods::is_not (line 55) stdout ----
error[E0271]: type mismatch resolving `<diesel::PgConnection as diesel::Connection>::Backend == Sqlite`
  --> src/sqlite/expression/expression_methods.rs:68:6
   |
14 |     .get_results::<Option<String>>(&connection)?;
   |      ^^^^^^^^^^^ expected struct `Pg`, found struct `Sqlite`
   |
   = note: required because of the requirements on the impl of `LoadQuery<diesel::PgConnection, Option<String>>` for `SelectStatement<schema::animals::table, diesel::query_builder::select_clause::SelectClause<schema::animals::columns::name>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::WhereClause<Grouped<sqlite::expression::operators::IsNot<schema::animals::columns::species, diesel::expression::bound::Bound<diesel::sql_types::Text, &str>>>>>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
Couldn't compile the test.

failures:
    src/sqlite/expression/expression_methods.rs - sqlite::expression::expression_methods::SqliteExpressionMethods::is (line 20)
    src/sqlite/expression/expression_methods.rs - sqlite::expression::expression_methods::SqliteExpressionMethods::is_not (line 55)

test result: FAILED. 177 passed; 2 failed; 16 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--doc'
```

### What are you trying to accomplish?
Run tests in order to prepare to work on diesel

### What is the expected output?
working tests

### What is the actual output?
see above

### Are you seeing any additional errors?
no

### Steps to reproduce
checkout master
./bin/test

## Checklist

- [x] I have already looked over the [issue tracker](https://github.com/diesel-rs/diesel/issues)  and the [disussion forum](https://github.com/diesel-rs/diesel/discussions)  for similar possible closed issues.
- [ ] This issue can be reproduced on Rust's stable channel. (Your issue will be
  closed if this is not the case)
- [x] This issue can be reproduced without requiring a third party crate


Discussion / hints:

Fix patch:
diff --git a/diesel_dynamic_schema/Cargo.toml b/diesel_dynamic_schema/Cargo.toml
index aa7ad93ed12a..d89efac5d06d 100644
--- a/diesel_dynamic_schema/Cargo.toml
+++ b/diesel_dynamic_schema/Cargo.toml
@@ -36,7 +36,7 @@ path = "tests/lib.rs"
 harness = true
 
 [features]
-default = ["mysql"]
+default = []
 postgres = ["diesel/postgres"]
 sqlite = ["diesel/sqlite"]
 mysql = ["diesel/mysql"]
diff --git a/diesel_dynamic_schema/src/dynamic_value.rs b/diesel_dynamic_schema/src/dynamic_value.rs
index a3a0716a2445..240581db107c 100644
--- a/diesel_dynamic_schema/src/dynamic_value.rs
+++ b/diesel_dynamic_schema/src/dynamic_value.rs
@@ -151,7 +151,7 @@
 
 use diesel::backend::Backend;
 use diesel::deserialize::{self, FromSql};
-use diesel::expression::{QueryMetadata, TypedExpressionType};
+use diesel::expression::TypedExpressionType;
 use diesel::row::{Field, NamedRow, Row};
 use diesel::QueryableByName;
 use std::iter::FromIterator;
@@ -166,21 +166,21 @@ pub struct Any;
 impl TypedExpressionType for Any {}
 
 #[cfg(feature = "postgres")]
-impl QueryMetadata<Any> for diesel::pg::Pg {
+impl diesel::expression::QueryMetadata<Any> for diesel::pg::Pg {
     fn row_metadata(_lookup: &Self::MetadataLookup, out: &mut Vec<Option<Self::TypeMetadata>>) {
         out.push(None)
     }
 }
 
 #[cfg(feature = "sqlite")]
-impl QueryMetadata<Any> for diesel::sqlite::Sqlite {
+impl diesel::expression::QueryMetadata<Any> for diesel::sqlite::Sqlite {
     fn row_metadata(_lookup: &Self::MetadataLookup, out: &mut Vec<Option<Self::TypeMetadata>>) {
         out.push(None)
     }
 }
 
 #[cfg(feature = "mysql")]
-impl QueryMetadata<Any> for diesel::mysql::Mysql {
+impl diesel::expression::QueryMetadata<Any> for diesel::mysql::Mysql {
     fn row_metadata(_lookup: &Self::MetadataLookup, out: &mut Vec<Option<Self::TypeMetadata>>) {
         out.push(None)
     }
diff --git a/examples/mysql/getting_started_step_1/src/schema.rs b/examples/mysql/getting_started_step_1/src/schema.rs
index eda90bcab0b7..54b162bb0c20 100644
--- a/examples/mysql/getting_started_step_1/src/schema.rs
+++ b/examples/mysql/getting_started_step_1/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,
diff --git a/examples/mysql/getting_started_step_2/src/schema.rs b/examples/mysql/getting_started_step_2/src/schema.rs
index eda90bcab0b7..54b162bb0c20 100644
--- a/examples/mysql/getting_started_step_2/src/schema.rs
+++ b/examples/mysql/getting_started_step_2/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,
diff --git a/examples/mysql/getting_started_step_3/src/schema.rs b/examples/mysql/getting_started_step_3/src/schema.rs
index eda90bcab0b7..54b162bb0c20 100644
--- a/examples/mysql/getting_started_step_3/src/schema.rs
+++ b/examples/mysql/getting_started_step_3/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,
diff --git a/examples/postgres/advanced-blog-cli/src/schema.rs b/examples/postgres/advanced-blog-cli/src/schema.rs
index 2f2a2f7f2a9d..ee6346c63e2e 100644
--- a/examples/postgres/advanced-blog-cli/src/schema.rs
+++ b/examples/postgres/advanced-blog-cli/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     comments (id) {
         id -> Int4,
diff --git a/examples/postgres/custom_types/src/schema.rs b/examples/postgres/custom_types/src/schema.rs
index 3294bb84f6d6..e271250ec16e 100644
--- a/examples/postgres/custom_types/src/schema.rs
+++ b/examples/postgres/custom_types/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     use diesel::sql_types::*;
     use crate::model::exports::*;
diff --git a/examples/postgres/getting_started_step_1/src/schema.rs b/examples/postgres/getting_started_step_1/src/schema.rs
index a007b361813a..e769c9936ac4 100644
--- a/examples/postgres/getting_started_step_1/src/schema.rs
+++ b/examples/postgres/getting_started_step_1/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Int4,
diff --git a/examples/postgres/getting_started_step_2/src/schema.rs b/examples/postgres/getting_started_step_2/src/schema.rs
index a007b361813a..e769c9936ac4 100644
--- a/examples/postgres/getting_started_step_2/src/schema.rs
+++ b/examples/postgres/getting_started_step_2/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Int4,
diff --git a/examples/postgres/getting_started_step_3/src/schema.rs b/examples/postgres/getting_started_step_3/src/schema.rs
index a007b361813a..e769c9936ac4 100644
--- a/examples/postgres/getting_started_step_3/src/schema.rs
+++ b/examples/postgres/getting_started_step_3/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Int4,
diff --git a/examples/sqlite/getting_started_step_1/src/schema.rs b/examples/sqlite/getting_started_step_1/src/schema.rs
index 6cf175136c6b..af8680bb82dc 100644
--- a/examples/sqlite/getting_started_step_1/src/schema.rs
+++ b/examples/sqlite/getting_started_step_1/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,
diff --git a/examples/sqlite/getting_started_step_2/src/schema.rs b/examples/sqlite/getting_started_step_2/src/schema.rs
index 6cf175136c6b..af8680bb82dc 100644
--- a/examples/sqlite/getting_started_step_2/src/schema.rs
+++ b/examples/sqlite/getting_started_step_2/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,
diff --git a/examples/sqlite/getting_started_step_3/src/schema.rs b/examples/sqlite/getting_started_step_3/src/schema.rs
index 6cf175136c6b..af8680bb82dc 100644
--- a/examples/sqlite/getting_started_step_3/src/schema.rs
+++ b/examples/sqlite/getting_started_step_3/src/schema.rs
@@ -1,3 +1,5 @@
+// @generated automatically by Diesel CLI.
+
 diesel::table! {
     posts (id) {
         id -> Integer,


Test patch:
diff --git a/bin/test b/bin/test
index 97ad1f019911..e1d4099e19e4 100755
--- a/bin/test
+++ b/bin/test
@@ -17,29 +17,36 @@ elif [ "$1" = "compile" ]; then
   shift
   (cd diesel_compile_tests && cargo test $*)
 else
-  (cd diesel && cargo test --no-default-features --features "extras sqlite postgres" $*)
-  (cd diesel && RUST_TEST_THREADS=1 cargo test --no-default-features --features "mysql" $*)
+  (cd diesel && cargo test --no-default-features --features "extras sqlite" $*)
+  (cd diesel && cargo test --no-default-features --features "extras postgres" $*)
+  (cd diesel && cargo test --no-default-features --features "mysql" $* -- --test-threads 1)
 
   (cd diesel_cli && cargo test --features "sqlite" --no-default-features $*)
   (cd diesel_migrations && cargo test --features "sqlite diesel/sqlite" $*)
+  (cd diesel_migrations && cargo test --features "sqlite diesel/sqlite" $*)
   (cd diesel_derives && cargo test --features "diesel/sqlite" $*)
   (cd diesel_tests && cargo test --features "sqlite" --no-default-features $*)
+  (cd diesel_dynamic_schema && cargo test --features "sqlite" $*)
+  (cd diesel_bench && cargo test --features "sqlite" $*)
 
   (cd diesel_migrations && cargo test --features "postgres diesel/postgres" $*)
+  (cd diesel_migrations/migrations_macros && cargo test --features "diesel/postgres postgres" $*)
   (cd diesel_derives && cargo test --features "diesel/postgres" $*)
   (cd diesel_cli && cargo test --features "postgres" --no-default-features $*)
   (cd diesel_tests && cargo test --features "postgres" --no-default-features $*)
+  (cd diesel_dynamic_schema && cargo test --features "postgres" $*)
+  (cd diesel_bench && cargo test --features "postgres" $*)
 
-  export RUST_TEST_THREADS=1
-  (cd diesel_migrations && cargo test --features "mysql diesel/mysql" $*)
-  (cd diesel_derives && cargo test --features "diesel/mysql" $*)
-  (cd diesel_cli && cargo test --features "mysql" --no-default-features $*)
-  (cd diesel_tests && cargo test --features "mysql" --no-default-features $*)
-  unset RUST_TEST_THREADS
+  (cd diesel_migrations && cargo test --features "mysql diesel/mysql" $* -- --test-threads 1)
+  (cd diesel_migrations/migrations_macros && cargo test --features "diesel/mysql mysql" $* -- --test-threads 1)
+  (cd diesel_derives && cargo test --features "diesel/mysql" $* -- --test-threads 1)
+  (cd diesel_cli && cargo test --features "mysql" --no-default-features $* -- --test-threads 1)
+  (cd diesel_tests && cargo test --features "mysql" --no-default-features $* -- --test-threads 1)
+  (cd diesel_dynamic_schema && cargo test --features "mysql" $* -- --test-threads 1)
+  (cd diesel_bench && cargo test --features "mysql" $* -- --test-threads 1)
 
   (cd diesel_compile_tests && cargo test $*)
   (cd diesel_migrations/migrations_internals && cargo test $*)
-  (cd diesel_migrations/migrations_macros && cargo test $*)
   export BACKEND="mysql sqlite postgres"
   (cd examples && ./test_all $*)
 fi;
diff --git a/diesel/src/doctest_setup.rs b/diesel/src/doctest_setup.rs
index c7995e39f039..9bb04378d184 100644
--- a/diesel/src/doctest_setup.rs
+++ b/diesel/src/doctest_setup.rs
@@ -19,7 +19,7 @@ cfg_if::cfg_if! {
             connection.execute("DROP TABLE IF EXISTS posts CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS comments CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS brands CASCADE").unwrap();
-
+       
             connection
         }
 
@@ -128,11 +128,13 @@ cfg_if::cfg_if! {
         fn connection_no_data() -> MysqlConnection {
             let connection_url = database_url_from_env("MYSQL_UNIT_TEST_DATABASE_URL");
             let connection = MysqlConnection::establish(&connection_url).unwrap();
+            connection.execute("SET FOREIGN_KEY_CHECKS=0;").unwrap();
             connection.execute("DROP TABLE IF EXISTS users CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS animals CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS posts CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS comments CASCADE").unwrap();
             connection.execute("DROP TABLE IF EXISTS brands CASCADE").unwrap();
+            connection.execute("SET FOREIGN_KEY_CHECKS=1;").unwrap();
 
             connection
         }
diff --git a/examples/mysql/test_all b/examples/mysql/test_all
index 772e3124dcab..77b23a8aa043 100755
--- a/examples/mysql/test_all
+++ b/examples/mysql/test_all
@@ -1,6 +1,10 @@
 #!/bin/sh
 set -e
 
+SCRIPTPATH=`dirname $0`
+
+cd $SCRIPTPATH
+
 set -a
 if [ -f ../../.env ]; then . ../../.env; fi
 DATABASE_URL=${MYSQL_EXAMPLE_DATABASE_URL}
@@ -9,9 +13,11 @@ if [ -z "$BACKEND" ]; then
 fi
 set +a
 
-for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
-  cd $dir
-  ../../../bin/diesel database reset
-  cargo build
-  cd ..
-done
+if [ -z "${BACKEND##*mysql*}" ]; then
+  for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
+    cd $dir
+    ../../../bin/diesel database reset
+    cargo build
+    cd ..
+  done
+fi
diff --git a/examples/postgres/test_all b/examples/postgres/test_all
index 94e4dab04360..782aad45f8bc 100755
--- a/examples/postgres/test_all
+++ b/examples/postgres/test_all
@@ -1,6 +1,10 @@
 #!/bin/sh
 set -e
 
+SCRIPTPATH=`dirname $0`
+
+cd $SCRIPTPATH
+
 set -a
 if [ -f ../../.env ]; then . ../../.env; fi
 DATABASE_URL=${PG_EXAMPLE_DATABASE_URL}
@@ -9,13 +13,15 @@ if [ -z "$BACKEND" ]; then
 fi
 set +a
 
-for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
-  cd $dir
+if [ -z "${BACKEND##*postgres*}" ]; then
+  for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
+    cd $dir
+  
+    if [ -d "migrations" ]; then
+      ../../../bin/diesel database reset
+    fi
 
-  if [ -d "migrations" ]; then
-    ../../../bin/diesel database reset
-  fi
-
-  cargo test
-  cd ..
-done
+    cargo test
+    cd ..
+  done
+fi
diff --git a/examples/sqlite/test_all b/examples/sqlite/test_all
index f9474e58a948..b1964a0ead8a 100755
--- a/examples/sqlite/test_all
+++ b/examples/sqlite/test_all
@@ -1,15 +1,21 @@
 #!/bin/sh
 set -e
 
+SCRIPTPATH=`dirname $0`
+
 export DATABASE_URL="/tmp/test_examples.db"
 
 if [ -z "$BACKEND" ]; then
     export BACKEND="sqlite"
 fi
 
-for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
-  cd $dir
-  ../../../bin/diesel database reset
-  cargo build
-  cd ..
-done
+cd $SCRIPTPATH
+
+if [ -z "${BACKEND##*sqlite*}" ]; then
+  for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
+    cd $dir
+    ../../../bin/diesel database reset
+    cargo build
+    cd ..
+  done
+fi
diff --git a/examples/test_all b/examples/test_all
index 0bfa526ecd3c..0191a6d1d868 100755
--- a/examples/test_all
+++ b/examples/test_all
@@ -1,6 +1,12 @@
 #!/bin/sh
 set -e
 
+SCRIPT=$(readlink -f $0)
+SCRIPTPATH=`dirname $SCRIPT`
+
+cd $SCRIPTPATH
+
 for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
-  (cd $dir && ./test_all)
+    echo $dir
+    (cd $dir && ./test_all)
 done