forked from diesel-rs/diesel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
65 lines (53 loc) · 1.77 KB
/
Copy pathbuild.rs
File metadata and controls
65 lines (53 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[cfg(not(feature = "unstable"))]
mod inner {
extern crate syntex;
extern crate diesel_codegen_syntex as diesel_codegen;
extern crate dotenv_codegen;
use std::env;
use std::path::Path;
pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut registry = syntex::Registry::new();
diesel_codegen::register(&mut registry);
dotenv_codegen::register(&mut registry);
let src = Path::new("tests/lib.in.rs");
let dst = Path::new(&out_dir).join("lib.rs");
registry.expand("", &src, &dst).unwrap();
}
}
#[cfg(feature = "unstable")]
mod inner {
pub fn main() {}
}
extern crate diesel;
extern crate dotenv;
use self::diesel::*;
use self::dotenv::dotenv;
use std::io;
#[cfg(feature = "postgres")]
use self::diesel::pg::PgConnection;
#[cfg(feature = "postgres")]
fn connection() -> PgConnection {
dotenv().ok();
let database_url = ::std::env::var("DATABASE_URL")
.expect("DATABASE_URL must be set to run tests");
PgConnection::establish(&database_url).unwrap()
}
#[cfg(feature = "sqlite")]
use self::diesel::sqlite::SqliteConnection;
#[cfg(feature = "sqlite")]
fn connection() -> SqliteConnection {
dotenv().ok();
let database_url = ::std::env::var("DATABASE_URL")
.expect("DATABASE_URL must be set to run tests");
SqliteConnection::establish(&database_url).unwrap()
}
#[cfg(feature = "postgres")]
const MIGRATION_SUBDIR: &'static str = "postgresql";
#[cfg(feature = "sqlite")]
const MIGRATION_SUBDIR: &'static str = "sqlite";
fn main() {
let migrations_dir = migrations::find_migrations_directory().unwrap().join(MIGRATION_SUBDIR);
migrations::run_pending_migrations_in_directory(&connection(), &migrations_dir, &mut io::sink()).unwrap();
::inner::main();
}