diff --git a/README.md b/README.md index 1e2856b..d650008 100644 --- a/README.md +++ b/README.md @@ -15,68 +15,61 @@ cp .env.example .env docker compose up -d --build ``` -## Deployment +## Deploy on Tizona (NAS) -### Prerequisites - -- Docker 24+ (or any modern version with compose v2) -- Docker Compose plugin installed (`docker compose` command works) -- ~500MB disk space for data volumes -- Outbound HTTPS access to `api.telegram.org` and `willhaben.at` - -### Step-by-step Setup - -1. Clone the repository and copy environment file: -```bash -git clone && cd willhaben-tracker -cp .env.example .env -``` - -2. Edit `.env` — at minimum set these values: -- `TELEGRAM_BOT_TOKEN` — get from @BotFather on Telegram -- `POSTGRES_PASSWORD` — any secure password - -3. Start all services: -```bash -docker compose up -d --build -``` - -4. Verify health: -```bash -# All containers should show "Up" and the db container "healthy" -docker compose ps - -# Worker logs should show "Bot started with long polling" -docker compose logs worker | grep "started" -``` - -5. Test the bot: send `/start` to your bot on Telegram, then `/add ` to create a search. - -### Updating the Stack +Copy-paste these commands from your local machine: ```bash -git pull && docker compose up -d --build +# 1. Clone repo on tizona (run as root via SSH) +ssh tizona "mkdir -p /mnt/user/appdata && rm -rf /mnt/user/appdata/willhaben-tracker" +ssh tizona "git clone https://git.lago.dev/Lago/willhaben-tracker.git /mnt/user/appdata/willhaben-tracker" + +# 2. Copy .env (must exist locally) +scp .env tizona:/mnt/user/appdata/willhaben-tracker/.env + +# 3. Start stack on tizona +ssh tizona "cd /mnt/user/appdata/willhaben-tracker && docker compose up -d --build" + +# 4. Verify everything is running +ssh tizona "cd /mnt/user/appdata/willhaben-tracker && docker compose ps" ``` -New database migrations are applied automatically when the Postgres container restarts with new migration files in `supabase/migrations/`. - -### Backing Up Data +### Update (pull + rebuild) ```bash -# Full database dump -docker compose exec db pg_dump -U postgres postgres > backup_$(date +%F).sql - -# Restore from backup -psql -h localhost -p 55632 -U postgres -d postgres < backup_2024-01-01.sql +ssh tizona "cd /mnt/user/appdata/willhaben-tracker && \ + git pull origin main && \ + docker compose build worker --no-cache && \ + docker compose up -d" ``` -### Troubleshooting Common Issues +### Full reset (wipe data, keep schema) -| Problem | Solution | -|---------|----------| -| Postgres auth error on first boot | Volume may contain stale `pg_hba.conf`. Delete `data/db` and restart. | -| Studio shows "unhealthy" but APIs work | Cosmetic health check issue — ignore unless you can't browse tables. | -| Bot doesn't respond | Check `docker compose logs worker` for errors. Verify token in `.env`. | +```bash +ssh tizona "cd /mnt/user/appdata/willhaben-tracker && \ + docker compose down && \ + rm -rf data/db && mkdir -p data/db && \ + docker compose up -d --build" +``` + +### Backup & Restore + +```bash +# Dump database +ssh tizona "docker compose exec db pg_dump -U postgres postgres" > backup_$(date +%F).sql + +# Restore +cat backup_2024-01-01.sql | ssh tizona "cd /mnt/user/appdata/willhaben-tracker && docker compose exec -T db psql -U postgres postgres" +``` + +### Troubleshooting + +| Problem | Fix | +|---------|-----| +| `role "supabase_admin" does not exist` in Studio | Full reset (wipes data, re-runs init scripts) | +| Migrations didn't run on new tables | `data/db/` had stale data — delete it and restart | +| Worker crashes with `UndefinedTableError` | Docker image was built before migration commit — force rebuild: `docker compose build worker --no-cache && docker compose up -d` | +| Studio shows "unhealthy" but APIs work | Cosmetic health check issue — ignore unless you can't browse tables | ## Configuration @@ -89,8 +82,7 @@ Edit `.env` before first startup. All values are read by the worker and database | `POSTGRES_PASSWORD` | PostgreSQL password | (required) | | `POSTGRES_DB` | Database name | `postgres` | | `JWT_SECRET` | PostgREST JWT signing key | auto-generated default | -| `DEFAULT_INTERVAL_MINUTES`| Default scrape interval per search query | `60` | -| `ADMIN_TELEGRAM_IDS` | Comma-separated Telegram IDs with admin privileges | (none) | +| `DEFAULT_INTERVAL_MINUTES`| Default scrape interval per keyword | `5` | ## Architecture @@ -107,16 +99,17 @@ Edit `.env` before first startup. All values are read by the worker and database All users must be whitelisted before use. Run `/start` to activate your account. -| Command | Access | Description | -|--------------------|-------------|--------------------------------------------------| -| `/start` | Anyone | Activate account and show help message | -| `/add ` | Active user | Subscribe to keyword (shared across users) | -| `/list` | Active user | List your subscriptions with subscriber counts | -| `/delete ` | Active user | Unsubscribe from a keyword | -| `/stats` | Active user | Show queries count, ads tracked, notifications | -| `/adduser [admin]` | Admin only | Add or promote a user by Telegram ID | -| `/removeuser ` | Admin only | Remove a user from the bot | -| `/users` | Admin only | List all registered users and their roles | +| Command | Access | Description | +|------------------------------------|-------------|--------------------------------------------------| +| `/start` | Anyone | Activate account and show help message | +| `/add ` | Active user | Subscribe to keyword (shared across users) | +| `/list` | Active user | List your subscriptions with subscriber counts | +| `/delete ` | Active user | Unsubscribe from a keyword | +| `/interval ` | Active user | Change scrape interval (1-1440 min) | +| `/stats` | Active user | Show keywords, ads tracked, notifications | +| `/adduser [admin]` | Admin only | Add or promote a user by Telegram ID | +| `/removeuser ` | Admin only | Remove a user from the bot | +| `/users` | Admin only | List all registered users and their roles | ## Default Admin