fix: pgvector deployment — idempotent migration, pgvector image, schema sync
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m21s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m21s
- docker-compose.yml: switch postgres:16-alpine to pgvector/pgvector:pg16
- migration: rewrite with IF NOT EXISTS guards, DO block for safe
text→vector(1536) conversion, handles partial/re-run states
- schema.prisma (both): add @default(now()) on NoteEmbedding.updatedAt,
sync mcp-server embedding type to Unsupported("vector(1536)")
- deploy.yaml: add docker compose pull postgres before build
This commit is contained in:
67
DEPLOY-ISSUES.md
Normal file
67
DEPLOY-ISSUES.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Déployment Issues — Migration pgvector
|
||||
|
||||
## Date: 2026-05-12
|
||||
|
||||
## Contexte
|
||||
Le commit `03e6a62` (migrate semantic search to pgvector + full-text search) a été pushé sur `main`. Le pipeline Gitea `deploy.yaml` a déployé automatiquement sur `192.168.1.190`. L'application **ne démarre plus** — erreur 502.
|
||||
|
||||
## Production Environment
|
||||
- **Serveur**: 192.168.1.190 (ops-user, sudo requires password)
|
||||
- **docker-compose.yml**: `/opt/memento/docker-compose.yml` (root-owned, ops-user cannot write directly)
|
||||
- **PostgreSQL image**: `postgres:16-alpine` — **pgvector NOT available**
|
||||
- **Database**: `memento` on `memento-postgres` container
|
||||
- **102 embeddings** existent dans la table `NoteEmbedding`
|
||||
|
||||
## Problèmes rencontrés
|
||||
|
||||
### 1. Extension pgvector manquante
|
||||
- L'image PostgreSQL est `postgres:16-alpine` — pas de pgvector
|
||||
- Il faut changer pour `pgvector/pgvector:pg16` dans le docker-compose
|
||||
- **OPS-USER ne peut pas écrire dans `/opt/memento/docker-compose.yml`** (root-owned)
|
||||
- Le `deploy.yaml` Gitea devrait gérer ce changement d'image
|
||||
|
||||
### 2. Migration Prisma failed (précédente)
|
||||
- `20260510123000_add_notebook_hierarchy_and_trash` était déjà en échec depuis le 10 mai
|
||||
- **Résolu manuellement**: `UPDATE _prisma_migrations SET finished_at = NOW() WHERE migration_name = '...' AND finished_at IS NULL;`
|
||||
|
||||
### 3. Nouvelle migration pgvector failed
|
||||
- `20260512120000_pgvector_and_fts_search` échoue car:
|
||||
- Le type `vector` n'existe pas (pgvector pas installé)
|
||||
- La colonne `updatedAt` sur `NoteEmbedding` n'a pas de default value (102 rows existants)
|
||||
- **Partiellement résolu**: `ALTER TABLE "NoteEmbedding" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT NOW();`
|
||||
|
||||
### 4. La migration doit:
|
||||
- D'abord installer l'extension pgvector: `CREATE EXTENSION IF NOT EXISTS vector;`
|
||||
- Puis modifier la colonne `embedding` de `String` (JSON) vers `vector(1536)`
|
||||
- Ajouter l'index HNSW
|
||||
- Ajouter le FTS tsvector sur `Note`
|
||||
- Tout cela doit être fait dans un ordre précis dans le fichier de migration Prisma
|
||||
|
||||
## Ce qui doit être corrigé dans le code
|
||||
|
||||
### docker-compose.yml
|
||||
```yaml
|
||||
# AVANT
|
||||
image: postgres:16-alpine
|
||||
# APRÈS
|
||||
image: pgvector/pgvector:pg16
|
||||
```
|
||||
|
||||
### Migration Prisma (fichier dans prisma/migrations/)
|
||||
La migration doit:
|
||||
1. `CREATE EXTENSION IF NOT EXISTS vector;` — en raw SQL
|
||||
2. Ajouter `updatedAt` avec `DEFAULT NOW()` sur `NoteEmbedding`
|
||||
3. Convertir la colonne `embedding` de text/JSON vers `vector(1536)` — avec conversion des données existantes
|
||||
4. Créer l'index HNSW
|
||||
5. Ajouter la colonne tsvector + trigger sur `Note`
|
||||
6. Être **idempotente** — pouvoir tourner plusieurs fois sans erreur
|
||||
|
||||
### schema.prisma
|
||||
- Vérifier que `updatedAt` a `@default(now())` et `@updatedAt`
|
||||
- Vérifier que le type `Unsupported("vector(1536)")` est correct
|
||||
|
||||
##État actuel de la prod
|
||||
- `memento-web`: **Restarting** en boucle (migration failed → app ne démarre pas)
|
||||
- `memento-mcp`: **unhealthy**
|
||||
- `memento-postgres`: healthy, mais migration en état incohérent
|
||||
- Le site retourne **502 Bad Gateway**
|
||||
Reference in New Issue
Block a user