diff --git a/src/main/resources/db/migration/V1.2__Create_Organisation_Table.sql b/src/main/resources/db/migration/V1.2__Create_Organisation_Table.sql index 7329794..41a4894 100644 --- a/src/main/resources/db/migration/V1.2__Create_Organisation_Table.sql +++ b/src/main/resources/db/migration/V1.2__Create_Organisation_Table.sql @@ -108,17 +108,24 @@ 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 - IF NOT EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_name = 'membres' AND column_name = 'organisation_id' + -- Vérifier d'abord si la table membres existe + IF EXISTS ( + SELECT 1 FROM information_schema.tables + WHERE table_name = 'membres' ) THEN - ALTER TABLE membres ADD COLUMN organisation_id BIGINT; - ALTER TABLE membres ADD CONSTRAINT fk_membre_organisation - FOREIGN KEY (organisation_id) REFERENCES organisations(id); - CREATE INDEX idx_membre_organisation ON membres(organisation_id); + -- 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' + ) THEN + ALTER TABLE membres ADD COLUMN organisation_id BIGINT; + ALTER TABLE membres ADD CONSTRAINT fk_membre_organisation + FOREIGN KEY (organisation_id) REFERENCES organisations(id); + CREATE INDEX idx_membre_organisation ON membres(organisation_id); + END IF; END IF; END $$;