From 3c1e5c6a2d34792bbe85ac34461f5484606981cd Mon Sep 17 00:00:00 2001 From: dahoud <41957584+DahoudG@users.noreply.github.com> Date: Wed, 8 Apr 2026 17:01:58 +0000 Subject: [PATCH] fix: SystemAlert @PrePersist override + types_reference complete schema in V1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SystemAlert.onCreate() now calls super.onCreate() to set dateCreation (was null → NOT NULL violation every minute) - V1: types_reference updated with full schema (domaine, est_defaut, est_systeme, ordre_affichage, modules_requis, organisation_id) - V9: idempotent guard for categorie nullable ALTER (already nullable in updated V1) --- .../lions/unionflow/server/entity/SystemAlert.java | 1 + .../db/migration/V1__UnionFlow_Complete_Schema.sql | 13 ++++++++++--- .../V9__Fix_TypesReference_Categorie_Nullable.sql | 7 ++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/lions/unionflow/server/entity/SystemAlert.java b/src/main/java/dev/lions/unionflow/server/entity/SystemAlert.java index f069066..5c60321 100644 --- a/src/main/java/dev/lions/unionflow/server/entity/SystemAlert.java +++ b/src/main/java/dev/lions/unionflow/server/entity/SystemAlert.java @@ -108,6 +108,7 @@ public class SystemAlert extends BaseEntity { */ @PrePersist protected void onCreate() { + super.onCreate(); if (timestamp == null) { timestamp = LocalDateTime.now(); } diff --git a/src/main/resources/db/migration/V1__UnionFlow_Complete_Schema.sql b/src/main/resources/db/migration/V1__UnionFlow_Complete_Schema.sql index 66cd92c..ef521f3 100644 --- a/src/main/resources/db/migration/V1__UnionFlow_Complete_Schema.sql +++ b/src/main/resources/db/migration/V1__UnionFlow_Complete_Schema.sql @@ -1055,16 +1055,23 @@ CREATE TABLE IF NOT EXISTS ayants_droit ( -- Table types_reference CREATE TABLE IF NOT EXISTS types_reference ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + domaine VARCHAR(50) NOT NULL, code VARCHAR(50) NOT NULL, - categorie VARCHAR(50) NOT NULL, + categorie VARCHAR(50), libelle VARCHAR(200) NOT NULL, description TEXT, - ordre INTEGER DEFAULT 0, + ordre_affichage INTEGER NOT NULL DEFAULT 0, + est_defaut BOOLEAN NOT NULL DEFAULT FALSE, + est_systeme BOOLEAN NOT NULL DEFAULT FALSE, + modules_requis VARCHAR(500), + organisation_id UUID, date_creation TIMESTAMP NOT NULL DEFAULT NOW(), date_modification TIMESTAMP, version BIGINT DEFAULT 0, actif BOOLEAN NOT NULL DEFAULT TRUE, - CONSTRAINT uk_type_ref UNIQUE (categorie, code) + cree_par VARCHAR(255), + modifie_par VARCHAR(255), + CONSTRAINT uk_typeref_domaine_code_org UNIQUE (domaine, code, organisation_id) ); -- Table modules_organisation_actifs diff --git a/src/main/resources/db/migration/V9__Fix_TypesReference_Categorie_Nullable.sql b/src/main/resources/db/migration/V9__Fix_TypesReference_Categorie_Nullable.sql index 9a0f951..a74c6e3 100644 --- a/src/main/resources/db/migration/V9__Fix_TypesReference_Categorie_Nullable.sql +++ b/src/main/resources/db/migration/V9__Fix_TypesReference_Categorie_Nullable.sql @@ -4,6 +4,11 @@ -- no longer includes this column, causing INSERT to fail with NOT NULL violation. -- Also drop the old unique constraint on (categorie, code) which references the old design. -ALTER TABLE types_reference ALTER COLUMN categorie DROP NOT NULL; +-- categorie is already nullable in V1 (updated schema), these are idempotent safety guards +DO $$ BEGIN + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='types_reference' AND column_name='categorie' AND is_nullable='NO') THEN + ALTER TABLE types_reference ALTER COLUMN categorie DROP NOT NULL; + END IF; +END $$; ALTER TABLE types_reference DROP CONSTRAINT IF EXISTS uk_type_ref;