Skip to main content

SQL Audit Store

The SQL audit store (SqlAuditStore) enables Flamingock to record execution history and ensure safe coordination across distributed deployments using any supported SQL database as the storage backend.

For a conceptual explanation of the audit store vs target systems, see Audit store vs target system.

Supported databases

Automatic Dialect Detection

Flamingock automatically detects the database vendor from the DataSource connection metadata and applies the appropriate SQL dialect. No manual configuration required.

The following databases are supported:

DatabaseAuto-detectionNotes
MySQL5.7+ recommended
MariaDB10.3+ recommended
PostgreSQL12+ recommended
SQLiteSuitable for testing and local development
H2Ideal for testing environments
SQL Server2017+ recommended
Oracle19c+ recommended
SybaseASE 16+ recommended
Firebird3.0+ recommended
Informix12.10+ recommended
DB211.5+ recommended

Installation

Add your preferred JDBC driver dependency to your project:

// PostgreSQL example
implementation("org.postgresql:postgresql:42.7.0")

// MySQL example
implementation("mysql:mysql-connector-java:8.0.33")

Basic setup

Configure the audit store:

var auditStore = new SqlAuditStore(dataSource);

The constructor requires a DataSource. Optional configurations can be added via .withXXX() methods.

Register Audit Store

Once created, you need to register this audit store with Flamingock. See Registering the community audit store for details.

Audit Store configuration

The SQL audit store uses explicit configuration with no global context fallback.

Constructor dependencies (mandatory)

These dependencies must be provided at audit store creation time with no global context fallback:

DependencyConstructor ParameterDescription
javax.sql.DataSourcedataSourceSQL database connection pool - required for audit store configuration

Optional configuration (.withXXX() methods)

These configurations can be customized via .withXXX() methods with no global context fallback:

ConfigurationMethodDefaultDescription
Auto Create.withAutoCreate(enabled)trueAuto-create tables and indexes
Audit Repository Name.withAuditRepositoryName(name)flamingockAuditLogTable name for audit entries
Lock Repository Name.withLockRepositoryName(name)flamingockLockTable name for distributed locks

Important: These default values are optimized for maximum consistency and should ideally be left unchanged. Override them only for testing purposes or exceptional cases.

Configuration example

Here's a comprehensive example showing the configuration:

// Audit store configuration (mandatory via constructor)
var auditStore = new SqlAuditStore(dataSource)
.withAutoCreate(true) // Optional configuration
.withAuditRepositoryName("custom_audit_log") // Optional configuration
.withLockRepositoryName("custom_lock_table"); // Optional configuration

// Register with Flamingock
Flamingock.builder()
.setAuditStore(auditStore)
.addTargetSystems(targetSystems...)
.build();

Audit store configuration resolution:

  • DataSource: Must be provided via constructor
  • Database dialect: Automatically detected from DataSource vendor
  • Table configurations: Uses explicit configuration instead of defaults

This architecture ensures explicit audit store configuration with no fallback dependencies.

Database-specific examples

PostgreSQL

// PostgreSQL DataSource configuration
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
config.setUsername("user");
config.setPassword("password");
config.setDriverClassName("org.postgresql.Driver");

DataSource dataSource = new HikariDataSource(config);
var auditStore = new SqlAuditStore(dataSource);

MySQL

// MySQL DataSource configuration
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/mydb");
config.setUsername("user");
config.setPassword("password");
config.setDriverClassName("com.mysql.cj.jdbc.Driver");

DataSource dataSource = new HikariDataSource(config);
var auditStore = new SqlAuditStore(dataSource);

Schema management

When autoCreate is enabled (default), Flamingock automatically creates the required tables:

  • Audit table (default: flamingockAuditLog): Stores execution history
  • Lock table (default: flamingockLock): Manages distributed locking

The SQL schemas are automatically optimized for each supported database dialect.

Database Permissions

Ensure your database user has CREATE TABLE and CREATE INDEX permissions when using autoCreate=true.

Next steps