From 2011c4f6a48e3cc6f2d0a5e8815f369ccc07a493 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Nov 2025 11:31:56 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20migrations=20SQL=20pour=20corriger?= =?UTF-8?q?=20le=20sch=C3=A9ma=20de=20base=20de=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Création du dossier migrations/ - Migration 001: Ajout de la colonne image_filename manquante - Script run-migrations.sh pour appliquer les migrations - Documentation dans migrations/README.md - Correction de l'erreur 'no such column: n.image_filename' --- migrations/001_add_image_filename.sql | 11 ++++++++ migrations/README.md | 36 +++++++++++++++++++++++++++ migrations/run-migrations.sh | 12 +++++++++ 3 files changed, 59 insertions(+) create mode 100644 migrations/001_add_image_filename.sql create mode 100644 migrations/README.md create mode 100755 migrations/run-migrations.sh diff --git a/migrations/001_add_image_filename.sql b/migrations/001_add_image_filename.sql new file mode 100644 index 0000000..0584f52 --- /dev/null +++ b/migrations/001_add_image_filename.sql @@ -0,0 +1,11 @@ +-- Migration pour ajouter la colonne image_filename à la table notes +-- À exécuter si vous obtenez l'erreur: "no such column: n.image_filename" + +-- Vérifier la structure actuelle +-- SELECT sql FROM sqlite_master WHERE name='notes'; + +-- Ajouter la colonne image_filename si elle n'existe pas +ALTER TABLE notes ADD COLUMN image_filename TEXT; + +-- Vérifier que la colonne a été ajoutée +-- SELECT * FROM notes LIMIT 1; diff --git a/migrations/README.md b/migrations/README.md new file mode 100644 index 0000000..2454bcf --- /dev/null +++ b/migrations/README.md @@ -0,0 +1,36 @@ +# Migrations de base de données + +Ce dossier contient les scripts de migration SQL pour mettre à jour le schéma de la base de données. + +## Utilisation + +### Méthode 1 : Exécuter dans le container Docker + +```bash +# Copier le script dans le container +docker cp migrations/run-migrations.sh notes-todo-app:/app/ + +# Exécuter la migration +docker exec notes-todo-app sh /app/run-migrations.sh +``` + +### Méthode 2 : Manuellement avec sqlite3 + +```bash +# Se connecter au container +docker exec -it notes-todo-app sh + +# Exécuter la migration SQL +sqlite3 /app/data/notes.db < /path/to/migration.sql +``` + +### Méthode 3 : Recréer la base de données (⚠️ perte de données) + +```bash +docker-compose down -v +docker-compose up -d --build +``` + +## Liste des migrations + +- **001_add_image_filename.sql** : Ajoute la colonne `image_filename` à la table `notes` diff --git a/migrations/run-migrations.sh b/migrations/run-migrations.sh new file mode 100755 index 0000000..a260db8 --- /dev/null +++ b/migrations/run-migrations.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Script pour exécuter les migrations SQL sur la base de données + +DB_PATH="/app/data/notes.db" + +echo "=== Exécution des migrations SQLite ===" + +# Migration 001: Ajouter image_filename +echo "Migration 001: Ajout de la colonne image_filename..." +sqlite3 $DB_PATH "ALTER TABLE notes ADD COLUMN image_filename TEXT;" 2>/dev/null && echo "✓ Migration 001 appliquée" || echo "⚠ Migration 001 déjà appliquée ou erreur" + +echo "=== Migrations terminées ==="