Convert JSON storage to SQLite #3
+1
-1
@@ -9,7 +9,7 @@ PORT=3003
|
||||
# FIREBASE_SERVICE_ACCOUNT_JSON={"type":"service_account",...}
|
||||
|
||||
# Directory for the SQLite FCM registration database (default: ./data).
|
||||
# Creates fcm-tokens.sqlite (plus -wal/-shm while the process is running).
|
||||
# Creates notify.sqlite (plus -wal/-shm while the process is running).
|
||||
# FCM_TOKEN_DATA_DIR=./data
|
||||
|
||||
# Set to "test-local" to bypass ethr JWT expiry verification in local dev only.
|
||||
|
||||
@@ -22,7 +22,7 @@ pnpm run dev
|
||||
|
||||
The server starts on `http://localhost:3003` (or the port in `PORT`). Hot-reloads on file changes.
|
||||
|
||||
On first use, the service creates `FCM_TOKEN_DATA_DIR` (default `./data`) and the SQLite file `fcm-tokens.sqlite` with the required schema.
|
||||
On first use, the service creates `FCM_TOKEN_DATA_DIR` (default `./data`) and the SQLite file `notify.sqlite` with the required schema.
|
||||
|
||||
### Authentication
|
||||
|
||||
@@ -38,9 +38,9 @@ Set `NODE_ENV=test-local` in `.env` to bypass ethr JWT *expiry* verification dur
|
||||
|
||||
| Path | Description |
|
||||
|---|---|
|
||||
| `{FCM_TOKEN_DATA_DIR}/fcm-tokens.sqlite` | Primary SQLite database (default dir: `./data`) |
|
||||
| `{FCM_TOKEN_DATA_DIR}/fcm-tokens.sqlite-wal` | WAL journal (present while the process is running) |
|
||||
| `{FCM_TOKEN_DATA_DIR}/fcm-tokens.sqlite-shm` | Shared-memory file used with WAL mode |
|
||||
| `{FCM_TOKEN_DATA_DIR}/notify.sqlite` | Primary SQLite database (default dir: `./data`) |
|
||||
| `{FCM_TOKEN_DATA_DIR}/notify.sqlite-wal` | WAL journal (present while the process is running) |
|
||||
| `{FCM_TOKEN_DATA_DIR}/notify.sqlite-shm` | Shared-memory file used with WAL mode |
|
||||
|
||||
`FCM_TOKEN_DATA_DIR` defaults to `./data` (relative to the process working directory). The `data/` directory is gitignored.
|
||||
|
||||
@@ -64,8 +64,8 @@ There is **no automatic migration** from the old JSON file (`fcm-tokens.json`).
|
||||
|
||||
Persist or back up the SQLite files under `FCM_TOKEN_DATA_DIR`:
|
||||
|
||||
1. Prefer stopping the service, then copy `fcm-tokens.sqlite` (and any `-wal` / `-shm` sidecars if present).
|
||||
2. Or, while the service is running, copy **all three** files (`fcm-tokens.sqlite`, `-wal`, `-shm`) together so the backup stays consistent under WAL mode.
|
||||
1. Prefer stopping the service, then copy `notify.sqlite` (and any `-wal` / `-shm` sidecars if present).
|
||||
2. Or, while the service is running, copy **all three** files (`notify.sqlite`, `-wal`, `-shm`) together so the backup stays consistent under WAL mode.
|
||||
3. For Docker, mount a volume at the data directory (or set `FCM_TOKEN_DATA_DIR` to a mounted path) so registrations survive container recreation.
|
||||
|
||||
## Production
|
||||
@@ -97,4 +97,4 @@ Required environment variables:
|
||||
| `FIREBASE_SERVICE_ACCOUNT_JSON` | Inline service account JSON (one line). If unset, falls back to Application Default Credentials. |
|
||||
| `PORT` | HTTP port (default: `3003`). |
|
||||
| `ENDORSER_URL` | Endorser API base URL used for auth checks on register/refresh (default: `https://api.endorser.ch`). |
|
||||
| `FCM_TOKEN_DATA_DIR` | Directory for the SQLite database file `fcm-tokens.sqlite` (default: `./data`). |
|
||||
| `FCM_TOKEN_DATA_DIR` | Directory for the SQLite database file `notify.sqlite` (default: `./data`). |
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import Database from "better-sqlite3";
|
||||
|
||||
const dataDir =
|
||||
process.env.FCM_TOKEN_DATA_DIR ?? path.join(process.cwd(), "data");
|
||||
const dbFile = path.join(dataDir, "fcm-tokens.sqlite");
|
||||
const dbFile = path.join(dataDir, "notify.sqlite");
|
||||
|
|
||||
|
||||
const SCHEMA_SQL = `
|
||||
CREATE TABLE IF NOT EXISTS fcm_registrations (
|
||||
|
||||
Reference in New Issue
Block a user
Let's make this DB a generic name for all wakeup notification purposes, eg. "notify.sqlite"
I renamed the database file accordingly.
I asked AI about also changing the name to FCM_TOKEN_DATA_DIR (as a what-if), and it brought up good points for and against. I'm curious what your thoughts are on it?
I'm not clear on that... it sounds like you are saying that it would be "FCM_TOKEN_DATA_DIR.sqlite", but it seems odd to put a "_DIR" name on the file.
Maybe you mean to have another environment variable like FCM_TOKEN_DATA_FILENAME, so the full change would be something like this:
That seems reasonable, but my feeling is that it adds some complexity (eg. if people name it something else then the file is harder to find) and it doesn't seem like the benefit of flexibility is worth it.
Or maybe you meant something else.
Ahh sorry, I bungled the wording on that last reply. I meant "…changing the name of FCM_TOKEN_DATA_DIR" (the name of the environment variable that specifies the directory where notify.sqlite resides).