QubitDT KMS — Data Model Developer Guide
|
|
| Source |
Plateforme de Bornes Bancaires Libre-Service — Modélisation des données (MCD/MLD/MPD) v3.0, 2026-10-09 |
| Target DBMS |
PostgreSQL ≥ 13 (gen_random_uuid() is built in from 13; on 12 enable pgcrypto) |
| Audience |
Backend developers, DBAs, QA |
| Status |
Working guide — follows the source document; where the source contradicts itself, this guide uses the executable DDL (source §7) and lists the discrepancy in §12 |
Identifiers (tables, columns, enum values) are kept in French, exactly as in the DDL. Do not translate them in code, migrations or API contracts.
Contents
- At a glance
- Conventions
- Schemas & creation order
- Entity-relationship diagrams
- Table reference
- Relationship matrix (all foreign keys)
- Enumerations
- Lifecycles & state machines
- Integrity rules — who enforces what
- Access rights, partitioning, retention
- Developer patterns (SQL)
- Known discrepancies & open points
- Glossary FR → EN
1. At a glance
The KMS is the single gateway between self-service banking kiosks (bornes) and the two external banking backends QUBIT and KALISPOT. It owns orchestration, routing, traceability and fleet management — never banking business rules, and never card data, PIN or amounts at rest.
| Schema |
Responsibility |
Tables |
Application role |
routage |
Client banks, backends, routing rules, transactions, attempts, event log |
backend_bancaire, banque_cliente, regle_routage, transaction, tentative_backend, transaction_event |
svc_kms_routeur |
parc |
Sites, kiosks, config profiles, remote management, peripherals |
site, profil_configuration, borne, action_telegestion, type_peripherique, peripherique, historique_statut_peripherique |
(not defined in source — see §12) |
service |
Service catalogue, kiosk assignment, peripheral dependencies, SLA impact |
categorie_service, service, profil_service, profil_service_item, regle_impact_sla, borne_service, service_peripherique |
svc_kms_supervision |
ops |
Operational incidents |
incident |
(not defined in source) |
21 tables · 23 conceptual associations · 3 append-only / partitioned journals.
Admin role for all reference data: svc_noc_admin.
2. Conventions
| Topic |
Rule |
| Primary keys |
UUID DEFAULT gen_random_uuid() for business/reference tables. BIGSERIAL + timestamp composite PK for partitioned journals (tentative_backend, transaction_event, historique_statut_peripherique). |
| Business keys |
code TEXT NOT NULL UNIQUE on reference tables (site, banque_cliente, type_peripherique, service, …). Use code in config and logs, id_* in FKs. |
| Timestamps |
Always TIMESTAMPTZ. Never store local time. Dates without time use DATE. |
| Enumerations |
TEXT + CHECK (... IN (...)) — not PG ENUM types. Adding a value = migration that drops/recreates the CHECK. |
| Soft deactivation |
actif / active booleans. Never DELETE reference rows that have history. |
| Versioning |
version INTEGER on regle_routage, profil_configuration, service. A significant change creates a new version rather than a silent update. |
| Current state vs journal |
Pattern used twice: a mutable current-state row + an append-only partitioned journal (transaction → transaction_event, peripherique → historique_statut_peripherique). Both writes happen in the same DB transaction. |
| Nullable FK = optional relation |
e.g. borne.id_profil_configuration, transaction.id_regle_appliquee, incident.id_borne. |
| Reserved-ish names |
routage.transaction and service.service are legal but TRANSACTION is an SQL keyword: always schema-qualify, and configure your ORM to quote identifiers. |
3. Schemas & creation order
Creation order does not follow schema boundaries, because of cross-schema FKs.
flowchart LR
subgraph R1["① routage (I)"]
BB[backend_bancaire] --> BC[banque_cliente]
end
subgraph P["② parc"]
SI[site]
PC[profil_configuration]
BO[borne]
TP[type_peripherique]
PE[peripherique]
HS[historique_statut_peripherique]
AT[action_telegestion]
SI --> BO
PC --> BO
BO --> PE
TP --> PE
PE --> HS
BO --> AT
end
subgraph O["③ ops"]
IN[incident]
end
subgraph R2["④ routage (II)"]
RR[regle_routage]
TR[transaction]
TB[tentative_backend]
TE[transaction_event]
RR --> TR
TR --> TB
TR --> TE
end
subgraph S["⑤ service"]
CS[categorie_service] --> SV[service]
PS[profil_service] --> PSI[profil_service_item]
SV --> PSI
SV --> RIS[regle_impact_sla]
SV --> BS[borne_service]
PS --> BS
SV --> SP[service_peripherique]
end
BC --> BO
BO --> IN
BB --> RR
BC --> RR
BO --> TR
IN --> TR
BB --> TR
BB --> TB
BO --> BS
TP --> SP
Arrow = "is referenced by" (parent → child). Migrations must respect ① → ⑤.
4. Entity-relationship diagrams
Crow's-foot notation: || exactly one · |o zero or one · o{ zero or many.
4.1 Overview — all 21 entities
erDiagram
BACKEND_BANCAIRE ||--o{ BANQUE_CLIENTE : "RATTACHER"
BACKEND_BANCAIRE ||--o{ REGLE_ROUTAGE : "CIBLER"
BANQUE_CLIENTE |o--o{ REGLE_ROUTAGE : "QUALIFIER"
BANQUE_CLIENTE ||--o{ BORNE : "AFFILIER"
SITE ||--o{ BORNE : "HEBERGER"
PROFIL_CONFIGURATION |o--o{ BORNE : "CONFIGURER"
BORNE ||--o{ ACTION_TELEGESTION : "COMMANDER"
BORNE ||--o{ TRANSACTION : "EMETTRE"
REGLE_ROUTAGE |o--o{ TRANSACTION : "APPLIQUER"
BACKEND_BANCAIRE |o--o{ TRANSACTION : "backend retenu"
TRANSACTION ||--o{ TENTATIVE_BACKEND : "TENTER"
BACKEND_BANCAIRE ||--o{ TENTATIVE_BACKEND : "SOLLICITER"
TRANSACTION ||--o{ TRANSACTION_EVENT : "JOURNALISER"
INCIDENT |o--o{ TRANSACTION : "DECLENCHER"
BORNE |o--o{ INCIDENT : "SIGNALER"
BORNE ||--o{ PERIPHERIQUE : "EQUIPER"
TYPE_PERIPHERIQUE ||--o{ PERIPHERIQUE : "TYPER"
PERIPHERIQUE ||--o{ HISTORIQUE_STATUT_PERIPHERIQUE : "HISTORISER"
CATEGORIE_SERVICE ||--o{ SERVICE : "RELEVER"
BORNE ||--o{ BORNE_SERVICE : "AFFECTER"
SERVICE ||--o{ BORNE_SERVICE : "AFFECTER"
PROFIL_SERVICE |o--o{ BORNE_SERVICE : "ORIGINER"
SERVICE ||--o{ SERVICE_PERIPHERIQUE : "DEPENDRE"
TYPE_PERIPHERIQUE ||--o{ SERVICE_PERIPHERIQUE : "DEPENDRE"
PROFIL_SERVICE ||--o{ PROFIL_SERVICE_ITEM : "REGROUPER"
SERVICE ||--o{ PROFIL_SERVICE_ITEM : "REGROUPER"
SERVICE ||--o{ REGLE_IMPACT_SLA : "QUALIFIER_SLA"
4.2 routage — banks, backends, rules, transactions
erDiagram
BACKEND_BANCAIRE {
uuid id_backend PK
text code UK "QUBIT | KALISPOT"
text nom_commercial_core_banking
text url_base
text protocole
text etat_circuit "FERME | OUVERT | SEMI_OUVERT"
int timeout_ms "default 8000"
bool actif
timestamptz last_health_check_at
timestamptz created_at
timestamptz updated_at
}
BANQUE_CLIENTE {
uuid id_banque PK
text code UK "ex. BIIC"
text libelle
text nom_commercial_core_banking
uuid id_backend_reference FK
bool eligible_failover_inter_backend "default false"
text statut "ACTIVE | INACTIVE"
date date_rattachement
}
REGLE_ROUTAGE {
uuid id_regle PK
int priorite UK "unique per environnement"
text environnement UK "PRODUCTION | PREPRODUCTION | SANDBOX"
uuid id_banque_critere FK "NULL = wildcard"
text critere_type_operation "NULL = wildcard"
text critere_canal "NULL = wildcard"
numeric montant_min
numeric montant_max
uuid id_backend_cible FK
int poids_pct "1..100"
bool eligible_failover_inter_backend "default false"
bool active
timestamptz valid_from
timestamptz valid_to
int version
text change_ticket
}
TRANSACTION {
uuid id_transaction PK
uuid id_borne FK
uuid correlation_id
text type_operation
text idempotency_key UK "unique with id_borne"
text payload_hash
text statut
uuid id_regle_appliquee FK
uuid id_backend_retenu FK
bool eligible_failover_inter_backend "frozen at routing"
int nb_tentatives_reconciliation
timestamptz prochaine_reconciliation_a
uuid id_incident FK
timestamptz horodatage_creation
timestamptz horodatage_cloture
}
TENTATIVE_BACKEND {
bigint id_tentative PK
timestamptz horodatage_emission PK "partition key"
uuid id_transaction FK
uuid id_backend FK
int numero_tentative
text statut "ENVOYEE | REPONSE_RECUE | TIMEOUT | ECHEC_RESEAU"
text code_retour_backend
timestamptz horodatage_reponse
int duree_traitement_ms
}
TRANSACTION_EVENT {
bigint id_event PK
timestamptz horodatage_evenement PK "partition key"
uuid id_transaction FK
text type_evenement
text statut_snapshot
text payload_hash
text acteur
}
BACKEND_BANCAIRE ||--o{ BANQUE_CLIENTE : "reference backend"
BACKEND_BANCAIRE ||--o{ REGLE_ROUTAGE : "cible"
BANQUE_CLIENTE |o--o{ REGLE_ROUTAGE : "critere"
REGLE_ROUTAGE |o--o{ TRANSACTION : "appliquee"
BACKEND_BANCAIRE |o--o{ TRANSACTION : "retenu"
TRANSACTION ||--o{ TENTATIVE_BACKEND : "tentatives"
BACKEND_BANCAIRE ||--o{ TENTATIVE_BACKEND : "sollicite"
TRANSACTION ||--o{ TRANSACTION_EVENT : "evenements"
4.3 parc — sites, kiosks, peripherals, remote management
erDiagram
SITE {
uuid id_site PK
text code UK "ex. AG-PLATEAU-01"
text nom
text adresse
text type_site "AGENCE | HORS_AGENCE | CENTRE_COMMERCIAL | AUTRE"
text responsable_local
timestamptz created_at
}
PROFIL_CONFIGURATION {
uuid id_profil PK
text nom UK "unique with version"
int version UK
jsonb parametres
bool actif
timestamptz date_creation
}
BORNE {
uuid id_borne PK
text numero_serie UK
uuid id_site FK
uuid id_banque FK "-> routage.banque_cliente"
text certificat_mtls_id UK
text statut "EN_SERVICE | MODE_DEGRADE | HORS_SERVICE | MAINTENANCE"
uuid id_profil_configuration FK
text version_agent
date date_mise_en_service
timestamptz date_derniere_supervision
}
ACTION_TELEGESTION {
uuid id_action PK
uuid id_borne FK
text type_action
text statut "DEMANDEE | EN_COURS | REUSSIE | ECHOUEE"
text demandee_par
timestamptz horodatage_demande
timestamptz horodatage_execution
text resultat
}
TYPE_PERIPHERIQUE {
uuid id_type_peripherique PK
text code UK "ex. CARD_READER"
text libelle
}
PERIPHERIQUE {
uuid id_peripherique PK
uuid id_borne FK
uuid id_type_peripherique FK
text numero_serie UK "nullable"
text fabricant
text version_firmware
text statut "OPERATIONNEL | PANNE | CONSOMMABLE_BAS | INCONNU"
text code_erreur
int niveau_consommable_pct "0..100"
date date_installation
timestamptz date_dernier_changement_statut
}
HISTORIQUE_STATUT_PERIPHERIQUE {
bigint id_historique PK
timestamptz horodatage PK "partition key"
uuid id_peripherique FK
text statut_precedent
text statut_nouveau
text code_erreur
text source "HEARTBEAT | TELEGESTION_DIAGNOSTIC | SAISIE_MANUELLE"
}
SITE ||--o{ BORNE : "heberge"
PROFIL_CONFIGURATION |o--o{ BORNE : "configure"
BORNE ||--o{ ACTION_TELEGESTION : "commandes"
BORNE ||--o{ PERIPHERIQUE : "equipe"
TYPE_PERIPHERIQUE ||--o{ PERIPHERIQUE : "type"
PERIPHERIQUE ||--o{ HISTORIQUE_STATUT_PERIPHERIQUE : "historique"
4.4 service — catalogue, assignment, dependencies, SLA
erDiagram
CATEGORIE_SERVICE {
uuid id_categorie PK
text code UK
text libelle
int ordre_affichage
bool actif
}
SERVICE {
uuid id_service PK
text code UK
text libelle
uuid id_categorie FK
int version
text statut "BROUILLON | ACTIF | SUSPENDU | OBSOLETE"
text criticite "CRITIQUE | MAJEUR | MINEUR"
text niveau_sla
interval duree_max_indisponibilite
int priorite
bool bloquant
timestamptz created_at
text created_by
}
PROFIL_SERVICE {
uuid id_profil_service PK
text code UK "ex. ATM_STANDARD"
text libelle
bool actif
}
PROFIL_SERVICE_ITEM {
uuid id_profil_service PK,FK
uuid id_service PK,FK
}
BORNE_SERVICE {
uuid id_borne PK,FK "-> parc.borne"
uuid id_service PK,FK
text source "DIRECT | PROFIL"
uuid id_profil_service_origine FK "set iff source = PROFIL"
text statut_affectation "AVAILABLE | DEGRADED | UNAVAILABLE"
timestamptz date_affectation
}
SERVICE_PERIPHERIQUE {
uuid id_service PK,FK
uuid id_type_peripherique PK,FK "-> parc.type_peripherique"
text niveau_dependance
}
REGLE_IMPACT_SLA {
uuid id_regle PK
uuid id_service FK
jsonb expression
int priorite
bool active
}
BORNE {
uuid id_borne PK
}
TYPE_PERIPHERIQUE {
uuid id_type_peripherique PK
}
CATEGORIE_SERVICE ||--o{ SERVICE : "categorise"
PROFIL_SERVICE ||--o{ PROFIL_SERVICE_ITEM : "contient"
SERVICE ||--o{ PROFIL_SERVICE_ITEM : "inclus dans"
BORNE ||--o{ BORNE_SERVICE : "propose"
SERVICE ||--o{ BORNE_SERVICE : "affecte a"
PROFIL_SERVICE |o--o{ BORNE_SERVICE : "origine"
SERVICE ||--o{ SERVICE_PERIPHERIQUE : "requiert"
TYPE_PERIPHERIQUE ||--o{ SERVICE_PERIPHERIQUE : "requis par"
SERVICE ||--o{ REGLE_IMPACT_SLA : "regles SLA"
4.5 ops — incidents and their links
erDiagram
INCIDENT {
uuid id_incident PK
text type_incident "SEUIL_SYSTEME | PERIPHERIQUE_PANNE | BORNE_HORS_SERVICE | ECHEC_ROUTAGE | AUTRE"
text severite "P1_CRITIQUE | P2_MAJEUR | P3_MINEUR"
text statut "OUVERT | EN_COURS | RESOLU | FERME"
text description
uuid id_borne FK "nullable"
timestamptz date_creation
timestamptz date_resolution
}
BORNE {
uuid id_borne PK
}
TRANSACTION {
uuid id_transaction PK
uuid id_incident FK "nullable"
}
BORNE |o--o{ INCIDENT : "signale"
INCIDENT |o--o{ TRANSACTION : "regroupe"
Direction note: the FK is on transaction.id_incident (many transactions → one incident), not on incident. One incident consolidates repeated failures.
5. Table reference
Legend — N: nullable · PK primary key · FK foreign key · UK unique.
5.1 Schema routage
routage.backend_bancaire — banking backends (reference, admin-write)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_backend |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK, IN ('QUBIT','KALISPOT') |
|
nom_commercial_core_banking |
TEXT |
✓ |
|
|
e.g. Amplitude Core Banking, PowerCard |
url_base |
TEXT |
|
|
|
Adapter endpoint |
protocole |
TEXT |
|
|
|
REST, SOAP… (free text) |
etat_circuit |
TEXT |
|
'FERME' |
IN ('FERME','OUVERT','SEMI_OUVERT') |
Circuit breaker state, read at routing time |
timeout_ms |
INTEGER |
|
8000 |
|
|
actif |
BOOLEAN |
|
true |
|
Disable without deleting |
last_health_check_at |
TIMESTAMPTZ |
✓ |
|
|
|
created_at, updated_at |
TIMESTAMPTZ |
|
now() |
|
updated_at is not auto-maintained (no trigger) |
routage.banque_cliente — client banks, single source of truth for bank → backend
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_banque |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK |
e.g. BIIC |
libelle |
TEXT |
|
|
|
|
nom_commercial_core_banking |
TEXT |
✓ |
|
|
|
id_backend_reference |
UUID |
|
|
FK → backend_bancaire |
Mandatory |
eligible_failover_inter_backend |
BOOLEAN |
|
false |
|
KMS-DATA-003 |
statut |
TEXT |
|
'ACTIVE' |
IN ('ACTIVE','INACTIVE') |
|
date_rattachement |
DATE |
|
CURRENT_DATE |
|
|
routage.regle_routage — versioned routing rules (admin-write)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_regle |
UUID |
|
gen_random_uuid() |
PK |
|
priorite |
INTEGER |
|
|
UK (priorite, environnement) |
Lower = evaluated first |
environnement |
TEXT |
|
'PRODUCTION' |
IN ('PRODUCTION','PREPRODUCTION','SANDBOX') |
|
id_banque_critere |
UUID |
✓ |
|
FK → banque_cliente |
NULL = any bank |
critere_type_operation |
TEXT |
✓ |
|
|
NULL = any |
critere_canal |
TEXT |
✓ |
|
|
NULL = any |
montant_min, montant_max |
NUMERIC(14,2) |
✓ |
|
min <= max |
See §12 (amount not stored elsewhere) |
id_backend_cible |
UUID |
|
|
FK → backend_bancaire |
|
poids_pct |
INTEGER |
|
100 |
BETWEEN 1 AND 100 |
Group sum = 100 → app/trigger (KMS-DATA-006) |
eligible_failover_inter_backend |
BOOLEAN |
|
false |
|
|
active |
BOOLEAN |
|
true |
|
|
valid_from |
TIMESTAMPTZ |
|
now() |
|
|
valid_to |
TIMESTAMPTZ |
✓ |
|
|
NULL = open-ended |
version |
INTEGER |
|
1 |
|
|
created_at / created_by |
TIMESTAMPTZ / TEXT |
|
now() / — |
|
created_by mandatory |
updated_at / updated_by |
TIMESTAMPTZ / TEXT |
updated_by ✓ |
now() |
|
|
change_ticket |
TEXT |
✓ |
|
|
Required by process when enabling failover |
routage.transaction — idempotent business transaction (mutable current state)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_transaction |
UUID |
|
gen_random_uuid() |
PK |
Not partitioned |
id_borne |
UUID |
|
|
FK → parc.borne |
|
correlation_id |
UUID |
|
|
indexed |
Propagated end-to-end; main support lookup key |
type_operation |
TEXT |
|
|
|
Free text (no CHECK) |
idempotency_key |
TEXT |
|
|
UK (id_borne, idempotency_key) |
Generated by the kiosk |
payload_hash |
TEXT |
|
|
|
Reuse with different hash → reject (KMS-DATA-002) |
statut |
TEXT |
|
'CREE' |
see §7 |
|
id_regle_appliquee |
UUID |
✓ |
|
FK → regle_routage |
Audit: which rule (KMS-DATA-007) |
id_backend_retenu |
UUID |
✓ |
|
FK → backend_bancaire |
NULL until routed |
eligible_failover_inter_backend |
BOOLEAN |
|
false |
|
Frozen copy at routing time |
nb_tentatives_reconciliation |
INTEGER |
|
0 |
|
|
prochaine_reconciliation_a |
TIMESTAMPTZ |
✓ |
|
partial index |
Reconciliation job queue |
id_incident |
UUID |
✓ |
|
FK → ops.incident |
|
horodatage_creation |
TIMESTAMPTZ |
|
now() |
|
|
horodatage_cloture |
TIMESTAMPTZ |
✓ |
|
|
Set on final status |
routage.tentative_backend — one row per backend call (mutable, partitioned monthly)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_tentative |
BIGSERIAL |
|
sequence |
PK (1/2) |
|
horodatage_emission |
TIMESTAMPTZ |
|
now() |
PK (2/2), partition key |
|
id_transaction |
UUID |
|
|
FK → transaction |
|
id_backend |
UUID |
|
|
FK → backend_bancaire |
NOT NULL: no attempt before routing |
numero_tentative |
INTEGER |
|
1 |
|
1, 2, 3… (uniqueness not enforced, see §12) |
statut |
TEXT |
|
'ENVOYEE' |
IN ('ENVOYEE','REPONSE_RECUE','TIMEOUT','ECHEC_RESEAU') |
|
code_retour_backend |
TEXT |
✓ |
|
|
Raw backend code |
horodatage_reponse |
TIMESTAMPTZ |
✓ |
|
|
|
duree_traitement_ms |
INTEGER |
✓ |
|
|
SLA tracking |
routage.transaction_event — immutable audit journal (append-only, partitioned monthly)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_event |
BIGSERIAL |
|
sequence |
PK (1/2) |
|
horodatage_evenement |
TIMESTAMPTZ |
|
now() |
PK (2/2), partition key |
Named horodatage_event in the source dictionary — DDL wins |
id_transaction |
UUID |
|
|
FK → transaction |
|
type_evenement |
TEXT |
|
|
see §7 |
|
statut_snapshot |
TEXT |
|
|
|
Transaction status right after the event |
payload_hash |
TEXT |
|
|
|
|
acteur |
TEXT |
|
|
|
kms-routeur, job-reconciliation, operateur:<id> |
No UPDATE / DELETE ever (KMS-DATA-001).
5.2 Schema parc
parc.site
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_site |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK |
e.g. AG-PLATEAU-01 |
nom |
TEXT |
|
|
|
|
adresse |
TEXT |
✓ |
|
|
|
type_site |
TEXT |
|
'AGENCE' |
IN ('AGENCE','HORS_AGENCE','CENTRE_COMMERCIAL','AUTRE') |
|
responsable_local |
TEXT |
✓ |
|
|
|
created_at |
TIMESTAMPTZ |
|
now() |
|
|
parc.profil_configuration — versioned technical config profile
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_profil |
UUID |
|
gen_random_uuid() |
PK |
|
nom |
TEXT |
|
|
UK (nom, version) |
|
version |
INTEGER |
|
1 |
|
New version per significant change |
parametres |
JSONB |
|
'{}' |
|
Schema owned by the kiosk agent |
actif |
BOOLEAN |
|
true |
|
|
date_creation |
TIMESTAMPTZ |
|
now() |
|
|
parc.borne — kiosk
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_borne |
UUID |
|
gen_random_uuid() |
PK |
|
numero_serie |
TEXT |
|
|
UK |
|
id_site |
UUID |
|
|
FK → site |
|
id_banque |
UUID |
|
|
FK → routage.banque_cliente |
Bank affiliation is per kiosk |
certificat_mtls_id |
TEXT |
|
|
UK |
Individually revocable |
statut |
TEXT |
|
'EN_SERVICE' |
IN ('EN_SERVICE','MODE_DEGRADE','HORS_SERVICE','MAINTENANCE') |
Can block operations before routing |
id_profil_configuration |
UUID |
✓ |
|
FK → profil_configuration |
NULL = default config |
version_agent |
TEXT |
✓ |
|
|
|
date_mise_en_service |
DATE |
|
CURRENT_DATE |
|
|
date_derniere_supervision |
TIMESTAMPTZ |
✓ |
|
|
Last heartbeat |
parc.action_telegestion — remote actions log
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_action |
UUID |
|
gen_random_uuid() |
PK |
|
id_borne |
UUID |
|
|
FK → borne |
|
type_action |
TEXT |
|
|
see §7 |
|
statut |
TEXT |
|
'DEMANDEE' |
see §7 |
|
demandee_par |
TEXT |
|
|
|
Operator or system id |
horodatage_demande |
TIMESTAMPTZ |
|
now() |
|
|
horodatage_execution |
TIMESTAMPTZ |
✓ |
|
|
|
resultat |
TEXT |
✓ |
|
|
|
parc.type_peripherique — peripheral types (reference)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_type_peripherique |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK |
CARD_READER, CASH_DISPENSER, PRINTER_TICKET, PRINTER_A4, QR_READER… |
libelle |
TEXT |
|
|
|
|
parc.peripherique — installed peripheral + current state
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_peripherique |
UUID |
|
gen_random_uuid() |
PK |
|
id_borne |
UUID |
|
|
FK → borne |
|
id_type_peripherique |
UUID |
|
|
FK → type_peripherique |
|
numero_serie |
TEXT |
✓ |
|
UK |
|
fabricant |
TEXT |
✓ |
|
|
|
version_firmware |
TEXT |
✓ |
|
|
|
statut |
TEXT |
|
'INCONNU' |
IN ('OPERATIONNEL','PANNE','CONSOMMABLE_BAS','INCONNU') |
|
code_erreur |
TEXT |
✓ |
|
|
Expected when statut = 'PANNE' (not enforced) |
niveau_consommable_pct |
INTEGER |
✓ |
|
BETWEEN 0 AND 100 |
|
date_installation |
DATE |
✓ |
|
|
|
date_dernier_changement_statut |
TIMESTAMPTZ |
✓ |
|
|
Copied from the history row |
parc.historique_statut_peripherique — status journal (append-only, partitioned monthly)
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_historique |
BIGSERIAL |
|
sequence |
PK (1/2) |
|
horodatage |
TIMESTAMPTZ |
|
now() |
PK (2/2), partition key |
|
id_peripherique |
UUID |
|
|
FK → peripherique |
|
statut_precedent |
TEXT |
✓ |
|
|
NULL on first measure |
statut_nouveau |
TEXT |
|
|
(no CHECK — see §12) |
Same values as peripherique.statut |
code_erreur |
TEXT |
✓ |
|
|
|
source |
TEXT |
|
|
|
HEARTBEAT, TELEGESTION_DIAGNOSTIC, SAISIE_MANUELLE |
5.3 Schema service
service.categorie_service
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_categorie |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK |
TRANSACTIONS, CONSULTATION… |
libelle |
TEXT |
|
|
|
|
ordre_affichage |
INTEGER |
|
0 |
|
UI ordering |
actif |
BOOLEAN |
|
true |
|
|
service.service — versioned service catalogue
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_service |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK |
⚠ unique alone → blocks multiple versions (§12) |
libelle |
TEXT |
|
|
|
|
id_categorie |
UUID |
|
|
FK → categorie_service |
|
version |
INTEGER |
|
1 |
|
|
statut |
TEXT |
|
'BROUILLON' |
IN ('BROUILLON','ACTIF','SUSPENDU','OBSOLETE') |
OBSOLETE → no new assignment (KMS-DATA-009) |
criticite |
TEXT |
✓ |
|
IN ('CRITIQUE','MAJEUR','MINEUR') |
|
niveau_sla |
TEXT |
✓ |
|
|
|
duree_max_indisponibilite |
INTERVAL |
✓ |
|
|
Escalation threshold |
priorite |
INTEGER |
✓ |
|
|
Ops priority |
bloquant |
BOOLEAN |
|
false |
|
Unavailable → kiosk goes MODE_DEGRADE |
created_at / created_by |
TIMESTAMPTZ / TEXT |
|
now() / — |
|
|
service.profil_service / service.profil_service_item — service bundles
| Table |
Column |
Type |
N |
Default |
Constraint |
profil_service |
id_profil_service |
UUID |
|
gen_random_uuid() |
PK |
|
code |
TEXT |
|
|
UK (ATM_STANDARD, ATM_DEPOT) |
|
libelle |
TEXT |
|
|
|
|
actif |
BOOLEAN |
|
true |
|
profil_service_item |
id_profil_service |
UUID |
|
|
PK (1/2), FK → profil_service |
|
id_service |
UUID |
|
|
PK (2/2), FK → service |
service.borne_service — effective service assignment per kiosk
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_borne |
UUID |
|
|
PK (1/2), FK → parc.borne |
|
id_service |
UUID |
|
|
PK (2/2), FK → service |
|
source |
TEXT |
|
'PROFIL' |
IN ('DIRECT','PROFIL') |
|
id_profil_service_origine |
UUID |
✓ |
|
FK → profil_service |
CHECK: NULL ⇔ source = 'DIRECT' |
statut_affectation |
TEXT |
|
'AVAILABLE' |
IN ('AVAILABLE','DEGRADED','UNAVAILABLE') |
Computed from peripherals (§11.5) |
date_affectation |
TIMESTAMPTZ |
|
now() |
|
|
Because source defaults to 'PROFIL', an insert that omits both source and id_profil_service_origine fails the CHECK. Always set source explicitly.
service.service_peripherique — service → peripheral type dependency
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_service |
UUID |
|
|
PK (1/2), FK → service |
|
id_type_peripherique |
UUID |
|
|
PK (2/2), FK → parc.type_peripherique |
|
niveau_dependance |
TEXT |
|
|
see §7 |
|
service.regle_impact_sla
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_regle |
UUID |
|
gen_random_uuid() |
PK |
|
id_service |
UUID |
|
|
FK → service |
|
expression |
JSONB |
|
|
|
Structured condition set — format not yet specified |
priorite |
INTEGER |
|
|
|
Evaluation order per service |
active |
BOOLEAN |
|
true |
|
|
5.4 Schema ops
ops.incident
| Column |
Type |
N |
Default |
Constraint |
Notes |
id_incident |
UUID |
|
gen_random_uuid() |
PK |
|
type_incident |
TEXT |
|
|
see §7 |
|
severite |
TEXT |
|
|
IN ('P1_CRITIQUE','P2_MAJEUR','P3_MINEUR') |
|
statut |
TEXT |
|
'OUVERT' |
IN ('OUVERT','EN_COURS','RESOLU','FERME') |
|
description |
TEXT |
✓ |
|
|
|
id_borne |
UUID |
✓ |
|
FK → parc.borne |
NULL for global incidents |
date_creation |
TIMESTAMPTZ |
|
now() |
|
|
date_resolution |
TIMESTAMPTZ |
✓ |
|
|
|
6. Relationship matrix (all foreign keys)
| # |
Child table.column |
→ Parent |
Nullable |
Cardinality (parent : child) |
MCD association |
| 1 |
routage.banque_cliente.id_backend_reference |
routage.backend_bancaire |
no |
1 : 0..n |
RATTACHER |
| 2 |
routage.regle_routage.id_banque_critere |
routage.banque_cliente |
yes |
0..1 : 0..n |
QUALIFIER |
| 3 |
routage.regle_routage.id_backend_cible |
routage.backend_bancaire |
no |
1 : 0..n |
CIBLER |
| 4 |
parc.borne.id_banque |
routage.banque_cliente |
no |
1 : 0..n |
AFFILIER |
| 5 |
parc.borne.id_site |
parc.site |
no |
1 : 0..n |
HEBERGER |
| 6 |
parc.borne.id_profil_configuration |
parc.profil_configuration |
yes |
0..1 : 0..n |
CONFIGURER |
| 7 |
parc.action_telegestion.id_borne |
parc.borne |
no |
1 : 0..n |
COMMANDER |
| 8 |
parc.peripherique.id_borne |
parc.borne |
no |
1 : 0..n |
EQUIPER |
| 9 |
parc.peripherique.id_type_peripherique |
parc.type_peripherique |
no |
1 : 0..n |
TYPER |
| 10 |
parc.historique_statut_peripherique.id_peripherique |
parc.peripherique |
no |
1 : 0..n |
HISTORISER |
| 11 |
ops.incident.id_borne |
parc.borne |
yes |
0..1 : 0..n |
SIGNALER |
| 12 |
routage.transaction.id_borne |
parc.borne |
no |
1 : 0..n |
EMETTRE |
| 13 |
routage.transaction.id_regle_appliquee |
routage.regle_routage |
yes |
0..1 : 0..n |
APPLIQUER |
| 14 |
routage.transaction.id_backend_retenu |
routage.backend_bancaire |
yes |
0..1 : 0..n |
(none in MCD — §12) |
| 15 |
routage.transaction.id_incident |
ops.incident |
yes |
0..1 : 0..n |
DECLENCHER |
| 16 |
routage.tentative_backend.id_transaction |
routage.transaction |
no |
1 : 0..n |
TENTER |
| 17 |
routage.tentative_backend.id_backend |
routage.backend_bancaire |
no |
1 : 0..n |
SOLLICITER |
| 18 |
routage.transaction_event.id_transaction |
routage.transaction |
no |
1 : 0..n |
JOURNALISER |
| 19 |
service.service.id_categorie |
service.categorie_service |
no |
1 : 0..n |
RELEVER |
| 20 |
service.profil_service_item.id_profil_service |
service.profil_service |
no |
1 : 0..n |
REGROUPER |
| 21 |
service.profil_service_item.id_service |
service.service |
no |
1 : 0..n |
REGROUPER |
| 22 |
service.regle_impact_sla.id_service |
service.service |
no |
1 : 0..n |
QUALIFIER_SLA |
| 23 |
service.borne_service.id_borne |
parc.borne |
no |
1 : 0..n |
AFFECTER |
| 24 |
service.borne_service.id_service |
service.service |
no |
1 : 0..n |
AFFECTER |
| 25 |
service.borne_service.id_profil_service_origine |
service.profil_service |
yes |
0..1 : 0..n |
ORIGINER |
| 26 |
service.service_peripherique.id_service |
service.service |
no |
1 : 0..n |
DEPENDRE |
| 27 |
service.service_peripherique.id_type_peripherique |
parc.type_peripherique |
no |
1 : 0..n |
DEPENDRE |
All FKs use the default ON DELETE NO ACTION — parent rows with children cannot be deleted. This is intentional: deactivate instead.
Cross-schema dependencies
| From schema |
References |
parc |
routage.banque_cliente |
ops |
parc.borne |
routage (II) |
parc.borne, ops.incident |
service |
parc.borne, parc.type_peripherique |
7. Enumerations
| Table.column |
Values |
Default |
backend_bancaire.code |
QUBIT, KALISPOT |
— |
backend_bancaire.etat_circuit |
FERME, OUVERT, SEMI_OUVERT |
FERME |
banque_cliente.statut |
ACTIVE, INACTIVE |
ACTIVE |
regle_routage.environnement |
PRODUCTION, PREPRODUCTION, SANDBOX |
PRODUCTION |
transaction.statut |
CREE, ROUTEE, REPONSE_RECUE, REUSSIE, REPONSE_INCONNUE, RECONCILIATION_EN_COURS, ECHEC_CONFIRME, A_REVOIR_MANUELLEMENT, ANNULEE |
CREE |
tentative_backend.statut |
ENVOYEE, REPONSE_RECUE, TIMEOUT, ECHEC_RESEAU |
ENVOYEE |
transaction_event.type_evenement |
CREE, ENVOYEE, REPONSE_RECUE, TIMEOUT, RECONCILIATION_DEMARREE, RECONCILIATION_CONFIRMEE, ECHEC_CONFIRME, COMPLETEE, ANNULEE |
— |
site.type_site |
AGENCE, HORS_AGENCE, CENTRE_COMMERCIAL, AUTRE |
AGENCE |
borne.statut |
EN_SERVICE, MODE_DEGRADE, HORS_SERVICE, MAINTENANCE |
EN_SERVICE |
action_telegestion.type_action |
REDEMARRAGE, MISE_A_JOUR_APPLICATIVE, VERROUILLAGE, DEVERROUILLAGE, DIAGNOSTIC_DISTANT |
— |
action_telegestion.statut |
DEMANDEE, EN_COURS, REUSSIE, ECHOUEE |
DEMANDEE |
peripherique.statut |
OPERATIONNEL, PANNE, CONSOMMABLE_BAS, INCONNU |
INCONNU |
service.statut |
BROUILLON, ACTIF, SUSPENDU, OBSOLETE |
BROUILLON |
service.criticite |
CRITIQUE, MAJEUR, MINEUR |
NULL |
borne_service.source |
DIRECT, PROFIL |
PROFIL |
borne_service.statut_affectation |
AVAILABLE, DEGRADED, UNAVAILABLE |
AVAILABLE |
service_peripherique.niveau_dependance |
OBLIGATOIRE, OPTIONNEL, REQUIS_SELON_PARCOURS, RECOMMANDE, CONDITIONNEL |
— |
incident.type_incident |
SEUIL_SYSTEME, PERIPHERIQUE_PANNE, BORNE_HORS_SERVICE, ECHEC_ROUTAGE, AUTRE |
— |
incident.severite |
P1_CRITIQUE, P2_MAJEUR, P3_MINEUR |
— |
incident.statut |
OUVERT, EN_COURS, RESOLU, FERME |
OUVERT |
Generate these as constants/enums in the application from a single source (ideally a test that diffs app enums against pg_constraint definitions).
8. Lifecycles & state machines
8.1 Transaction status
stateDiagram-v2
[*] --> CREE : request received
CREE --> ROUTEE : rule resolved
CREE --> ANNULEE : no applicable rule / kiosk refused (to confirm)
ROUTEE --> REPONSE_RECUE : backend answered
ROUTEE --> REPONSE_INCONNUE : TIMEOUT / ECHEC_RESEAU
REPONSE_RECUE --> REUSSIE : processing confirmed
REPONSE_RECUE --> ECHEC_CONFIRME : backend refusal (to confirm)
REPONSE_INCONNUE --> RECONCILIATION_EN_COURS : job picks it up
RECONCILIATION_EN_COURS --> REUSSIE : backend confirms done
RECONCILIATION_EN_COURS --> ECHEC_CONFIRME : backend confirms not done
RECONCILIATION_EN_COURS --> RECONCILIATION_EN_COURS : still unknown, reschedule
RECONCILIATION_EN_COURS --> A_REVOIR_MANUELLEMENT : max cycles / delay exceeded
A_REVOIR_MANUELLEMENT --> REUSSIE : operator decision
A_REVOIR_MANUELLEMENT --> ECHEC_CONFIRME : operator decision
REUSSIE --> [*]
ECHEC_CONFIRME --> [*]
ANNULEE --> [*]
Golden rule: a timeout is never a failure. TIMEOUT → REPONSE_INCONNUE → reconciliation. No automatic resend to the other backend unless transaction.eligible_failover_inter_backend = true and nothing was sent yet.
8.2 Step-by-step write sequence
sequenceDiagram
autonumber
participant K as Borne
participant R as KMS-Routeur
participant DB as PostgreSQL
participant B as Backend (QUBIT / KALISPOT)
participant J as Job réconciliation
K->>R: request (idempotency_key, payload)
R->>DB: INSERT transaction (CREE) + INSERT event CREE
Note over R,DB: ON CONFLICT (id_borne, idempotency_key) → replay / reject
R->>DB: resolve regle_routage
R->>DB: UPDATE transaction → ROUTEE (regle, backend, failover flag)
R->>DB: INSERT tentative_backend (ENVOYEE) + event ENVOYEE
R->>B: call
alt response received
B-->>R: response
R->>DB: UPDATE tentative → REPONSE_RECUE + event REPONSE_RECUE
R->>DB: UPDATE transaction → REPONSE_RECUE → REUSSIE, cloture + event COMPLETEE
R-->>K: result
else timeout / network error
R->>DB: UPDATE tentative → TIMEOUT | ECHEC_RESEAU + event TIMEOUT
R->>DB: UPDATE transaction → REPONSE_INCONNUE, prochaine_reconciliation_a
R-->>K: pending / unknown
J->>DB: pick due rows (FOR UPDATE SKIP LOCKED)
J->>DB: event RECONCILIATION_DEMARREE, nb_tentatives_reconciliation++
J->>B: status inquiry (never replay)
J->>DB: event RECONCILIATION_CONFIRMEE + final status + COMPLETEE
end
| Step |
transaction.statut |
tentative_backend.statut |
transaction_event.type_evenement |
| Request received |
CREE |
— |
CREE |
| Rule resolved |
ROUTEE |
— |
(none — §12) |
| Call sent |
ROUTEE |
ENVOYEE |
ENVOYEE |
| Response received |
REPONSE_RECUE → REUSSIE |
REPONSE_RECUE |
REPONSE_RECUE |
| Timeout / network error |
REPONSE_INCONNUE |
TIMEOUT / ECHEC_RESEAU |
TIMEOUT |
| Reconciliation start |
RECONCILIATION_EN_COURS |
— |
RECONCILIATION_DEMARREE |
| Reconciliation outcome |
REUSSIE / ECHEC_CONFIRME |
— |
RECONCILIATION_CONFIRMEE (+ ECHEC_CONFIRME) |
| Manual review |
A_REVOIR_MANUELLEMENT |
— |
(none — §12) |
| Closure |
final + horodatage_cloture |
— |
COMPLETEE / ANNULEE |
Every status change and its event row are written in the same DB transaction.
8.3 Remote action (action_telegestion)
stateDiagram-v2
[*] --> DEMANDEE
DEMANDEE --> EN_COURS : kiosk acknowledges (horodatage_execution)
EN_COURS --> REUSSIE
EN_COURS --> ECHOUEE
REUSSIE --> [*]
ECHOUEE --> [*]
8.4 Incident
stateDiagram-v2
[*] --> OUVERT
OUVERT --> EN_COURS
EN_COURS --> RESOLU : set date_resolution
RESOLU --> FERME
RESOLU --> EN_COURS : reopened (to confirm)
FERME --> [*]
8.5 Peripheral status → service availability
flowchart LR
HB[Heartbeat / diagnostic / manual] --> U[UPDATE parc.peripherique.statut]
U --> H[INSERT historique_statut_peripherique]
U --> C{Recompute borne_service\nfor this borne}
C -->|OBLIGATOIRE type down| UN[UNAVAILABLE]
C -->|other dependency down| DG[DEGRADED]
C -->|all OK| AV[AVAILABLE]
UN --> BL{service.bloquant?}
BL -->|yes| BD[borne.statut = MODE_DEGRADE]
UN --> INC[optionally open incident PERIPHERIQUE_PANNE]
9. Integrity rules — who enforces what
| ID |
Rule |
Enforced by |
How |
| KMS-DATA-001 |
transaction_event append-only |
DB |
GRANT SELECT, INSERT only |
| KMS-DATA-002 |
Same (id_borne, idempotency_key) with different payload_hash → reject |
App (+ DB unique index) |
Compare hash on conflict, return 409/422 |
| KMS-DATA-003 |
No inter-backend failover by default |
App |
Read frozen transaction.eligible_failover_inter_backend; never fail over after ENVOYEE |
| KMS-DATA-004 |
No PAN / PIN / amount stored |
Review + tests |
Schema lint in CI; no such columns; scrub logs |
| KMS-DATA-005 |
Kiosk → bank → backend via FKs only |
DB |
borne.id_banque, banque_cliente.id_backend_reference NOT NULL |
| KMS-DATA-006 |
poids_pct of a concurrent rule group sums to 100 |
App / trigger |
Validate on rule activation (group definition pending — §12) |
| KMS-DATA-007 |
Applied rule is traceable |
App |
Always set id_regle_appliquee; never edit a rule in place — create new version |
| KMS-DATA-008 |
OBLIGATOIRE dependency down → UNAVAILABLE; optional → DEGRADED |
App |
§11.5 |
| KMS-DATA-009 |
OBSOLETE service cannot be newly assigned |
App / trigger |
Not in DDL — add a BEFORE INSERT trigger on borne_service |
| KMS-DATA-010 |
historique_statut_peripherique append-only |
DB |
GRANT SELECT, INSERT only (grant not yet scripted — §12) |
| — |
borne_service.source ⇔ id_profil_service_origine |
DB |
Table CHECK |
| — |
montant_min <= montant_max |
DB |
Table CHECK |
| — |
Idempotency (id_borne, idempotency_key) |
DB |
ux_transaction_idempotency |
10. Access rights, partitioning, retention
10.1 Role matrix
| Object |
svc_kms_routeur |
svc_kms_supervision |
svc_noc_admin |
routage.transaction |
S I U |
— |
full |
routage.tentative_backend |
S I U |
— |
full |
routage.transaction_event |
S I (no U/D) |
— |
S I (no U/D recommended) |
routage.backend_bancaire, banque_cliente, regle_routage |
S |
— |
S I U |
service.borne_service |
— |
S I U |
full |
service.service, categorie_service, profil_service, service_peripherique, regle_impact_sla |
— |
S |
S I U |
parc.*, ops.incident |
not specified |
not specified |
full |
S = SELECT · I = INSERT · U = UPDATE
Grants the source omits but the app will need (proposed):
GRANT USAGE ON SCHEMA routage, parc, ops TO svc_kms_routeur;
GRANT USAGE ON SCHEMA service, parc TO svc_kms_supervision;
-- BIGSERIAL inserts fail without sequence usage
GRANT USAGE ON SEQUENCE routage.tentative_backend_id_tentative_seq,
routage.transaction_event_id_event_seq
TO svc_kms_routeur;
-- Router must identify the kiosk and may open routing incidents
GRANT SELECT ON parc.borne TO svc_kms_routeur;
GRANT SELECT, INSERT, UPDATE ON ops.incident TO svc_kms_routeur; -- to confirm
-- KMS-DATA-010
GRANT SELECT, UPDATE ON parc.peripherique TO svc_kms_supervision;
GRANT SELECT, INSERT ON parc.historique_statut_peripherique TO svc_kms_supervision;
GRANT USAGE ON SEQUENCE parc.historique_statut_peripherique_id_historique_seq TO svc_kms_supervision;
GRANT SELECT ON parc.borne, parc.type_peripherique TO svc_kms_supervision;
10.2 Partitioning & retention
| Table |
Partition key |
Granularity |
Retention |
Purge |
routage.tentative_backend |
horodatage_emission |
monthly |
≥ 5 years (to confirm per bank compliance) |
DETACH PARTITION only |
routage.transaction_event |
horodatage_evenement |
monthly |
≥ 5 years (to confirm) |
DETACH PARTITION only |
parc.historique_statut_peripherique |
horodatage |
monthly |
≥ 1 year (to confirm with ops) |
DETACH PARTITION only |
routage.transaction |
— (not partitioned) |
— |
aligned with events |
— |
- Each partitioned table has a
DEFAULT partition as a safety net. Rows landing in DEFAULT = alert: it means the monthly partition job did not run.
- Automate future partitions with
pg_partman or a scheduled job (create M+1, M+2 ahead).
- Never purge row by row.
10.3 Indexes in the DDL
| Index |
Table |
Columns |
Purpose |
ux_transaction_idempotency (unique) |
transaction |
(id_borne, idempotency_key) |
Idempotency |
ix_transaction_correlation |
transaction |
correlation_id |
Support / cross-system lookup |
ix_transaction_statut |
transaction |
statut |
|
ix_transaction_incident |
transaction |
id_incident |
|
ix_transaction_reconciliation (partial) |
transaction |
prochaine_reconciliation_a WHERE statut IN (REPONSE_INCONNUE,RECONCILIATION_EN_COURS) |
Reconciliation queue |
ix_tentative_transaction |
tentative_backend |
id_transaction |
|
ix_tentative_backend |
tentative_backend |
id_backend |
|
ix_event_transaction |
transaction_event |
id_transaction |
|
ix_regle_banque, ix_regle_backend_cible, ix_regle_active |
regle_routage |
FK / (active, environnement) |
Rule resolution |
ix_borne_site, _statut, _banque, _profil |
borne |
|
|
ix_telegestion_borne, _statut |
action_telegestion |
|
|
ix_peripherique_borne, _type, _statut |
peripherique |
|
|
ix_historique_statut_peripherique |
historique_statut_peripherique |
(id_peripherique, horodatage DESC) |
Latest-first history |
ix_incident_borne, _statut |
incident |
|
|
ix_service_categorie, _statut |
service |
|
|
Missing FK indexes worth adding (avoid seq scans on joins and parent-row locks):
CREATE INDEX ix_transaction_regle ON routage.transaction (id_regle_appliquee);
CREATE INDEX ix_transaction_backend ON routage.transaction (id_backend_retenu);
CREATE INDEX ix_banque_backend ON routage.banque_cliente (id_backend_reference);
CREATE INDEX ix_borne_service_svc ON service.borne_service (id_service);
CREATE INDEX ix_svc_periph_type ON service.service_peripherique (id_type_peripherique);
CREATE INDEX ix_psi_service ON service.profil_service_item (id_service);
CREATE INDEX ix_regle_sla_service ON service.regle_impact_sla (id_service);
11. Developer patterns (SQL)
11.1 Idempotent transaction creation
BEGIN;
INSERT INTO routage.transaction
(id_borne, correlation_id, type_operation, idempotency_key, payload_hash)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (id_borne, idempotency_key) DO NOTHING
RETURNING id_transaction;
-- If a row was returned → new transaction:
INSERT INTO routage.transaction_event
(id_transaction, type_evenement, statut_snapshot, payload_hash, acteur)
VALUES ($id, 'CREE', 'CREE', $5, 'kms-routeur');
COMMIT;
If no row is returned, it is a replay:
SELECT id_transaction, payload_hash, statut
FROM routage.transaction
WHERE id_borne = $1 AND idempotency_key = $4;
payload_hash differs → reject (KMS-DATA-002), do not touch the row.
payload_hash equal → return the stored outcome / current status; do not call the backend again.
11.2 Routing rule resolution
SELECT r.id_regle, r.id_backend_cible, r.eligible_failover_inter_backend, r.poids_pct
FROM routage.regle_routage r
WHERE r.environnement = $env
AND r.active
AND r.valid_from <= now()
AND (r.valid_to IS NULL OR r.valid_to > now())
AND (r.id_banque_critere IS NULL OR r.id_banque_critere = $id_banque)
AND (r.critere_type_operation IS NULL OR r.critere_type_operation = $type_operation)
AND (r.critere_canal IS NULL OR r.critere_canal = $canal)
AND (r.montant_min IS NULL OR $montant >= r.montant_min)
AND (r.montant_max IS NULL OR $montant <= r.montant_max)
ORDER BY r.priorite
LIMIT 1;
Then, in the application:
- Check
backend_bancaire.actif and etat_circuit <> 'OUVERT' for the target.
- Compute the frozen failover flag — recommended:
rule.eligible_failover_inter_backend AND banque_cliente.eligible_failover_inter_backend (see §12).
UPDATE transaction SET statut='ROUTEE', id_regle_appliquee, id_backend_retenu, eligible_failover_inter_backend.
Cache rules in memory with a short TTL; invalidate on admin change.
11.3 Recording an attempt
BEGIN;
INSERT INTO routage.tentative_backend (id_transaction, id_backend, numero_tentative)
VALUES ($tx, $backend,
(SELECT coalesce(max(numero_tentative), 0) + 1
FROM routage.tentative_backend WHERE id_transaction = $tx))
RETURNING id_tentative, horodatage_emission;
INSERT INTO routage.transaction_event (id_transaction, type_evenement, statut_snapshot, payload_hash, acteur)
VALUES ($tx, 'ENVOYEE', 'ROUTEE', $hash, 'kms-routeur');
COMMIT;
Update an attempt using both PK columns so the planner prunes to one partition:
UPDATE routage.tentative_backend
SET statut = 'REPONSE_RECUE', code_retour_backend = $code,
horodatage_reponse = now(), duree_traitement_ms = $ms
WHERE id_tentative = $id AND horodatage_emission = $ts;
11.4 Reconciliation worker queue
SELECT id_transaction
FROM routage.transaction
WHERE statut IN ('REPONSE_INCONNUE', 'RECONCILIATION_EN_COURS')
AND prochaine_reconciliation_a <= now()
ORDER BY prochaine_reconciliation_a
LIMIT 50
FOR UPDATE SKIP LOCKED;
The WHERE matches the partial index predicate exactly — keep it that way. Multiple workers can run in parallel safely thanks to SKIP LOCKED.
11.5 Peripheral update + service availability
BEGIN;
SELECT statut FROM parc.peripherique WHERE id_peripherique = $p FOR UPDATE; -- → $prev
-- only if the status actually changed:
UPDATE parc.peripherique
SET statut = $new, code_erreur = $err, date_dernier_changement_statut = now()
WHERE id_peripherique = $p;
INSERT INTO parc.historique_statut_peripherique
(id_peripherique, statut_precedent, statut_nouveau, code_erreur, source)
VALUES ($p, $prev, $new, $err, 'HEARTBEAT');
COMMIT;
Recompute availability for the kiosk (a type is "OK" if at least one peripheral of that type is usable):
WITH dep AS (
SELECT bs.id_borne, bs.id_service, sp.niveau_dependance,
coalesce(bool_or(p.statut IN ('OPERATIONNEL','CONSOMMABLE_BAS')), false) AS type_ok
FROM service.borne_service bs
JOIN service.service_peripherique sp ON sp.id_service = bs.id_service
LEFT JOIN parc.peripherique p
ON p.id_borne = bs.id_borne
AND p.id_type_peripherique = sp.id_type_peripherique
WHERE bs.id_borne = $borne
GROUP BY bs.id_borne, bs.id_service, sp.niveau_dependance, sp.id_type_peripherique
)
SELECT id_borne, id_service,
CASE
WHEN bool_or(niveau_dependance = 'OBLIGATOIRE' AND NOT type_ok) THEN 'UNAVAILABLE'
WHEN bool_or(NOT type_ok) THEN 'DEGRADED'
ELSE 'AVAILABLE'
END AS statut_calcule
FROM dep
GROUP BY id_borne, id_service;
Assumptions to validate with the business: INCONNU counts as not OK; services with no declared dependency stay AVAILABLE; REGLE_IMPACT_SLA expressions, when defined, override this default logic.
11.6 Support: full trace of a transaction
SELECT t.*, b.code AS backend, r.priorite, r.version AS regle_version
FROM routage.transaction t
LEFT JOIN routage.backend_bancaire b ON b.id_backend = t.id_backend_retenu
LEFT JOIN routage.regle_routage r ON r.id_regle = t.id_regle_appliquee
WHERE t.correlation_id = $corr;
SELECT * FROM routage.tentative_backend WHERE id_transaction = $tx ORDER BY numero_tentative;
SELECT * FROM routage.transaction_event WHERE id_transaction = $tx ORDER BY horodatage_evenement, id_event;
Add a time bound (horodatage_* >= t.horodatage_creation) to benefit from partition pruning on large volumes.
12. Known discrepancies & open points
Found while reviewing source v3.0. Items marked 🔴 will break code or tests if ignored.
Naming / DDL vs dictionary
| # |
Sev. |
Issue |
Guide decision |
| D1 |
🔴 |
transaction.statut: dictionary says CREEE (default + CHECK), DDL and lifecycle say CREE |
Use CREE; fix the dictionary |
| D2 |
🔴 |
transaction_event timestamp: dictionary horodatage_event, DDL horodatage_evenement |
Use horodatage_evenement |
| D3 |
🔴 |
service.code is UNIQUE alone while service is versioned → a 2nd version with the same code is impossible |
Change to UNIQUE (code, version) (as profil_configuration), or keep one row and log versions elsewhere — decision needed |
| D4 |
🔴 |
No GRANT USAGE on schemas nor on BIGSERIAL sequences → app inserts fail |
Add grants (§10.1) |
| D5 |
🟠 |
Grants for historique_statut_peripherique (KMS-DATA-010) and svc_kms_supervision described in text but not scripted |
Add to migration |
Model
| # |
Sev. |
Issue |
Proposal |
| M1 |
🟠 |
FK transaction.id_backend_retenu has no MCD association (23 listed, this one missing) |
Add association e.g. RETENIR |
| M2 |
🟠 |
MCD cardinality table mixes conventions (e.g. AFFILIER written BORNE (0,n) / BANQUE (1,1), i.e. swapped vs Merise convention, while CIBLER/SOLLICITER follow it) |
Use the FK matrix in §6 as reference; harmonise source |
| M3 |
🟠 |
UNIQUE (priorite, environnement) conflicts with (a) rule versioning — a new version at the same priority cannot coexist with the old row; (b) weighted A/B groups (poids_pct) — "group of concurrent rules" is undefined if priorities are unique |
Define a groupe_regle / rule-lineage id; make uniqueness partial (WHERE active) or include version |
| M4 |
🟠 |
Rules filter on montant_min/max, but the amount is deliberately not stored → impossible to re-prove why a rule matched |
Store an amount bucket or the match result, or drop amount criteria |
| M5 |
🟠 |
Source of transaction.eligible_failover_inter_backend (rule? bank? both?) not specified |
Recommend rule AND bank |
| M6 |
🟠 |
No event type for ROUTEE nor A_REVOIR_MANUELLEMENT → routing decision and manual-review transition are not in the immutable journal (contradicts §2.1 traceability) |
Add ROUTEE, A_REVOIR (and ECHEC_RESEAU) to type_evenement |
| M7 |
🟡 |
Backend explicit refusal (response received, operation declined) → target status not described |
Confirm REPONSE_RECUE → ECHEC_CONFIRME |
| M8 |
🟡 |
No-rule case: transaction "stays" CREE with no exit |
Define terminal path (ANNULEE + incident ECHEC_ROUTAGE?) |
| M9 |
🟡 |
(id_transaction, numero_tentative) not unique; a global unique index on a partitioned table must include the partition key |
Enforce in app (§11.3) or accept |
| M10 |
🟡 |
KMS-DATA-008 only defines OBLIGATOIRE and OPTIONNEL; REQUIS_SELON_PARCOURS, RECOMMANDE, CONDITIONNEL have no behaviour; "OPTIONNEL" vs "OPTIONNELLE" |
Specify each level |
| M11 |
🟡 |
regle_impact_sla.expression JSONB format unspecified |
Publish a JSON Schema before implementation |
| M12 |
🟡 |
KMS-DATA-009 (OBSOLETE not assignable) not enforced in DDL |
Trigger on borne_service |
| M13 |
🟡 |
historique_statut_peripherique.statut_nouveau/precedent have no CHECK |
Add same CHECK as peripherique.statut |
| M14 |
🟡 |
updated_at columns are not maintained automatically |
Add a generic BEFORE UPDATE trigger |
| M15 |
🟡 |
Two "profile" concepts (profil_configuration = technical params, profil_service = service bundle) |
Name them distinctly in code: ConfigProfile vs ServiceProfile |
| M16 |
🟡 |
service.bloquant → kiosk MODE_DEGRADE: who writes borne.statut? Supervision vs heartbeat ownership unclear |
Define a single writer |
| M17 |
🟡 |
Glossary says append-only is "reserved to transaction_event" — outdated since v3.0 (historique_statut_peripherique) |
Update glossary |
| M18 |
⚪ |
MCD/MLD diagrams in source still v2.0 (10 entities) |
§4 of this guide covers all 21 |
13. Glossary FR → EN
| FR identifier |
EN meaning |
| borne |
kiosk / self-service terminal |
| banque cliente |
client bank |
| backend bancaire |
banking backend (core banking adapter) |
| règle de routage |
routing rule |
| tentative |
attempt (one backend call) |
| réconciliation |
reconciliation (status inquiry after unknown outcome) |
| télégestion |
remote management |
| périphérique |
peripheral / device |
| site |
site / location |
| profil de configuration |
configuration profile (technical) |
| profil de services |
service profile (bundle of services) |
| affectation |
assignment |
| dépendance |
dependency |
| incident / sévérité |
incident / severity |
| horodatage |
timestamp |
| statut |
status |
| actif / active |
active (soft-enable flag) |
| en ajout seul |
append-only |
| basculement inter-backend |
inter-backend failover |
| disjoncteur (etat_circuit) |
circuit breaker state: FERME = closed, OUVERT = open, SEMI_OUVERT = half-open |