28 lines
652 B
Rust
28 lines
652 B
Rust
use std::env;
|
|
|
|
use diesel::prelude::*;
|
|
use diesel_migrations::embed_migrations;
|
|
use dotenv::dotenv;
|
|
|
|
pub mod errors;
|
|
pub mod models;
|
|
pub mod schedules;
|
|
pub mod schema;
|
|
pub mod tag;
|
|
|
|
mod model_utils;
|
|
|
|
embed_migrations!("migrations");
|
|
|
|
fn get_connection() -> SqliteConnection {
|
|
dotenv().ok();
|
|
|
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
|
SqliteConnection::establish(&database_url)
|
|
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
|
}
|
|
|
|
pub fn run_migrations() {
|
|
let connection = get_connection();
|
|
embedded_migrations::run(&connection).expect("Failed to run migrations.");
|
|
}
|