Add database migrations + README

- migrations/001_initial.sql: full schema with 12 tables, triggers, indexes
- migrate.py: idempotent migration runner with version tracking
- README.md: deploy instructions, architecture overview
- .gitignore: exclude migration tracking data
This commit is contained in:
Jetour BI
2026-06-18 20:43:33 +00:00
parent 8f206aa4f1
commit 9ff9ec27e9
4 changed files with 409 additions and 0 deletions

78
README.md Normal file
View File

@@ -0,0 +1,78 @@
# Jetour BI Dashboard
Dark-themed sales & CRM pipeline dashboard for Jetour Mauritius, powered by CMS BI data.
## Quick Deploy
```bash
# 1. Clone
git clone https://gitea.iseva.net.za/jjsm01/jetour-bi.git
cd jetour-bi
# 2. Create database
createdb jetour-bi
# 3. Run migrations
pip install psycopg bcrypt
DATABASE_URL="postgresql://postgres:***@localhost:5432/jetour-bi" python migrate.py
# 4. Start dashboard
pip install fastapi uvicorn
uvicorn app:app --host 0.0.0.0 --port 8765
# 5. Open http://localhost:8765
# Default login: admin / admin
```
## Architecture
```
Browser → FastAPI (:8765) → PostgreSQL (jetour-bi)
n8n workflows (02:00-02:50) ───┘ (populate BI data from CMS)
n8n report triggers (07:00) ───┘ (daily/weekly/monthly emails)
```
## Database
| Table | Purpose |
|-------|---------|
| `prospects` | CMS BI prospect records |
| `prospect_otps` | Vehicle orders (model, color, amount, stock) |
| `status_logs` | Status change history |
| `change_log` | Field-level audit trail (auto-triggered) |
| `appointments` | Delivery/test-drive appointments |
| `report_recipients` | Email report recipients per type |
| `app_settings` | SMTP config, app preferences |
| `dashboard_users` | Auth users |
### Migrations
```bash
# Apply all pending migrations (idempotent)
DATABASE_URL="postgresql://user:***@host:5432/dbname" python migrate.py
# Or pass URL directly
python migrate.py postgresql://user:***@host:5432/jetour-bi
```
Migrations are tracked in the `_migrations` table. Safe to run repeatedly.
## Dashboard Pages
| URL | Description |
|-----|-------------|
| `/` | Main dashboard (pipeline, velocity, models, vehicle orders) |
| `/settings.html` | Email report settings (recipients + SMTP config) |
## n8n Integration
5 workflows manage the data pipeline. n8n just calls dashboard endpoints:
| Workflow | Schedule | Endpoint |
|----------|----------|----------|
| Daily Report | 07:00 SAST | `POST /api/send-report/daily` |
| Weekly Report | Mon 07:00 | `POST /api/send-report/weekly` |
| Monthly Report | 1st 07:00 | `POST /api/send-report/monthly` |
Dashboard handles all SMTP send + recipient resolution.