chore: added db path env
0f49bc3a
3 file(s) · +9 −2
| 61 | 61 | |---|---| |
|
| 62 | 62 | | `SIPP_API_KEY` | API key for protecting endpoints | |
|
| 63 | 63 | | `SIPP_AUTH_ENDPOINTS` | Comma-separated list of endpoints requiring auth: `api_list`, `api_create`, `api_get`, `api_delete`, `all`, or `none` (defaults to `api_delete,api_list`) | |
|
| 64 | + | | `SIPP_DB_PATH` | Custom path for the SQLite database file (defaults to `sipp.sqlite` in the working directory) | |
|
| 64 | 65 | ||
| 65 | 66 | The server stores snippets in a local `sipp.sqlite` SQLite database. |
|
| 66 | 67 | ||
| 173 | 174 | ||
| 174 | 175 | 1. Connect your repository to [Railway](https://railway.app) |
|
| 175 | 176 | 2. Set the environment variables `SIPP_API_KEY` and optionally `SIPP_AUTH_ENDPOINTS` |
|
| 177 | + | 3. Add a [volume](https://docs.railway.com/guides/volumes) to your service and mount it at `/data` |
|
| 178 | + | 4. Set `SIPP_DB_PATH` to `/data/sipp.sqlite` so the database persists across deploys |
|
| 46 | 46 | .collect() |
|
| 47 | 47 | } |
|
| 48 | 48 | ||
| 49 | + | pub fn db_path() -> String { |
|
| 50 | + | std::env::var("SIPP_DB_PATH").unwrap_or_else(|_| "sipp.sqlite".to_string()) |
|
| 51 | + | } |
|
| 52 | + | ||
| 49 | 53 | pub fn init_db() -> Result<Db, DbError> { |
|
| 50 | - | let conn = Connection::open("sipp.sqlite")?; |
|
| 54 | + | let conn = Connection::open(db_path())?; |
|
| 51 | 55 | conn.execute( |
|
| 52 | 56 | "CREATE TABLE IF NOT EXISTS snippets ( |
|
| 53 | 57 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 427 | 427 | )); |
|
| 428 | 428 | } |
|
| 429 | 429 | ||
| 430 | - | if !std::path::Path::new("sipp.sqlite").exists() { |
|
| 430 | + | if !std::path::Path::new(&crate::db::db_path()).exists() { |
|
| 431 | 431 | let cfg = config::load_config(); |
|
| 432 | 432 | let url = cfg.remote_url.unwrap_or_else(|| "http://localhost:3000".to_string()); |
|
| 433 | 433 | let api_key = api_key.or(cfg.api_key); |