Fix: Add table existence check in V1.2 migration
V1.2 now checks if the 'membres' table exists before trying to add the organisation_id column. This prevents failures when Flyway runs before Hibernate creates the initial schema from JPA entities. Changes: - Added table existence check before ALTER TABLE membres - Migration will skip the ALTER if table doesn't exist yet - Allows Hibernate to create initial schema first This ensures migrations work correctly without any test data.
This commit is contained in:
@@ -108,9 +108,15 @@ CREATE INDEX idx_organisation_nom_lower ON organisations(LOWER(nom));
|
||||
CREATE INDEX idx_organisation_nom_court_lower ON organisations(LOWER(nom_court));
|
||||
CREATE INDEX idx_organisation_ville_lower ON organisations(LOWER(ville));
|
||||
|
||||
-- Ajout de la colonne organisation_id à la table membres (si elle n'existe pas déjà)
|
||||
-- Ajout de la colonne organisation_id à la table membres (si la table et la colonne existent)
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Vérifier d'abord si la table membres existe
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.tables
|
||||
WHERE table_name = 'membres'
|
||||
) THEN
|
||||
-- Puis vérifier si la colonne organisation_id n'existe pas déjà
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'membres' AND column_name = 'organisation_id'
|
||||
@@ -120,6 +126,7 @@ BEGIN
|
||||
FOREIGN KEY (organisation_id) REFERENCES organisations(id);
|
||||
CREATE INDEX idx_membre_organisation ON membres(organisation_id);
|
||||
END IF;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- IMPORTANT: Aucune donnée fictive n'est insérée dans ce script de migration.
|
||||
|
||||
Reference in New Issue
Block a user