Skip to content

Commit

Permalink
Updated diesel dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Oct 7, 2018
1 parent 4048ff8 commit fea0b4e
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 118 deletions.
153 changes: 51 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ ui = []
[dependencies]
ape = "0.2.0"
app_dirs = "1.1.1"
diesel = { version = "0.99.0", features = ["sqlite"] }
diesel_infer_schema = { version = "0.99.0", features = ["sqlite"] }
diesel_migrations = { version = "0.99.0", features = ["sqlite"] }
diesel = { version = "1.3.3", features = ["sqlite"] }
diesel_migrations = { version = "1.3.0", features = ["sqlite"] }
error-chain = "0.12.0"
getopts = "0.2.15"
hyper = "0.11.2"
hyper = "0.12.11"
id3 = "0.2.3"
image = "0.20.0"
iron = "0.5.1"
rustfm-scrobble = "0.9.1"
lewton = "0.9.1"
log = "0.3.8"
log = "0.4.5"
md5 = "0.4.0"
metaflac = "0.1.8"
mount = "0.3.0"
Expand Down
2 changes: 2 additions & 0 deletions diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[print_schema]
file = "src/db/schema.rs"
Empty file added migrations/.gitkeep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mod schema;
pub use self::schema::*;

#[allow(dead_code)]
const DB_MIGRATIONS_PATH: &str = "src/db/migrations";
embed_migrations!("src/db/migrations");
const DB_MIGRATIONS_PATH: &str = "migrations";
embed_migrations!("migrations");

pub trait ConnectionSource {
fn get_connection(&self) -> MutexGuard<SqliteConnection>;
Expand Down
100 changes: 99 additions & 1 deletion src/db/schema.rs
Original file line number Diff line number Diff line change
@@ -1 +1,99 @@
infer_schema!("src/db/schema.sqlite");
table! {
ddns_config (id) {
id -> Integer,
host -> Text,
username -> Text,
password -> Text,
}
}

table! {
directories (id) {
id -> Integer,
path -> Text,
parent -> Nullable<Text>,
artist -> Nullable<Text>,
year -> Nullable<Integer>,
album -> Nullable<Text>,
artwork -> Nullable<Text>,
date_added -> Integer,
}
}

table! {
misc_settings (id) {
id -> Integer,
auth_secret -> Text,
index_sleep_duration_seconds -> Integer,
index_album_art_pattern -> Text,
prefix_url -> Text,
}
}

table! {
mount_points (id) {
id -> Integer,
source -> Text,
name -> Text,
}
}

table! {
playlist_songs (id) {
id -> Integer,
playlist -> Integer,
path -> Text,
ordering -> Integer,
}
}

table! {
playlists (id) {
id -> Integer,
owner -> Integer,
name -> Text,
}
}

table! {
songs (id) {
id -> Integer,
path -> Text,
parent -> Text,
track_number -> Nullable<Integer>,
disc_number -> Nullable<Integer>,
title -> Nullable<Text>,
artist -> Nullable<Text>,
album_artist -> Nullable<Text>,
year -> Nullable<Integer>,
album -> Nullable<Text>,
artwork -> Nullable<Text>,
duration -> Nullable<Integer>,
}
}

table! {
users (id) {
id -> Integer,
name -> Text,
password_salt -> Binary,
password_hash -> Binary,
admin -> Integer,
lastfm_username -> Nullable<Text>,
lastfm_session_key -> Nullable<Text>,
}
}

joinable!(playlist_songs -> playlists (playlist));
joinable!(playlists -> users (owner));

allow_tables_to_appear_in_same_query!(
ddns_config,
directories,
misc_settings,
mount_points,
playlist_songs,
playlists,
songs,
users,
);
Binary file removed src/db/schema.sqlite
Binary file not shown.
8 changes: 4 additions & 4 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use diesel;
use diesel::dsl::sql;
use diesel::prelude::*;
use diesel::sqlite::SqliteConnection;
use diesel::types;
use diesel::sql_types;
use regex::Regex;
use std::fs;
use std::path::Path;
Expand All @@ -28,7 +28,7 @@ const INDEX_BUILDING_CLEAN_BUFFER_SIZE: usize = 500; // Insertions in each trans

no_arg_sql_function!(
random,
types::Integer,
sql_types::Integer,
"Represents the SQL RANDOM() function"
);

Expand Down Expand Up @@ -512,7 +512,7 @@ where

let real_directories: Vec<Directory> = directories::table
.filter(directories::parent.eq(&real_path_string))
.order(sql::<types::Bool>("path COLLATE NOCASE ASC"))
.order(sql::<sql_types::Bool>("path COLLATE NOCASE ASC"))
.load(connection.deref())?;
let virtual_directories = real_directories
.into_iter()
Expand All @@ -521,7 +521,7 @@ where

let real_songs: Vec<Song> = songs::table
.filter(songs::parent.eq(&real_path_string))
.order(sql::<types::Bool>("path COLLATE NOCASE ASC"))
.order(sql::<sql_types::Bool>("path COLLATE NOCASE ASC"))
.load(connection.deref())?;
let virtual_songs = real_songs
.into_iter()
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ extern crate crypto;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_infer_schema;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate error_chain;
Expand Down
4 changes: 2 additions & 2 deletions src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::clone::Clone;
use core::ops::Deref;
use diesel;
use diesel::prelude::*;
use diesel::types::*;
use diesel::sql_types;
use diesel::BelongingToDsl;
use std::path::Path;

Expand Down Expand Up @@ -188,7 +188,7 @@ where
WHERE ps.playlist = ?
ORDER BY ps.ordering
"#);
let query = query.clone().bind::<Integer, _>(playlist.id);
let query = query.clone().bind::<sql_types::Integer, _>(playlist.id);
songs = query.get_results(connection.deref())?;
}

Expand Down
6 changes: 6 additions & 0 deletions update_db_schema.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cargo install diesel_cli --no-default-features --features "sqlite-bundled"

mkdir tmp
diesel --database-url tmp/print-schema.sqlite setup
diesel --database-url tmp/print-schema.sqlite migration run
rmdir /q /s tmp

0 comments on commit fea0b4e

Please sign in to comment.