2020-05-09 15:41:25 +00:00
|
|
|
pub mod character;
|
2020-04-25 13:41:27 +00:00
|
|
|
pub mod stats;
|
|
|
|
|
2020-04-20 08:44:29 +00:00
|
|
|
mod error;
|
2020-05-09 15:41:25 +00:00
|
|
|
mod models;
|
|
|
|
mod schema;
|
|
|
|
|
|
|
|
extern crate diesel;
|
|
|
|
|
|
|
|
use diesel::prelude::*;
|
|
|
|
use diesel_migrations::embed_migrations;
|
2020-05-12 23:58:15 +00:00
|
|
|
use std::fs;
|
2020-05-09 15:41:25 +00:00
|
|
|
|
|
|
|
// See: https://docs.rs/diesel_migrations/1.4.0/diesel_migrations/macro.embed_migrations.html
|
|
|
|
// This macro is called at build-time, and produces the necessary migration info
|
|
|
|
// for the `embedded_migrations` call below.
|
|
|
|
embed_migrations!();
|
|
|
|
|
2020-05-12 23:58:15 +00:00
|
|
|
pub fn run_migrations(db_dir: &str) -> Result<(), diesel_migrations::RunMigrationsError> {
|
|
|
|
let _ = fs::create_dir(format!("{}/", db_dir));
|
|
|
|
embedded_migrations::run_with_output(&establish_connection(db_dir), &mut std::io::stdout())
|
2020-05-09 15:41:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 23:58:15 +00:00
|
|
|
fn establish_connection(db_dir: &str) -> SqliteConnection {
|
|
|
|
let database_url = format!("{}/db.sqlite", db_dir);
|
2020-05-09 15:41:25 +00:00
|
|
|
SqliteConnection::establish(&database_url)
|
|
|
|
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
|
|
|
}
|