Skip to content

Fix db_ddl.sql: align with authoritative openas2-schema.xml#538

Merged
uhurusurfa merged 1 commit into
OpenAS2:masterfrom
ricardopsj:fix/db_ddl_align_with_schema
Jun 15, 2026
Merged

Fix db_ddl.sql: align with authoritative openas2-schema.xml#538
uhurusurfa merged 1 commit into
OpenAS2:masterfrom
ricardopsj:fix/db_ddl_align_with_schema

Conversation

@ricardopsj

Copy link
Copy Markdown
Contributor

Summary

Aligns Server/src/config/db_ddl.sql with the authoritative schema in Server/src/resources/db/openas2-schema.xml. The two had drifted: most notably, db_ddl.sql was missing the SENT_FILE_NAME column that DbTrackingModule writes on every outbound, plus several other smaller divergences (column types, defaults).

Fixes the bug described in #537 (created alongside this PR).

What's in the change

  • SENT_FILE_NAME VARCHAR(255) added immediately after FILE_NAME (same position as in the XML).
  • MSG_ID, PRIOR_MSG_ID, MDN_ID, MDN_RESPONSE, STATE_MSG promoted from unbounded VARCHAR to LONGVARCHAR, matching the XML.
  • Column defaults added so the SQL matches the XML's behavior on fresh installs:
    • IS_RESEND DEFAULT 'N'
    • RESEND_COUNT DEFAULT 0
    • CREATE_DT DEFAULT CURRENT_TIMESTAMP
  • Header comment added pointing maintainers at openas2-schema.xml as the single source of truth, so the two files don't drift again.
  • Server/src/test/resources/config/db_ddl.sql mirrored with the same content to keep the test fixture aligned.

Why this matters

create_db_table.sh (the "official" bootstrap path) needs Apache Ant on the host and TCP 9092 open on the H2 server. Hardened deployments routinely:

  • skip ant (not on the runtime image), and
  • set tcp_server_start="false" in DbTrackingModule so H2 stays in embedded/file mode (no exposed 9092).

In those deployments the only viable bootstrap is to apply db_ddl.sql directly via org.h2.tools.RunScript against the embedded .mv.db file. That's the path this PR fixes.

Backwards compatibility

  • Pure additive on the schema (one new column, defaults on existing columns, type widenings). No data migration needed for fresh installs.
  • For existing installs that already created the table from the old db_ddl.sql and want to upgrade in place:
    ALTER TABLE msg_metadata ADD COLUMN sent_file_name VARCHAR(255);
    (DbTrackingModule inserts will work after this even without restarting.)

How this was tested

  • Bootstrapped a fresh H2 file with the new db_ddl.sql using org.h2.tools.RunScript on Debian 13 + OpenJDK 21.
  • Sent an outbound message; DbTrackingModule wrote a complete row including sent_file_name.
  • Smoke test repeated on a second independent deployment (same OS/JDK stack), same result.

Notes for reviewers

  • The XML schema (openas2-schema.xml) remains the source of truth; this PR just brings the convenience SQL up to date with it.
  • A follow-up could consider auto-generating db_ddl.sql from the XML at build time so they cannot drift again. Out of scope for this PR — happy to do it as a second PR if maintainers prefer.

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).

@uhurusurfa uhurusurfa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes.
The next release for OpenAS2 will be a major release using Hibernate to manage the schema so the use of DDL utils and the XML schema will soon be dropped.

@uhurusurfa uhurusurfa merged commit 980faba into OpenAS2:master Jun 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants