mirror of
https://github.com/diesel-rs/diesel.git
synced 2024-10-04 17:47:17 +03:00
Ensure that we are *actually* able to compile without PG
While the tests were passing previously, we didn't actually build if you compiled without libpq installed on your system. This corrects those issues, and the failures that resulted from it. There are several places where I'm legitimately unsure how the code compiled before this change. I've had to do some janky things to codegen to make it actually work, as there's an issue where cfg attrs aren't properly applied inside of `include!`. This is why the dummy version has to exist, and why it warns instead of errors. It might make sense to just define the macro as a no-op in the future.
This commit is contained in:
parent
d9f733f856
commit
9da6065fb5
@ -43,7 +43,7 @@ matrix:
|
||||
allow_failures:
|
||||
- rust: nightly
|
||||
after_success:
|
||||
- "(cd diesel && travis-cargo --only stable doc-upload -- --features \"postgres sqlite\")"
|
||||
- "(cd diesel && travis-cargo --only stable doc-upload)"
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
@ -17,12 +17,13 @@ syntex_syntax = { version = "^0.26.0", optional = true }
|
||||
[dependencies]
|
||||
syntex = { version = "^0.26.0", optional = true }
|
||||
syntex_syntax = { version = "^0.26.0", optional = true }
|
||||
diesel = { git = "https://github.com/sgrif/diesel.git" }
|
||||
diesel = { path = "../diesel", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["with-syntex"]
|
||||
default = ["with-syntex", "postgres"]
|
||||
nightly = []
|
||||
with-syntex = ["syntex", "syntex_syntax"]
|
||||
postgres = ["diesel/postgres"]
|
||||
|
||||
[lib]
|
||||
name = "diesel_codegen"
|
||||
|
21
diesel_codegen/src/dummy_schema_inference.rs
Normal file
21
diesel_codegen/src/dummy_schema_inference.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::ext::base::*;
|
||||
|
||||
pub fn expand_load_table<'cx>(
|
||||
cx: &'cx mut ExtCtxt,
|
||||
sp: Span,
|
||||
_tts: &[ast::TokenTree]
|
||||
) -> Box<MacResult+'cx> {
|
||||
cx.span_warn(sp, "load_table_from_schema! is only supported on PostgreSQL");
|
||||
DummyResult::any(sp)
|
||||
}
|
||||
|
||||
pub fn expand_infer_schema<'cx>(
|
||||
cx: &'cx mut ExtCtxt,
|
||||
sp: Span,
|
||||
_tts: &[ast::TokenTree]
|
||||
) -> Box<MacResult+'cx> {
|
||||
cx.span_warn(sp, "infer_schema! is only supported on PostgreSQL");
|
||||
DummyResult::any(sp)
|
||||
}
|
@ -3,5 +3,10 @@ mod attr;
|
||||
mod insertable;
|
||||
mod model;
|
||||
mod queryable;
|
||||
#[cfg(feature = "postgres")]
|
||||
mod schema_inference;
|
||||
#[cfg(not(feature = "postgres"))]
|
||||
#[path="dummy_schema_inference.rs"]
|
||||
mod schema_inference;
|
||||
|
||||
mod update;
|
||||
|
@ -9,7 +9,7 @@ build = "build.rs"
|
||||
syntex = { version = "^0.26.0", optional = true }
|
||||
diesel_codegen = { path = "../diesel_codegen", default-features = false }
|
||||
dotenv_codegen = { git = "https://github.com/slapresta/rust-dotenv.git", optional = true }
|
||||
diesel = { path = "../diesel" }
|
||||
diesel = { path = "../diesel", default-features = false }
|
||||
dotenv = { git = "https://github.com/slapresta/rust-dotenv.git" }
|
||||
|
||||
[dependencies]
|
||||
@ -26,7 +26,7 @@ quickcheck = { git = "https://github.com/BurntSushi/quickcheck.git" }
|
||||
default = ["syntex", "diesel_codegen/with-syntex", "dotenv_codegen"]
|
||||
unstable = ["compiletest_rs", "diesel_codegen/nightly", "diesel/unstable",
|
||||
"quickcheck/unstable", "dotenv_macros"]
|
||||
postgres = ["diesel/postgres"]
|
||||
postgres = ["diesel/postgres", "diesel_codegen/postgres"]
|
||||
sqlite = ["diesel/sqlite"]
|
||||
|
||||
[[test]]
|
||||
|
@ -25,19 +25,33 @@ mod inner {
|
||||
pub fn main() {}
|
||||
}
|
||||
|
||||
extern crate diesel;
|
||||
extern crate dotenv;
|
||||
use diesel::*;
|
||||
use diesel::pg::PgConnection;
|
||||
use dotenv::dotenv;
|
||||
use std::io;
|
||||
#[cfg(feature = "postgres")]
|
||||
mod outer {
|
||||
extern crate diesel;
|
||||
extern crate dotenv;
|
||||
use self::diesel::*;
|
||||
use self::diesel::pg::PgConnection;
|
||||
use self::dotenv::dotenv;
|
||||
use std::io;
|
||||
|
||||
pub fn main() {
|
||||
dotenv().ok();
|
||||
let database_url = ::std::env::var("DATABASE_URL")
|
||||
.expect("DATABASE_URL must be set to run tests");
|
||||
let connection = PgConnection::establish(&database_url).unwrap();
|
||||
let migrations_dir = migrations::find_migrations_directory().unwrap().join("postgresql");
|
||||
migrations::run_pending_migrations_in_directory(&connection, &migrations_dir, &mut io::sink()).unwrap();
|
||||
::inner::main();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "postgres"))]
|
||||
mod outer {
|
||||
pub fn main() {
|
||||
::inner::main();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dotenv().ok();
|
||||
let database_url = ::std::env::var("DATABASE_URL")
|
||||
.expect("DATABASE_URL must be set to run tests");
|
||||
let connection = PgConnection::establish(&database_url).unwrap();
|
||||
let migrations_dir = migrations::find_migrations_directory().unwrap().join("postgresql");
|
||||
migrations::run_pending_migrations_in_directory(&connection, &migrations_dir, &mut io::sink()).unwrap();
|
||||
inner::main();
|
||||
outer::main();
|
||||
}
|
||||
|
@ -94,13 +94,13 @@ mod associations_can_have_nullable_foreign_keys {
|
||||
|
||||
table! {
|
||||
foos{
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
bars {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
foo_id -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::expression::count;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use diesel::expression::count;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
title -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,14 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
title -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
title -> VarChar,
|
||||
user_id -> Integer,
|
||||
}
|
||||
|
@ -5,14 +5,14 @@ use diesel::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
title -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::expression::AsExpression;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ use diesel::types::*;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
posts {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
title -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::expression::dsl::*;
|
||||
|
||||
table! {
|
||||
stuff {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ use diesel::pg::PgConnection;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
hair_color -> VarChar,
|
||||
}
|
@ -6,7 +6,7 @@ use diesel::pg::PgConnection;
|
||||
|
||||
table! {
|
||||
int_primary_key {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::pg::PgConnection;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::pg::PgConnection;
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use diesel::types::{Integer, VarChar};
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use diesel::types::{Integer, VarChar};
|
||||
|
||||
table! {
|
||||
users {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
name -> VarChar,
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use diesel::expression::dsl::*;
|
||||
|
||||
table! {
|
||||
has_timestamps {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
created_at -> Timestamp,
|
||||
updated_at -> Timestamp,
|
||||
}
|
||||
@ -15,7 +15,7 @@ operator_allowed!(has_timestamps::created_at, Add, add);
|
||||
|
||||
table! {
|
||||
has_time {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
time -> Time,
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +107,6 @@ fn arbitrary<T>() -> Arbitrary<T> {
|
||||
|
||||
#[test]
|
||||
fn max_accepts_all_numeric_string_and_date_types() {
|
||||
let _ = users.select(max(arbitrary::<types::SmallSerial>()));
|
||||
let _ = users.select(max(arbitrary::<types::Serial>()));
|
||||
let _ = users.select(max(arbitrary::<types::BigSerial>()));
|
||||
let _ = users.select(max(arbitrary::<types::SmallInt>()));
|
||||
let _ = users.select(max(arbitrary::<types::Integer>()));
|
||||
let _ = users.select(max(arbitrary::<types::BigInt>()));
|
||||
@ -119,9 +116,6 @@ fn max_accepts_all_numeric_string_and_date_types() {
|
||||
let _ = users.select(max(arbitrary::<types::VarChar>()));
|
||||
let _ = users.select(max(arbitrary::<types::Text>()));
|
||||
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::SmallSerial>>()));
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::Serial>>()));
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::BigSerial>>()));
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::SmallInt>>()));
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::Integer>>()));
|
||||
let _ = users.select(max(arbitrary::<types::Nullable<types::BigInt>>()));
|
||||
@ -202,7 +196,7 @@ fn test_sum_for_double() {
|
||||
|
||||
table! {
|
||||
nullable_doubles {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
n -> Nullable<Double>,
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,12 @@ pub struct Comment {
|
||||
}
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
mod backend_specifics {
|
||||
include!("postgres_specific_schema.rs");
|
||||
}
|
||||
#[path="postgres_specific_schema.rs"]
|
||||
mod backend_specifics;
|
||||
|
||||
#[cfg(feature = "sqlite")]
|
||||
mod backend_specifics {
|
||||
include!("sqlite_specific_schema.rs");
|
||||
}
|
||||
#[path="sqlite_specific_schema.rs"]
|
||||
mod backend_specifics;
|
||||
|
||||
pub use self::backend_specifics::*;
|
||||
|
||||
|
@ -103,7 +103,7 @@ fn selecting_expression_with_bind_param() {
|
||||
|
||||
table! {
|
||||
select {
|
||||
id -> Serial,
|
||||
id -> Integer,
|
||||
join -> Integer,
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ pub use schema::{connection, TestConnection};
|
||||
pub use diesel::*;
|
||||
pub use diesel::result::Error;
|
||||
pub use diesel::data_types::*;
|
||||
pub use diesel::types::{HasSqlType, ToSql, Nullable, Array};
|
||||
pub use diesel::types::{HasSqlType, ToSql, Nullable};
|
||||
|
||||
use diesel::expression::AsExpression;
|
||||
use diesel::query_builder::QueryFragment;
|
||||
@ -58,7 +58,7 @@ macro_rules! test_round_trip {
|
||||
#[cfg(feature = "postgres")]
|
||||
fn vec_round_trip(val: Vec<$tpe>) -> bool {
|
||||
let val: Vec<_> = val.into_iter().map($map_fn).collect();
|
||||
test_type_round_trips::<Array<types::$sql_type>, _>(val)
|
||||
test_type_round_trips::<types::Array<types::$sql_type>, _>(val)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "postgres"))]
|
||||
|
Loading…
Reference in New Issue
Block a user