Skip to content

Conversation

@vadikko2
Copy link
Owner

Release Notes - python-cqrs 4.6.4

Summary

This release adds support for customizing saga storage table names through environment variables, providing better flexibility for multi-tenant deployments and service-specific naming conventions.

Added

Saga Storage Configuration

  • Environment Variable Support for Saga Table Names: Added support for customizing saga execution and log table names via environment variables, similar to the existing outbox table configuration.

    • CQRS_SAGA_EXECUTION_TABLE_NAME: Environment variable to customize the saga execution table name (default: "saga_executions")
    • CQRS_SAGA_LOG_TABLE_NAME: Environment variable to customize the saga log table name (default: "saga_logs")

    This enhancement allows different services or deployments to use service-specific table names (e.g., service_manager_saga_executions, payment_service_saga_executions) while maintaining the same codebase.

    Usage:

    # In .env file or environment variables
    export CQRS_SAGA_EXECUTION_TABLE_NAME=service_manager_saga_executions
    export CQRS_SAGA_LOG_TABLE_NAME=service_manager_saga_logs

    The table names are automatically loaded from environment variables when the cqrs.saga.storage.sqlalchemy module is imported, using python-dotenv for .env file support.

Technical Details

Changes in cqrs.saga.storage.sqlalchemy

  • Added os and dotenv imports
  • Added dotenv.load_dotenv() call to load environment variables from .env files
  • Modified DEFAULT_SAGA_EXECUTION_TABLE_NAME and DEFAULT_SAGA_LOG_TABLE_NAME to be read from environment variables with fallback to default values
  • Updated SagaExecutionModel and SagaLogModel to use the configurable table names
  • Updated ForeignKey reference in SagaLogModel to use the configurable execution table name

Backward Compatibility

  • Fully backward compatible: If environment variables are not set, the default table names (saga_executions and saga_logs) are used
  • No breaking changes: Existing code will continue to work without modifications
  • Optional feature: The feature is opt-in via environment variables

Migration Guide

For Existing Users

No migration required. The feature is backward compatible and uses default table names if environment variables are not set.

For New Users or Custom Table Names

  1. Set environment variables in your .env file or deployment configuration:

    CQRS_SAGA_EXECUTION_TABLE_NAME=your_custom_saga_executions
    CQRS_SAGA_LOG_TABLE_NAME=your_custom_saga_logs
  2. Ensure your database migration creates tables with the custom names:

    CREATE TABLE IF NOT EXISTS `your_custom_saga_executions` (
        -- table definition
    );
    
    CREATE TABLE IF NOT EXISTS `your_custom_saga_logs` (
        -- table definition
    );
  3. The SqlAlchemySagaStorage will automatically use the custom table names when initialized.

Examples

Example: Service-Specific Table Names

# .env file
CQRS_SAGA_EXECUTION_TABLE_NAME=service_manager_saga_executions
CQRS_SAGA_LOG_TABLE_NAME=service_manager_saga_logs

# Python code (no changes needed)
from cqrs.saga.storage.sqlalchemy import SqlAlchemySagaStorage

storage = SqlAlchemySagaStorage(session_factory)
# Automatically uses service_manager_saga_executions and service_manager_saga_logs

Related Issues

  • Enables service-specific saga table naming for multi-service deployments
  • Provides consistency with existing outbox table configuration pattern
  • Improves flexibility for database schema customization

@vadikko2 vadikko2 changed the title [Feature] [Feature] Support for customizing saga storage table names through environment variables Jan 27, 2026
@codspeed-hq
Copy link
Contributor

codspeed-hq bot commented Jan 27, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feature-add-saga-table-names-vars (aa10cb1) with master (a845305)

Summary

✅ 11 untouched benchmarks

@vadikko2 vadikko2 merged commit 88a410d into master Jan 27, 2026
8 checks passed
Copy link

@Azatic Azatic left a comment

Choose a reason for hiding this comment

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

q

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.

3 participants