Testing things and being helpless about db migration stuff *shrug*
This commit is contained in:
parent
7cb3d0ceae
commit
6f1192a73c
4 changed files with 20 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
[config]
|
||||
database_path = "src/storage/db.sqlite"
|
||||
max_workers = 100
|
||||
min_workers = 0
|
||||
min_workers = 200
|
|
@ -54,8 +54,8 @@ pub struct CLIArguments {
|
|||
/// Path to the config file
|
||||
#[arg(default_value = "config.toml")]
|
||||
config: PathBuf,
|
||||
/// Maximum amount of workers to use
|
||||
/// If not set, the max is calculated depending on system resources
|
||||
/// Maximum amount of workers to use.
|
||||
/// If not set, the max is calculated depending on system resources.
|
||||
/// A value of 0 will cause the server to be singlethreaded, potentially reducing the performance and responsiveness by a lot
|
||||
#[arg(long)]
|
||||
max_workers: Option<u32>,
|
||||
|
@ -90,7 +90,9 @@ pub fn read_from_env() -> Result<Config, Error> {
|
|||
Ok(d) => d,
|
||||
Err(err) => bail!("Failed to parse config file. Error: {err}"),
|
||||
};
|
||||
Ok(unsanitized.into_config(&args))
|
||||
let conf = unsanitized.into_config(&args);
|
||||
conf.sanity_check()?;
|
||||
Ok(conf)
|
||||
}
|
||||
|
||||
fn calc_max_workers_from_system() -> u32 {
|
||||
|
@ -161,3 +163,12 @@ impl ConfigRootToml {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn sanity_check(&self) -> Result<(), Error> {
|
||||
if self.min_workers > self.max_workers {
|
||||
bail!("Minimum amount of workers ({}) can't be greater than maximum amount of workers ({})", self.min_workers, self.max_workers)
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -17,5 +17,5 @@ mod webui;
|
|||
|
||||
|
||||
fn main() {
|
||||
println!("{:?}", config::read_from_env());
|
||||
storage::establish_connection("./src/storage/db.sqlite");
|
||||
}
|
|
@ -8,24 +8,21 @@
|
|||
// See the Licence for the specific language governing permissions and limitations under the Licence.
|
||||
//
|
||||
|
||||
use diesel::{prelude::*, sqlite::Sqlite};
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::{prelude::*, pg::PgConnection, sqlite::Sqlite};
|
||||
use diesel_migrations::{EmbeddedMigrations, embed_migrations, MigrationHarness};
|
||||
use dotenvy::dotenv;
|
||||
use std::{env, error::Error};
|
||||
use std::error::Error;
|
||||
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
||||
|
||||
pub fn establish_connection(db_url: &str) -> PgConnection {
|
||||
dotenv().ok();
|
||||
//SqliteConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e))
|
||||
let conn = PgConnection::establish(db_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||
.unwrap_or_else(|e| panic!("Error connecting to {}: {}", db_url, e));
|
||||
// TODO: Add migrations here
|
||||
conn
|
||||
}
|
||||
|
||||
|
||||
fn run_migrations_sqlite(connection: &mut impl MigrationHarness<Sqlite>) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
|
||||
// This will run the necessary migrations.
|
||||
|
|
Loading…
Reference in a new issue