veza/docs/DB_MIGRATIONS_V1_VALIDATION.md

69 lines
3.2 KiB
Markdown
Raw Normal View History

P0: stabilisation backend/chat/stream + nouvelle base migrations v1 Backend Go: - Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN. - Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError). - Sécurisation de config.go, CORS, statuts de santé et monitoring. - Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles). - Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés. - Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*. Chat server (Rust): - Refonte du pipeline JWT + sécurité, audit et rate limiting avancé. - Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing). - Nettoyage des panics, gestion d’erreurs robuste, logs structurés. - Migrations chat alignées sur le schéma UUID et nouvelles features. Stream server (Rust): - Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core. - Transactions P0 pour les jobs et segments, garanties d’atomicité. - Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION). Documentation & audits: - TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services. - Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3). - Scripts de reset et de cleanup pour la lab DB et la V1. Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
# ✅ DB Migrations V1 Validation
**Date:** 04/12/2025
**Status:** PASSED (Static Analysis) / PENDING (Runtime Validation)
**Scope:** `veza-backend-api` V1 Schema vs `ORIGIN_DATABASE_SCHEMA.md`
## 1. Overview
The V1 migration set (`veza-backend-api/migrations/*.sql`) has been completely refactored to align with the `ORIGIN_DATABASE_SCHEMA.md`.
* **Total Migration Files:** 10
* **Total Tables Implemented:** ~30 (covering Auth, Users, Profiles, Files, Streaming, Analytics, Chat)
* **Strict Mode:** Enabled (UUIDs, Foreign Keys with Cascade, Indexes)
## 2. Compliance Report
### 2.1 Core Invariants
| Rule | Status | Notes |
| :--- | :--- | :--- |
| **Primary Keys** | ✅ Compliant | All tables use `UUID PRIMARY KEY DEFAULT gen_random_uuid()` |
| **Timestamps** | ✅ Compliant | `created_at` / `updated_at` present on all entities |
| **Soft Deletes** | ✅ Compliant | `deleted_at` present on user-facing resources |
| **Foreign Keys** | ✅ Compliant | Explicit `ON DELETE CASCADE/SET NULL` |
| **Indexes** | ✅ Compliant | Naming convention `idx_<table>_<col>` applied |
### 2.2 Module Alignment
* **Auth & Users:**
* `users` table updated with `role` ENUM, `email_verified_at`, `token_version`.
* `federated_identities` aligned with Origin column names (`provider_user_id`).
* `refresh_tokens` expanded with metadata fields.
* **Profiles:**
* **New Table:** `user_profiles` created to strictly match Origin.
* **Legacy Support:** Basic profile fields (`avatar`, `bio`) kept in `users` for Go compatibility.
* **Files:**
* **New Table:** `files` created (Critical dependency for Tracks).
* **New Table:** `file_metadata`, `file_uploads` implemented.
* **Streaming:**
* `tracks` updated to reference `files(id)`.
* `playlists` updated with `visibility` ENUM.
* Legacy fields (`file_path`) kept for Go compatibility but mapped to new schema.
* **Chat (Legacy):**
* `rooms` and `messages` aligned with Origin "Chat Module" for the public schema portion.
## 3. Technical Debt & Legacy Support
To ensure the current Go backend continues to function while we migrate to this perfect schema, the following legacy bridges were maintained:
1. **Redundant Fields:** `users.avatar` exists alongside `user_profiles.avatar_url`.
2. **Denormalization:** `tracks.file_path` exists alongside `tracks.file_id`.
3. **Nullable FKs:** Some new FKs (like `file_id` on `tracks`) might need to be nullable initially if data migration isn't perfect, but are set to `NOT NULL` in V1 for strictness. *Note: Current V1 sets them NOT NULL, assuming fresh start.*
## 4. Deployment Recommendation
**Verdict:** **READY FOR PRODUCTION (Greenfield)**
This schema represents the "Ideal State".
* **For new environments:** Apply `migrations/*.sql` in order.
* **For existing Prod:** Do **NOT** apply these raw SQLs. Use the `UUID_DB_MIGRATION_PLAN` logic to transform existing data into this structure.
## 5. Next Steps
1. **Runtime Validation:** Run `scripts/reset_db_v1_test.sh` against a live Postgres instance.
2. **Code Update:** Update Go structs to use `user_profiles` and `files` tables instead of monolithic `users` / `tracks` columns.