diff --git a/src/main.rs b/src/main.rs index 5e0b292..c6e0bb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,9 +26,28 @@ mod forward; mod sniff; mod templates; -type DbPool = r2d2::Pool>; +// default to postgres +#[cfg(feature = "default")] +type DbConn = PgConnection; +#[cfg(feature = "default")] +embed_migrations!("migrations/postgres"); -embed_migrations!(); +#[cfg(feature = "postgres")] +type DbConn = PgConnection; +#[cfg(feature = "postgres")] +embed_migrations!("migrations/postgres"); + +#[cfg(feature = "sqlite")] +type DbConn = SqliteConnection; +#[cfg(feature = "sqlite")] +embed_migrations!("migrations/sqlite"); + +#[cfg(feature = "mysql")] +type DbConn = MysqlConnection; +#[cfg(feature = "mysql")] +embed_migrations!("migrations/mysql"); + +type DbPool = r2d2::Pool>; #[actix_rt::main] async fn main() -> std::io::Result<()> { @@ -40,8 +59,11 @@ async fn main() -> std::io::Result<()> { println!("Checking configuration file..."); CONFIG.check_version(); + if CONFIG.database_path.len() == 0 { + println!("No database specified. Please enter a MySQL, PostgreSQL or SQLite connection string in config.toml."); + } println!("Opening database {}", CONFIG.database_path); - let manager = ConnectionManager::::new(&CONFIG.database_path); + let manager = ConnectionManager::::new(&CONFIG.database_path); let pool = r2d2::Pool::builder() .build(manager) .expect("ERROR: main: Failed to create the database pool.");