commit 42af7c6dab113388a0db4fae0c196bae14761bc1
parent 1eb1502a07e96197c803cc5d7c9c7384d8fc46b5
Author: Emil Madsen <sovende@gmail.com>
Date: Mon, 20 May 2019 19:53:14 +0200
MySQL database
Diffstat:
3 files changed, 5 insertions(+), 22 deletions(-)
diff --git a/src/config.rs b/src/config.rs
@@ -201,7 +201,7 @@ make_config! {
data_folder: String, false, def, "data".to_string();
/// Database URL
- database_url: String, false, auto, |c| format!("{}/{}", c.data_folder, "db.sqlite3");
+ database_url: String, false, auto, |c| format!("mysql://root:my-secret-pw@localhost:3306/");
/// Icon chache folder
icon_cache_folder: String, false, auto, |c| format!("{}/{}", c.data_folder, "icon_cache");
/// Attachments folder
diff --git a/src/db/mod.rs b/src/db/mod.rs
@@ -2,7 +2,7 @@ use std::ops::Deref;
use diesel::r2d2;
use diesel::r2d2::ConnectionManager;
-use diesel::sqlite::SqliteConnection;
+use diesel::sqlite::MysqlConnection;
use diesel::{Connection as DieselConnection, ConnectionError};
use rocket::http::Status;
@@ -12,9 +12,9 @@ use rocket::{Outcome, Request, State};
use crate::CONFIG;
/// An alias to the database connection used
-type Connection = SqliteConnection;
+type Connection = MysqlConnection;
-/// An alias to the type for a pool of Diesel SQLite connections.
+/// An alias to the type for a pool of Diesel MySQL connections.
type Pool = r2d2::Pool<ConnectionManager<Connection>>;
/// Connection request guard type: a wrapper around an r2d2 pooled connection.
diff --git a/src/main.rs b/src/main.rs
@@ -123,24 +123,7 @@ fn chain_syslog(logger: fern::Dispatch) -> fern::Dispatch {
fn check_db() {
let url = CONFIG.database_url();
- let path = Path::new(&url);
-
- if let Some(parent) = path.parent() {
- use std::fs;
- if fs::create_dir_all(parent).is_err() {
- error!("Error creating database directory");
- exit(1);
- }
- }
-
- // Turn on WAL in SQLite
- if CONFIG.enable_db_wal() {
- use diesel::RunQueryDsl;
- let connection = db::get_connection().expect("Can't conect to DB");
- diesel::sql_query("PRAGMA journal_mode=wal")
- .execute(&connection)
- .expect("Failed to turn on WAL");
- }
+ println!(url.to_string());
}
fn check_rsa_keys() {