feat: SQLite DB with migrations replaces all JSON file storage
- Add db.php with PDO singleton, migration runner, and all helper functions - Add migrations/001_initial_schema.sql (full schema) - Add migrations/002_import_json.php (one-time JSON → DB importer) - Add _incl/switch_tenant.php POST endpoint for tenant/centro switching - Update tools.auth.php: DB-backed login, cookie auth, session reload, init_active_centro() - Update all sysadmin pages (users, centros, aularios, invitations, reset_password) to use DB - Update aulatek/index.php, aulario.php, supercafe.php, supercafe_edit.php to use DB - Update aulatek/comedor.php and api/comedor.php to use DB - Update aulatek/paneldiario.php: aulario config + comedor data from DB - Update aulatek/proyectos.php: aulario config + sharing metadata from DB - Update club/cal.php, index.php, edit_data.php, upload/upload.php to use DB - Update account/index.php: rich profile, tenant list, aula list, session info, permissions - Update pre-body.php account dropdown: shows active org + inline tenant switcher - Update DATA_STRUCTURE.md to document DB approach and migration system Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,65 @@
|
||||
# Example Data Structure for Axia4
|
||||
# Data Architecture for Axia4
|
||||
|
||||
Axia4 uses a **SQLite database** (`/DATA/axia4.sqlite`) for all structured data, with the
|
||||
filesystem reserved for binary assets (photos, uploaded files, project documents).
|
||||
|
||||
## Database (`/DATA/axia4.sqlite`)
|
||||
|
||||
The schema is defined in `public_html/_incl/migrations/001_initial_schema.sql` and
|
||||
applied automatically on first boot via `db.php`.
|
||||
|
||||
| Table | Replaces |
|
||||
|----------------------|---------------------------------------------------|
|
||||
| `config` | `/DATA/AuthConfig.json` |
|
||||
| `users` | `/DATA/Usuarios/*.json` |
|
||||
| `invitations` | `/DATA/Invitaciones_de_usuarios.json` |
|
||||
| `centros` | Directory existence at `.../Centros/{id}/` |
|
||||
| `user_centros` | `entreaulas.centro` + `entreaulas.aulas` in users |
|
||||
| `aularios` | `.../Aularios/{id}.json` |
|
||||
| `supercafe_menu` | `.../SuperCafe/Menu.json` |
|
||||
| `supercafe_orders` | `.../SuperCafe/Comandas/*.json` |
|
||||
| `comedor_menu_types` | `.../Comedor-MenuTypes.json` |
|
||||
| `comedor_entries` | `.../Comedor/{ym}/{day}/_datos.json` |
|
||||
| `club_events` | `/DATA/club/IMG/{date}/data.json` |
|
||||
| `club_config` | `/DATA/club/config.json` |
|
||||
|
||||
## Migrations
|
||||
|
||||
Migrations live in `public_html/_incl/migrations/`:
|
||||
|
||||
- `001_initial_schema.sql` — DDL for all tables.
|
||||
- `002_import_json.php` — One-time importer: reads existing JSON files and
|
||||
inserts them into the database. Run automatically on first boot if JSON files
|
||||
exist and the DB is empty.
|
||||
|
||||
## Filesystem (binary / large assets)
|
||||
|
||||
```
|
||||
DATA/
|
||||
└── entreaulas/
|
||||
└── Centros/
|
||||
└── {centro_id}/
|
||||
├── Aularios/
|
||||
│ └── {aulario_id}/
|
||||
│ ├── Alumnos/ # Student photo directories
|
||||
│ │ └── {alumno}/photo.jpg
|
||||
│ ├── Comedor/{ym}/{day}/ # Comedor pictogram images
|
||||
│ └── Proyectos/ # Project binary files
|
||||
└── Panel/
|
||||
└── Actividades/{name}/photo.jpg # Activity photos
|
||||
└── club/
|
||||
└── IMG/{date}/ # Club event photos (still on filesystem)
|
||||
```
|
||||
|
||||
## Multi-Tenant Support
|
||||
|
||||
A user can belong to **multiple centros** (organizations). The active centro
|
||||
is stored in `$_SESSION['active_centro']` and can be switched at any time via
|
||||
`POST /_incl/switch_tenant.php`.
|
||||
|
||||
The account page (`/account/`) shows all assigned organizations and lets the
|
||||
user switch between them.
|
||||
|
||||
|
||||
This directory contains example data files that demonstrate the structure needed for the Axia4 application.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user