Skip to content

feat(sql): add journal event persistence - #954

Open
bercianor wants to merge 1 commit into
masterfrom
feat/sql-journal-events
Open

feat(sql): add journal event persistence#954
bercianor wants to merge 1 commit into
masterfrom
feat/sql-journal-events

Conversation

@bercianor

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds SQL-backed “journal event” persistence to complement the existing SQL audit log, enabling stage-scoped journal streams while keeping the audit table as the current-state store. It also tightens SQL transaction session lifecycle handling and aligns the SQL external-system API with other transactional target systems.

Changes:

  • Introduces a SQL Journal Event store (schema helper + mapper) and journal-aware SQL audit persistence that appends journal events and updates current state in one transaction.
  • Refactors SqlAuditStore to provide stage-scoped persistence via getPersistenceFactory() and adds repository name validation (audit/lock/journal).
  • Updates SQL transaction wrapper session lifecycle (closeSession) and adds/extends tests covering journaling behavior and SQL transaction wrapper behavior.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/target-systems/flamingock-sql-targetsystem/src/test/java/io/flamingock/targetsystem/sql/SqlTxWrapperLifecycleTest.java New test coverage for SQL tx wrapper commit/rollback and session reuse.
core/target-systems/flamingock-sql-targetsystem/src/main/java/io/flamingock/targetsystem/sql/SqlTxWrapper.java Closes transaction sessions in a finally block to avoid reusing closed sessions.
core/target-systems/flamingock-sql-externalsystem-api/src/main/java/io/flamingock/externalsystem/sql/api/SqlExternalSystem.java Aligns SQL external system API with transactional external systems by exposing getTxWrapper().
core/target-systems/flamingock-sql-externalsystem-api/build.gradle.kts Adjusts dependencies to expose core-commons types to consumers of the external-system API.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/SqlAuditTestHelper.java Updates test schema helper to include the new journal table and adjusts dialect-specific DDL.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/SqlAuditStoreTest.java Adds tests validating journal-enabled behavior, repository naming rules, and feature-flag snapshot behavior.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/PipelineTestHelper.java Removes a local test helper (pipeline preview builder).
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/internal/SqlJournalEventStoreJdbcTest.java New JDBC tests for schema creation/validation, append/read/ack flows, and failure cases.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/internal/SqlJournalEventMapperTest.java New unit tests for journal event ↔ row mapping, including nullable handling and dialect null types.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/internal/SqlJournalDialectHelperTest.java New tests asserting portable schema generation and deterministic index naming across dialects.
community/flamingock-sql-auditstore/src/test/java/io/flamingock/store/sql/internal/SqlAuditPersistenceJournalTest.java New tests validating journal-enabled write ordering, rollback semantics, and sequencing guarantees.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/SqlAuditStore.java Refactors to stage-scoped persistence, adds journal store wiring, and validates repository naming.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlLockService.java Makes lock table initialization idempotent by checking existence before creating.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlJournalEventStore.java Adds the JDBC implementation of journal buffering + schema validation + acknowledgements.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlJournalEventMapper.java Adds binder/reader for journal event envelope + flattened audit payload.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlJournalDialectHelper.java Adds dialect-aware DDL/DML generation and index naming limits/strategy.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlAuditRepository.java New audit repository used for both append-only history and current-state replacement operations.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlAuditPersistence.java Journal-aware persistence: append event + update current state transactionally, confirm sequencer on success.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/SqlAuditor.java Removes legacy auditor implementation in favor of the new repository/mapper approach.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/JournalEventConstants.java Adds shared SQL identifier validation and journal naming constants.
community/flamingock-sql-auditstore/src/main/java/io/flamingock/store/sql/internal/AuditEntryMapper.java Adds typed binding/reading of AuditEntry for both audit and journal storage.
Suppressed comments (1)

core/target-systems/flamingock-sql-externalsystem-api/build.gradle.kts:8

  • The SQL external-system API Gradle script still declares an unused sqlVersion extra and carries over a DynamoDB-only compileOnly dependency. Since this module now only exposes SqlExternalSystem and already depends on :core:flamingock-core-commons, these leftovers are misleading and can fail configuration if the extra properties are not defined.
val coreApiVersion: String by extra
val sqlVersion: String by extra
dependencies {
    api(project(":core:flamingock-core-commons"))

    //General
    compileOnly("software.amazon.awssdk:dynamodb-enhanced:2.25.29")
}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +34 to +38
public SqlAuditRepository(DataSource dataSource, String auditTableName) {
JournalEventConstants.validateIdentifier(auditTableName, "auditTableName");
this.dataSource = dataSource;
this.auditTableName = auditTableName;
}
Comment on lines +145 to +149
public List<AuditEntry> getAuditHistory() {
List<AuditEntry> entries = new ArrayList<>();
try (Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(dialectHelper.getSelectHistorySqlString(auditTableName))) {
Comment on lines +56 to +60
public Result writeEntry(AuditEntry auditEntry) {
Connection conn = null;
try {
conn = dataSource.getConnection();

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