Content-Length: 351256 | pFad | https://github.com/sebadob/rauthy/commit/a68c6527a68b970221f3c48982cabc418aa81d39

DE Merge pull request #5 from sebadob/target-database-startup-check · sebadob/rauthy@a68c652 · GitHub
Skip to content

Commit

Permalink
Merge pull request #5 from sebadob/target-database-startup-check
Browse files Browse the repository at this point in the history
target database check at startup
  • Loading branch information
sebadob authored Aug 1, 2023
2 parents adb3971 + 9666925 commit a68c652
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
52 changes: 29 additions & 23 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ set shell := ["bash", "-uc"]

export TAG := `cat rauthy-main/Cargo.toml | grep '^version =' | cut -d " " -f3 | xargs`

db_url_sqlite := "sqlite:data/rauthy.db"
db_url_postgres := "postgresql://rauthy:123SuperSafe@localhost:5432/rauthy"

clippy-sqlite:
clear
DATABASE_URL="sqlite:data/rauthy.db" cargo clippy --features sqlite
DATABASE_URL={{db_url_sqlite}} cargo clippy --features sqlite


clippy-postgres:
clear
DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" cargo clippy --features postgres
DATABASE_URL={{db_url_postgres}} cargo clippy --features postgres


migrate-sqlite:
DATABASE_URL="sqlite:data/rauthy.db" sqlx database create
DATABASE_URL="sqlite:data/rauthy.db" sqlx migrate run --source migrations/sqlite
DATABASE_URL={{db_url_sqlite}} sqlx database create
DATABASE_URL={{db_url_sqlite}} sqlx migrate run --source migrations/sqlite


migrate-postgres:
DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" sqlx migrate run --source migrations/postgres
DATABASE_URL={{db_url_postgres}} sqlx migrate run --source migrations/postgres


# runs the application with sqlite feature
run-sqlite:
DATABASE_URL="sqlite:data/rauthy.db" cargo run --target x86_64-unknown-linux-musl --features sqlite
DATABASE_URL={{db_url_sqlite}} cargo run --target x86_64-unknown-linux-musl --features sqlite


# runs the application with postgres feature
run-postgres:
DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" cargo run --target x86_64-unknown-linux-musl --features postgres
ATABASE_URL={{db_url_postgres}} cargo run --target x86_64-unknown-linux-musl --features postgres


# runs the UI in development mode
Expand All @@ -48,13 +50,13 @@ test-sqlite:
#!/usr/bin/env bash
clear
DATABASE_URL="sqlite:data/rauthy.db" cargo build --features sqlite
DATABASE_URL="sqlite:data/rauthy.db" cargo run --features sqlite test &
DATABASE_URL={{db_url_sqlite}} cargo build --features sqlite
DATABASE_URL={{db_url_sqlite}} cargo run --features sqlite test &
sleep 1
PID=$(echo "$!")
echo "PID: $PID"

DATABASE_URL="sqlite:data/rauthy.db" cargo test --features sqlite
DATABASE_URL={{db_url_sqlite}} cargo test --features sqlite
kill "$PID"
echo All tests successful

Expand All @@ -67,13 +69,13 @@ test-postgres:
#!/usr/bin/env bash
clear
DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" cargo build --features postgres
DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" cargo run --features postgres test &
DATABASE_URL={{db_url_postgres}} cargo build --features postgres
DATABASE_URL={{db_url_postgres}} cargo run --features postgres test &
sleep 1
PID=$(echo "$!")
echo "PID: $PID"

DATABASE_URL="postgresql://rauthy:123SuperSafe@localhost:5432/rauthy" cargo test --features postgres
DATABASE_URL={{db_url_postgres}} cargo test --features postgres
kill "$PID"
echo All tests successful

Expand Down Expand Up @@ -149,19 +151,23 @@ build-docs:
# cp target/x86_64-unknown-linux-musl/release/rauthy out/

# builds the whole application in release mode
build-sqlite: build-docs build-ui
cargo clippy -- -D warnings
cargo build --release --target x86_64-unknown-linux-musl
cp target/x86_64-unknown-linux-musl/release/rauthy out/
build-sqlite: build-docs build-ui migrate-sqlite
DATABASE_URL={{db_url_sqlite}} cargo clippy --features sqlite -- -D warnings
DATABASE_URL={{db_url_sqlite}} cargo build \
--release \
--target x86_64-unknown-linux-musl \
--features sqlite
cp target/x86_64-unknown-linux-musl/release/rauthy out/rauthy-lite


# builds the whole application in release mode
build-postgres: build-docs build-ui
export DATABASE_URL := "postgresql://rauthy:123SuperSafe@localhost:5432/rauthy"

cargo clippy -- -D warnings
cargo build --release --target x86_64-unknown-linux-musl
cp target/x86_64-unknown-linux-musl/release/rauthy out/
build-postgres: build-docs build-ui migrate-postgres
DATABASE_URL={{db_url_postgres}} cargo clippy --features postgres -- -D warnings
DATABASE_URL={{db_url_postgres}} cargo build \
--release \
--target x86_64-unknown-linux-musl \
--features postgres
cp target/x86_64-unknown-linux-musl/release/rauthy out/rauthy


# makes sure everything is fine
Expand Down
21 changes: 20 additions & 1 deletion rauthy-models/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::migration::db_migrate_dev::migrate_dev_data;
use crate::ListenScheme;
use anyhow::Context;
use argon2::Params;
use rauthy_common::constants::{DATABASE_URL, DEV_MODE, PROXY_MODE};
use rauthy_common::constants::{DATABASE_URL, DB_TYPE, DEV_MODE, PROXY_MODE};
use rauthy_common::DbType;
use regex::Regex;
use serde::{Deserialize, Serialize};
use sqlx::pool::PoolOptions;
Expand Down Expand Up @@ -246,6 +247,15 @@ impl AppState {

#[cfg(feature = "postgres")]
let pool = {
if *DB_TYPE == DbType::Sqlite {
let msg = r#"
You are trying to connect to a SQLite instance with the 'Postgres'
version of Rauthy. You need to either change to a SQLite database or use the '*-lite'
container image of Rauthy."#;
error!("{msg}");
panic!("{msg}");
}

let pool = Self::connect_postgres(&DATABASE_URL, db_max_conn).await?;
info!("Using Postgres");

Expand All @@ -257,6 +267,15 @@ impl AppState {

#[cfg(feature = "sqlite")]
let pool = {
if *DB_TYPE == DbType::Postgres {
let msg = r#"
You are trying to connect to a Postgres instance with the 'SQLite'
version of Rauthy. You need to either change to a Postgres database or use the default
Postgres container image of Rauthy."#;
error!("{msg}");
panic!("{msg}");
}

let pool = Self::connect_sqlite(&DATABASE_URL, db_max_conn, false).await?;
if DATABASE_URL.ends_with(":memory:") {
info!("Using in-memory SQLite");
Expand Down

0 comments on commit a68c652

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/a68c6527a68b970221f3c48982cabc418aa81d39

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy