From e75acc0a14786c9d0585b4565850d6cffdb84169 Mon Sep 17 00:00:00 2001 From: "ICB (Ferrero 3PL project)" Date: Sun, 14 Jun 2026 21:10:33 +0000 Subject: [PATCH] Fix db_ddl.sql: align with authoritative openas2-schema.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DDL Utils schema at Server/src/resources/db/openas2-schema.xml has been the source of truth for the msg_metadata table since the schema was introduced, but the SQL script in Server/src/config/db_ddl.sql has not been kept in sync. The most impactful gap is a missing SENT_FILE_NAME column, which DbTrackingModule writes to but is absent from the table created via this DDL — breaking any deployment that bootstraps the H2 schema with this file instead of the ant-based create_db_table.sh route. This commit aligns db_ddl.sql with openas2-schema.xml: * Adds SENT_FILE_NAME VARCHAR(255) immediately after FILE_NAME (matches the position in the XML and the order used by DbTrackingModule inserts). * Promotes MSG_ID, PRIOR_MSG_ID, MDN_ID, MDN_RESPONSE and STATE_MSG from unbounded VARCHAR to LONGVARCHAR, mirroring the XML. * Applies the column defaults declared in the XML: - IS_RESEND DEFAULT 'N' - RESEND_COUNT DEFAULT 0 - CREATE_DT DEFAULT CURRENT_TIMESTAMP * Adds an explicit reminder comment so the two files do not drift again. The same fix is mirrored in Server/src/test/resources/config/db_ddl.sql to keep the test fixture aligned. This was field-validated in two independent deployments running OpenAS2 v4.8.2 on Debian 13 + OpenJDK 21 with embedded H2 and tcp_server_start="false" (where create_db_table.sh is not usable because it relies on ant + a TCP 9092 listener that the deployments intentionally do not enable). --- Server/src/config/db_ddl.sql | 33 +++++++++++---------- Server/src/test/resources/config/db_ddl.sql | 33 +++++++++++---------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Server/src/config/db_ddl.sql b/Server/src/config/db_ddl.sql index 027dee730..c6df5edf5 100644 --- a/Server/src/config/db_ddl.sql +++ b/Server/src/config/db_ddl.sql @@ -1,22 +1,25 @@ --- ----------------------------------------------------------------------- --- msg_metadata --- ----------------------------------------------------------------------- +-- ----------------------------------------------------------------------- +-- msg_metadata +-- ----------------------------------------------------------------------- +-- This DDL must stay aligned with the authoritative schema in +-- Server/src/resources/db/openas2-schema.xml. If you add/remove a column +-- here, mirror the change in the XML (and vice versa). DROP TABLE msg_metadata IF EXISTS; --- ----------------------------------------------------------------------- --- msg_metadata --- ----------------------------------------------------------------------- +-- ----------------------------------------------------------------------- +-- msg_metadata +-- ----------------------------------------------------------------------- CREATE TABLE msg_metadata ( ID INTEGER NOT NULL AUTO_INCREMENT, - MSG_ID VARCHAR NOT NULL, - PRIOR_MSG_ID VARCHAR, - MDN_ID VARCHAR, + MSG_ID LONGVARCHAR NOT NULL, + PRIOR_MSG_ID LONGVARCHAR, + MDN_ID LONGVARCHAR, DIRECTION VARCHAR(25), - IS_RESEND VARCHAR(1), - RESEND_COUNT INTEGER, + IS_RESEND VARCHAR(1) DEFAULT 'N', + RESEND_COUNT INTEGER DEFAULT 0, SENDER_ID VARCHAR(255) NOT NULL, RECEIVER_ID VARCHAR(255) NOT NULL, STATUS VARCHAR(255), @@ -25,15 +28,15 @@ CREATE TABLE msg_metadata ENCRYPTION_ALGORITHM VARCHAR(255), COMPRESSION VARCHAR(255), FILE_NAME VARCHAR(255), + SENT_FILE_NAME VARCHAR(255), CONTENT_TYPE VARCHAR(255), CONTENT_TRANSFER_ENCODING VARCHAR(255), MDN_MODE VARCHAR(255), - MDN_RESPONSE VARCHAR, - STATE_MSG VARCHAR, - CREATE_DT TIMESTAMP, + MDN_RESPONSE LONGVARCHAR, + STATE_MSG LONGVARCHAR, + CREATE_DT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UPDATE_DT TIMESTAMP, PRIMARY KEY (ID) ); CREATE UNIQUE INDEX MSG_ID_UNIQUE ON msg_metadata (MSG_ID); - diff --git a/Server/src/test/resources/config/db_ddl.sql b/Server/src/test/resources/config/db_ddl.sql index 027dee730..c6df5edf5 100644 --- a/Server/src/test/resources/config/db_ddl.sql +++ b/Server/src/test/resources/config/db_ddl.sql @@ -1,22 +1,25 @@ --- ----------------------------------------------------------------------- --- msg_metadata --- ----------------------------------------------------------------------- +-- ----------------------------------------------------------------------- +-- msg_metadata +-- ----------------------------------------------------------------------- +-- This DDL must stay aligned with the authoritative schema in +-- Server/src/resources/db/openas2-schema.xml. If you add/remove a column +-- here, mirror the change in the XML (and vice versa). DROP TABLE msg_metadata IF EXISTS; --- ----------------------------------------------------------------------- --- msg_metadata --- ----------------------------------------------------------------------- +-- ----------------------------------------------------------------------- +-- msg_metadata +-- ----------------------------------------------------------------------- CREATE TABLE msg_metadata ( ID INTEGER NOT NULL AUTO_INCREMENT, - MSG_ID VARCHAR NOT NULL, - PRIOR_MSG_ID VARCHAR, - MDN_ID VARCHAR, + MSG_ID LONGVARCHAR NOT NULL, + PRIOR_MSG_ID LONGVARCHAR, + MDN_ID LONGVARCHAR, DIRECTION VARCHAR(25), - IS_RESEND VARCHAR(1), - RESEND_COUNT INTEGER, + IS_RESEND VARCHAR(1) DEFAULT 'N', + RESEND_COUNT INTEGER DEFAULT 0, SENDER_ID VARCHAR(255) NOT NULL, RECEIVER_ID VARCHAR(255) NOT NULL, STATUS VARCHAR(255), @@ -25,15 +28,15 @@ CREATE TABLE msg_metadata ENCRYPTION_ALGORITHM VARCHAR(255), COMPRESSION VARCHAR(255), FILE_NAME VARCHAR(255), + SENT_FILE_NAME VARCHAR(255), CONTENT_TYPE VARCHAR(255), CONTENT_TRANSFER_ENCODING VARCHAR(255), MDN_MODE VARCHAR(255), - MDN_RESPONSE VARCHAR, - STATE_MSG VARCHAR, - CREATE_DT TIMESTAMP, + MDN_RESPONSE LONGVARCHAR, + STATE_MSG LONGVARCHAR, + CREATE_DT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UPDATE_DT TIMESTAMP, PRIMARY KEY (ID) ); CREATE UNIQUE INDEX MSG_ID_UNIQUE ON msg_metadata (MSG_ID); -