fix: SystemAlert @PrePersist override + types_reference complete schema in V1

- 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)
This commit is contained in:
dahoud
2026-04-08 17:01:58 +00:00
parent 771755dce8
commit 3c1e5c6a2d
3 changed files with 17 additions and 4 deletions

View File

@@ -108,6 +108,7 @@ public class SystemAlert extends BaseEntity {
*/ */
@PrePersist @PrePersist
protected void onCreate() { protected void onCreate() {
super.onCreate();
if (timestamp == null) { if (timestamp == null) {
timestamp = LocalDateTime.now(); timestamp = LocalDateTime.now();
} }

View File

@@ -1055,16 +1055,23 @@ CREATE TABLE IF NOT EXISTS ayants_droit (
-- Table types_reference -- Table types_reference
CREATE TABLE IF NOT EXISTS types_reference ( CREATE TABLE IF NOT EXISTS types_reference (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
domaine VARCHAR(50) NOT NULL,
code VARCHAR(50) NOT NULL, code VARCHAR(50) NOT NULL,
categorie VARCHAR(50) NOT NULL, categorie VARCHAR(50),
libelle VARCHAR(200) NOT NULL, libelle VARCHAR(200) NOT NULL,
description TEXT, 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_creation TIMESTAMP NOT NULL DEFAULT NOW(),
date_modification TIMESTAMP, date_modification TIMESTAMP,
version BIGINT DEFAULT 0, version BIGINT DEFAULT 0,
actif BOOLEAN NOT NULL DEFAULT TRUE, 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 -- Table modules_organisation_actifs

View File

@@ -4,6 +4,11 @@
-- no longer includes this column, causing INSERT to fail with NOT NULL violation. -- 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. -- 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; ALTER TABLE types_reference DROP CONSTRAINT IF EXISTS uk_type_ref;