Files
tipibot/docs/POCKETBASE_SETUP.md
Rene Arumetsa c40c871a4b Sync pb
2026-07-26 21:29:35 +03:00

91 lines
2.7 KiB
Markdown

# PocketBase Setup
## 1. Download & run PocketBase
Download the binary for your OS from https://pocketbase.io/docs/ and run it:
```bash
./pocketbase serve
# Admin UI: http://127.0.0.1:8090/_/
```
Create your admin account on first launch via the Admin UI.
---
## 2. Create economy collections for both bot profiles
In the Admin UI → **Collections****New collection** and create:
- `economy_users_dev`
- `economy_users_prod`
Use the same schema for both collections.
Add the following fields:
| Field name | Type | Required | Default |
|-------------------|-----------|----------|---------|
| `user_id` | Text | ✅ | - |
| `balance` | Number | | `0` |
| `exp` | Number | | `0` |
| `daily_streak` | Number | | `0` |
| `last_daily` | Text | | - |
| `last_work` | Text | | - |
| `last_beg` | Text | | - |
| `last_crime` | Text | | - |
| `last_rob` | Text | | - |
| `last_streak_date`| Text | | - |
| `jailed_until` | Text | | - |
| `items` | JSON | | `[]` |
| `item_uses` | JSON | | `{}` |
| `reminders` | JSON | | `[]` |
| `eco_banned` | Bool | | `false` |
> **Tip:** Set `user_id` as a unique index under **Indexes** tab.
The table above is only the base schema. After creating the collections, run:
```bash
python scripts/sync_pb_schema.py
```
It derives the complete field list from the bot's user model and adds whatever
is missing to **both** collections (stats, fishing, prestige, quests, ...).
Re-run it after every update - PocketBase silently drops writes to fields that
are not in the collection schema, which breaks features without any error.
Set **API rules** (all four: list, view, create, update) to admin-only (leave blank / locked).
---
## 3. Configure .env
Add to your `.env`:
```
PB_URL=http://127.0.0.1:8090
PB_ADMIN_EMAIL=your-admin@email.com
PB_ADMIN_PASSWORD=your-admin-password
PB_ECONOMY_COLLECTION_DEV=economy_users_dev
PB_ECONOMY_COLLECTION_ECONOMY=economy_users_prod
```
---
## 4. Migrate existing data (one-time)
If you have existing data in `data/economy.json`, run the migration script **once** before starting the bot:
```bash
python migrate_to_pb.py
```
---
## 5. Production
On a server, run PocketBase as a background service (systemd, Docker, etc.) and update `PB_URL` in `.env` to the server's address.
PocketBase stores all data in `pb_data/` - back this directory up regularly.