Move stuff from hammond_data/src/lib.rs into utils.
This commit is contained in:
parent
563f249a48
commit
a6dbf65575
@ -14,7 +14,7 @@ use rayon::prelude::*;
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
use hammond_data::run_migration_on;
|
use hammond_data::utils::run_migration_on;
|
||||||
use hammond_data::models::NewSource;
|
use hammond_data::models::NewSource;
|
||||||
use hammond_data::feed::{index, Feed};
|
use hammond_data::feed::{index, Feed};
|
||||||
use hammond_data::Database;
|
use hammond_data::Database;
|
||||||
@ -51,7 +51,7 @@ fn get_temp_db() -> TempDB {
|
|||||||
.join(format!("hammonddb_{}.db", rng.gen::<usize>()));
|
.join(format!("hammonddb_{}.db", rng.gen::<usize>()));
|
||||||
|
|
||||||
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
||||||
::run_migration_on(&db).unwrap();
|
run_migration_on(&db).unwrap();
|
||||||
|
|
||||||
TempDB(tmp_dir, db_path, db)
|
TempDB(tmp_dir, db_path, db)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use diesel::result;
|
use diesel::result;
|
||||||
|
use diesel::migrations::RunMigrationsError;
|
||||||
use rss;
|
use rss;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ use std::io;
|
|||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
DieselResultError(result::Error);
|
DieselResultError(result::Error);
|
||||||
|
DieselMigrationError(RunMigrationsError);
|
||||||
RSSError(rss::Error);
|
RSSError(rss::Error);
|
||||||
ReqError(reqwest::Error);
|
ReqError(reqwest::Error);
|
||||||
IoError(io::Error);
|
IoError(io::Error);
|
||||||
|
|||||||
@ -125,6 +125,7 @@ mod tests {
|
|||||||
use rss;
|
use rss;
|
||||||
use self::rand::Rng;
|
use self::rand::Rng;
|
||||||
use models::NewSource;
|
use models::NewSource;
|
||||||
|
use utils::run_migration_on;
|
||||||
|
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -146,7 +147,7 @@ mod tests {
|
|||||||
.join(format!("hammonddb_{}.db", rng.gen::<usize>()));
|
.join(format!("hammonddb_{}.db", rng.gen::<usize>()));
|
||||||
|
|
||||||
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap();
|
||||||
::run_migration_on(&db).unwrap();
|
run_migration_on(&db).unwrap();
|
||||||
|
|
||||||
TempDB(tmp_dir, db_path, db)
|
TempDB(tmp_dir, db_path, db)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,6 @@ pub mod errors;
|
|||||||
mod parser;
|
mod parser;
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
use diesel::migrations::RunMigrationsError;
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -38,8 +37,6 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
pub type Database = Arc<Mutex<SqliteConnection>>;
|
pub type Database = Arc<Mutex<SqliteConnection>>;
|
||||||
|
|
||||||
embed_migrations!("migrations/");
|
|
||||||
|
|
||||||
lazy_static!{
|
lazy_static!{
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
static ref HAMMOND_XDG: xdg::BaseDirectories = {
|
static ref HAMMOND_XDG: xdg::BaseDirectories = {
|
||||||
@ -66,28 +63,3 @@ lazy_static!{
|
|||||||
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
|
HAMMOND_XDG.create_data_directory("Downloads").unwrap()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() -> Result<(), RunMigrationsError> {
|
|
||||||
let conn = establish_connection();
|
|
||||||
run_migration_on(&conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_migration_on(connection: &SqliteConnection) -> Result<(), RunMigrationsError> {
|
|
||||||
info!("Running DB Migrations...");
|
|
||||||
embedded_migrations::run(connection)
|
|
||||||
// embedded_migrations::run_with_output(connection, &mut std::io::stdout())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn establish_connection() -> SqliteConnection {
|
|
||||||
let database_url = DB_PATH.to_str().unwrap();
|
|
||||||
SqliteConnection::establish(database_url)
|
|
||||||
.expect(&format!("Error connecting to {}", database_url))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,15 +1,38 @@
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use dbqueries;
|
use dbqueries;
|
||||||
use Database;
|
use Database;
|
||||||
use models::Episode;
|
use models::Episode;
|
||||||
use chrono::prelude::*;
|
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use DB_PATH;
|
||||||
|
|
||||||
|
embed_migrations!("migrations/");
|
||||||
|
|
||||||
|
pub fn init() -> Result<()> {
|
||||||
|
let conn = establish_connection();
|
||||||
|
run_migration_on(&conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
||||||
|
info!("Running DB Migrations...");
|
||||||
|
embedded_migrations::run(connection)?;
|
||||||
|
// embedded_migrations::run_with_output(connection, &mut std::io::stdout())
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn establish_connection() -> SqliteConnection {
|
||||||
|
let database_url = DB_PATH.to_str().unwrap();
|
||||||
|
SqliteConnection::establish(database_url)
|
||||||
|
.expect(&format!("Error connecting to {}", database_url))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Write unit test.
|
// TODO: Write unit test.
|
||||||
fn download_checker(db: &Database) -> Result<()> {
|
fn download_checker(db: &Database) -> Result<()> {
|
||||||
let episodes = {
|
let episodes = {
|
||||||
|
|||||||
@ -56,7 +56,7 @@ THIS IS STILL A PROTOTYPE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
fn build_ui(app: >k::Application) {
|
fn build_ui(app: >k::Application) {
|
||||||
let db = Arc::new(Mutex::new(hammond_data::establish_connection()));
|
let db = Arc::new(Mutex::new(hammond_data::utils::establish_connection()));
|
||||||
|
|
||||||
let menu = gio::Menu::new();
|
let menu = gio::Menu::new();
|
||||||
menu.append("Quit", "app.quit");
|
menu.append("Quit", "app.quit");
|
||||||
@ -109,7 +109,7 @@ fn main() {
|
|||||||
// TODO: make the the logger a cli -vv option
|
// TODO: make the the logger a cli -vv option
|
||||||
loggerv::init_with_level(LogLevel::Info).unwrap();
|
loggerv::init_with_level(LogLevel::Info).unwrap();
|
||||||
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
static_resource::init().expect("Something went wrong with the resource file initialization.");
|
||||||
hammond_data::init().expect("Hammond Initialazation failed.");
|
hammond_data::utils::init().expect("Hammond Initialazation failed.");
|
||||||
|
|
||||||
let application = gtk::Application::new("org.gnome.Hammond", gio::ApplicationFlags::empty())
|
let application = gtk::Application::new("org.gnome.Hammond", gio::ApplicationFlags::empty())
|
||||||
.expect("Initialization failed...");
|
.expect("Initialization failed...");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user