Re-add database flag
All checks were successful
Fly Deploy / Deploy app (push) Successful in 2m7s

This commit is contained in:
Gabriel Simmer 2023-10-01 02:46:12 +01:00
parent b40c7a0262
commit 8a52d12891
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
2 changed files with 6 additions and 3 deletions

View file

@ -32,7 +32,7 @@ proxy:
# the last command to be long-running (e.g. an application server). When the # the last command to be long-running (e.g. an application server). When the
# last command exits, LiteFS is shut down. # last command exits, LiteFS is shut down.
exec: exec:
- cmd: "DATABASE_PATH=/litefs/db /app/gabrielsimmerdotcom --bind 0.0.0.0:8081" - cmd: "/app/gabrielsimmerdotcom --bind 0.0.0.0:8081 --database-path=/litefs/db"
# The lease section specifies how the cluster will be managed. We're using the # The lease section specifies how the cluster will be managed. We're using the
# "consul" lease type so that our application can dynamically change the primary. # "consul" lease type so that our application can dynamically change the primary.

View file

@ -32,6 +32,8 @@ use crate::cache::{Cache, init_cache};
#[derive(Parser)] #[derive(Parser)]
struct Cli { struct Cli {
#[arg(short, long, default_value_t=("gs.db").to_string())]
database_path: String,
#[arg(short, long, default_value_t=("0.0.0.0:3000").to_string())] #[arg(short, long, default_value_t=("0.0.0.0:3000").to_string())]
bind: String, bind: String,
} }
@ -78,14 +80,15 @@ impl Render for Project {
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), sqlx::Error> { async fn main() -> Result<(), sqlx::Error> {
let args = Cli::parse(); let args = Cli::parse();
let path = env::var("DATABASE_PATH").unwrap_or("gs.db".to_owned());
let opts = SqliteConnectOptions::from_str(&path)? let opts = SqliteConnectOptions::from_str(&args.database_path)?
.journal_mode(SqliteJournalMode::Wal) .journal_mode(SqliteJournalMode::Wal)
.create_if_missing(true); .create_if_missing(true);
let pool = SqlitePoolOptions::new().connect_with(opts).await?; let pool = SqlitePoolOptions::new().connect_with(opts).await?;
sqlx::migrate!("./migrations").run(&pool).await?; sqlx::migrate!("./migrations").run(&pool).await?;
env::set_var("DATABASE_PATH", &args.database_path);
let state = AppState { cache: init_cache().await }; let state = AppState { cache: init_cache().await };
let app = Router::new() let app = Router::new()