Skip to content

Conversation

@Aaronontheweb
Copy link
Member

Summary

Adds a DDL generator tool and complete database schema documentation to address user feedback that DDL scripts were not available in the repository.

Changes

  • New DDL Generator Tool: Console application that generates provider-specific DDL scripts using schema introspection
  • DDL Documentation: Complete SQL scripts for SQL Server and PostgreSQL in docs/ddl/
  • Integration Tests: Validation tests that verify DDL executes successfully and is idempotent
  • Proper Table/Column Mapping: Uses AkkaPersistenceDataConnectionFactory to ensure generated DDL matches HOCON-configured names

Generated DDL Files

For SQL Server and PostgreSQL:

  • journal.sql - Event journal table with proper indexing
  • journal-tags.sql - Tag table for normalized tag storage (TagMode.TagTable)
  • snapshot.sql - Snapshot store table
  • metadata.sql - Metadata table for delete-compatibility-mode

All DDL includes:

  • ✅ Idempotent CREATE TABLE statements (IF NOT EXISTS checks)
  • ✅ Primary key constraints
  • ✅ Unique constraints
  • ✅ Performance indexes
  • ✅ Provider-specific SQL syntax

Test Results

All DdlValidationSpec tests passing:

  • SqlServer_DDL_Should_Execute_Successfully
  • SqlServer_DDL_Should_Be_Idempotent
  • PostgreSQL_DDL_Should_Execute_Successfully
  • PostgreSQL_DDL_Should_Be_Idempotent

Remaining Work (Draft Status)

This PR is marked as draft because:

  • MySQL DDL generation not yet complete
  • SQLite DDL generation not yet complete
  • Comprehensive README documentation for docs/ddl/ needed
  • Main README.md update with DDL documentation links needed

The core functionality is working and validated for SQL Server and PostgreSQL. Will complete remaining providers and documentation before marking ready for review.

Created a new Akka.Persistence.Sql.DdlGenerator console application that generates
provider-specific DDL scripts for all supported databases (SQL Server, PostgreSQL,
MySQL, SQLite). The tool captures constraint and index creation SQL with proper
error handling for idempotent execution.

Key features:
- Generates DDL for journal, snapshot, metadata, and tag tables
- Provider-specific constraint and index syntax
- Error handling for existing objects (IF NOT EXISTS checks)
- Uses test containers to generate actual provider DDL
- Command-line interface with --all and --provider options

Generated DDL files are stored in docs/ddl/{provider}/ directories and include:
- journal.sql: Event journal constraints and indexes
- journal-tags.sql: Tag table indexes
- snapshot.sql: Snapshot store constraints and indexes
- metadata.sql: Compatibility mode metadata table

Note: The tool captures constraint and index DDL but not CREATE TABLE statements
due to Linq2Db's table creation mechanism. Table structures are defined by the
C# entity classes in the codebase (JournalRow, SnapshotRow, etc.).

This addresses user feedback requesting documented DDL for manual database setup
and provides foundation for future integration tests validating schema currency.
…ency

This commit fixes the DDL generator to produce correct, idempotent SQL scripts
for SQL Server and PostgreSQL by integrating with AkkaPersistenceDataConnectionFactory
for proper table and column name mappings.

Changes:
- Integrated AkkaPersistenceDataConnectionFactory to apply HOCON-configured table/column mappings
- Added IF NOT EXISTS checks to make DDL idempotent (PostgreSQL: CREATE TABLE IF NOT EXISTS, SQL Server: IF NOT EXISTS wrapper)
- Fixed metadata table generation by enabling delete-compatibility-mode when needed
- Added explicit table name parameters to schema introspection for accurate matching
- Regenerated all DDL files with correct table names (event_journal, EventJournal, etc.)
- Added DdlValidationSpec integration tests to verify DDL execution and idempotency

All validation tests pass:
- SqlServer_DDL_Should_Execute_Successfully
- SqlServer_DDL_Should_Be_Idempotent
- PostgreSQL_DDL_Should_Execute_Successfully
- PostgreSQL_DDL_Should_Be_Idempotent
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.

1 participant