forked from rust-lang/crates.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
20 lines (19 loc) · 813 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use diesel::prelude::*;
use diesel_migrations::{FileBasedMigrations, MigrationHarness};
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=TEST_DATABASE_URL");
println!("cargo:rerun-if-changed=.env");
println!("cargo:rerun-if-changed=migrations/");
if env::var("PROFILE") == Ok("debug".into()) {
if let Ok(database_url) = dotenvy::var("TEST_DATABASE_URL") {
let connection = &mut PgConnection::establish(&database_url)
.expect("Could not connect to TEST_DATABASE_URL");
let migrations = FileBasedMigrations::find_migrations_directory()
.expect("Could not find migrations");
connection
.run_pending_migrations(migrations)
.expect("Error running migrations");
}
}
}