|
| 1 | +--- |
| 2 | +title: SQL |
| 3 | +sidebar_position: 3 |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +# SQL Audit Store |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +> For a conceptual explanation of the audit store vs target systems, see [Audit store vs target system](../../get-started/audit-store-vs-target-system.md). |
| 14 | +
|
| 15 | +## Supported databases |
| 16 | + |
| 17 | +:::info Automatic Dialect Detection |
| 18 | +Flamingock automatically detects the database vendor from the DataSource connection metadata and applies the appropriate SQL dialect. No manual configuration required. |
| 19 | +::: |
| 20 | + |
| 21 | +The following databases are supported: |
| 22 | + |
| 23 | +| Database | Auto-detection | Notes | |
| 24 | +|--------------|----------------|------------------------------------------| |
| 25 | +| MySQL | ✅ | 5.7+ recommended | |
| 26 | +| MariaDB | ✅ | 10.3+ recommended | |
| 27 | +| PostgreSQL | ✅ | 12+ recommended | |
| 28 | +| SQLite | ✅ | Suitable for testing and local development | |
| 29 | +| H2 | ✅ | Ideal for testing environments | |
| 30 | +| HSQLDB | ✅ | Testing and embedded scenarios | |
| 31 | +| SQL Server | ✅ | 2017+ recommended | |
| 32 | +| Oracle | ✅ | 19c+ recommended | |
| 33 | +| Sybase | ✅ | ASE 16+ recommended | |
| 34 | +| Firebird | ✅ | 3.0+ recommended | |
| 35 | +| Informix | ✅ | 12.10+ recommended | |
| 36 | +| DB2 | ✅ | 11.5+ recommended | |
| 37 | + |
| 38 | +## Installation |
| 39 | + |
| 40 | +Add your preferred JDBC driver dependency to your project: |
| 41 | + |
| 42 | +<Tabs groupId="gradle_maven"> |
| 43 | + <TabItem value="gradle" label="Gradle" default> |
| 44 | +```kotlin |
| 45 | +// PostgreSQL example |
| 46 | +implementation("org.postgresql:postgresql:42.7.0") |
| 47 | + |
| 48 | +// MySQL example |
| 49 | +implementation("mysql:mysql-connector-java:8.0.33") |
| 50 | + |
| 51 | +``` |
| 52 | + </TabItem> |
| 53 | + <TabItem value="maven" label="Maven"> |
| 54 | +```xml |
| 55 | +<!-- PostgreSQL example --> |
| 56 | +<dependency> |
| 57 | + <groupId>org.postgresql</groupId> |
| 58 | + <artifactId>postgresql</artifactId> |
| 59 | + <version>42.7.0</version> |
| 60 | +</dependency> |
| 61 | + |
| 62 | +<!-- MySQL example --> |
| 63 | +<dependency> |
| 64 | + <groupId>mysql</groupId> |
| 65 | + <artifactId>mysql-connector-java</artifactId> |
| 66 | + <version>8.0.33</version> |
| 67 | +</dependency> |
| 68 | +``` |
| 69 | + </TabItem> |
| 70 | +</Tabs> |
| 71 | + |
| 72 | +## Basic setup |
| 73 | + |
| 74 | +Configure the audit store: |
| 75 | + |
| 76 | +```java |
| 77 | +var auditStore = new SqlAuditStore(dataSource); |
| 78 | +``` |
| 79 | + |
| 80 | +The constructor requires a `DataSource`. Optional configurations can be added via `.withXXX()` methods. |
| 81 | + |
| 82 | +:::info Register Audit Store |
| 83 | +Once created, you need to register this audit store with Flamingock. See [Registering the community audit store](../introduction.md#registering-the-community-audit-store) for details. |
| 84 | +::: |
| 85 | + |
| 86 | +## Audit Store configuration |
| 87 | + |
| 88 | +The SQL audit store uses explicit configuration with no global context fallback. |
| 89 | + |
| 90 | +### Constructor dependencies (mandatory) |
| 91 | + |
| 92 | +These dependencies must be provided at audit store creation time with **no global context fallback**: |
| 93 | + |
| 94 | +| Dependency | Constructor Parameter | Description | |
| 95 | +|------------------------|-----------------------|--------------------------------------------------------------------------| |
| 96 | +| `javax.sql.DataSource` | `dataSource` | SQL database connection pool - **required** for audit store configuration | |
| 97 | + |
| 98 | +### Optional configuration (.withXXX() methods) |
| 99 | + |
| 100 | +These configurations can be customized via `.withXXX()` methods with **no global context fallback**: |
| 101 | + |
| 102 | +| Configuration | Method | Default | Description | |
| 103 | +|-------------------------|----------------------------------|----------------------|---------------------------------------| |
| 104 | +| `Auto Create` | `.withAutoCreate(enabled)` | `true` | Auto-create tables and indexes | |
| 105 | +| `Audit Repository Name` | `.withAuditRepositoryName(name)` | `flamingockAuditLog` | Table name for audit entries | |
| 106 | +| `Lock Repository Name` | `.withLockRepositoryName(name)` | `flamingockLock` | Table name for distributed locks | |
| 107 | + |
| 108 | +**Important**: These default values are optimized for maximum consistency and should ideally be left unchanged. Override them only for testing purposes or exceptional cases. |
| 109 | + |
| 110 | +## Configuration example |
| 111 | + |
| 112 | +Here's a comprehensive example showing the configuration: |
| 113 | + |
| 114 | +```java |
| 115 | +// Audit store configuration (mandatory via constructor) |
| 116 | +var auditStore = new SqlAuditStore(dataSource) |
| 117 | + .withAutoCreate(true) // Optional configuration |
| 118 | + .withAuditRepositoryName("custom_audit_log") // Optional configuration |
| 119 | + .withLockRepositoryName("custom_lock_table"); // Optional configuration |
| 120 | + |
| 121 | +// Register with Flamingock |
| 122 | +Flamingock.builder() |
| 123 | + .setAuditStore(auditStore) |
| 124 | + .addTargetSystems(targetSystems...) |
| 125 | + .build(); |
| 126 | +``` |
| 127 | + |
| 128 | +**Audit store configuration resolution:** |
| 129 | +- **DataSource**: Must be provided via constructor |
| 130 | +- **Database dialect**: Automatically detected from DataSource vendor |
| 131 | +- **Table configurations**: Uses explicit configuration instead of defaults |
| 132 | + |
| 133 | +This architecture ensures explicit audit store configuration with no fallback dependencies. |
| 134 | + |
| 135 | +## Database-specific examples |
| 136 | + |
| 137 | +### PostgreSQL |
| 138 | +```java |
| 139 | +// PostgreSQL DataSource configuration |
| 140 | +HikariConfig config = new HikariConfig(); |
| 141 | +config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb"); |
| 142 | +config.setUsername("user"); |
| 143 | +config.setPassword("password"); |
| 144 | +config.setDriverClassName("org.postgresql.Driver"); |
| 145 | + |
| 146 | +DataSource dataSource = new HikariDataSource(config); |
| 147 | +var auditStore = new SqlAuditStore(dataSource); |
| 148 | +``` |
| 149 | + |
| 150 | +### MySQL |
| 151 | +```java |
| 152 | +// MySQL DataSource configuration |
| 153 | +HikariConfig config = new HikariConfig(); |
| 154 | +config.setJdbcUrl("jdbc:mysql://localhost:3306/mydb"); |
| 155 | +config.setUsername("user"); |
| 156 | +config.setPassword("password"); |
| 157 | +config.setDriverClassName("com.mysql.cj.jdbc.Driver"); |
| 158 | + |
| 159 | +DataSource dataSource = new HikariDataSource(config); |
| 160 | +var auditStore = new SqlAuditStore(dataSource); |
| 161 | +``` |
| 162 | + |
| 163 | +## Schema management |
| 164 | + |
| 165 | +When `autoCreate` is enabled (default), Flamingock automatically creates the required tables: |
| 166 | + |
| 167 | +- **Audit table** (default: `flamingockAuditLog`): Stores execution history |
| 168 | +- **Lock table** (default: `flamingockLock`): Manages distributed locking |
| 169 | + |
| 170 | +The SQL schemas are automatically optimized for each supported database dialect. |
| 171 | + |
| 172 | +:::tip Database Permissions |
| 173 | +Ensure your database user has `CREATE TABLE` and `CREATE INDEX` permissions when using `autoCreate=true`. |
| 174 | +::: |
| 175 | + |
| 176 | +## Next steps |
| 177 | + |
| 178 | +- Learn about [Target systems](../../target-systems/introduction.md) |
| 179 | +- 👉 See a [full example project](https://github.com/flamingock/flamingock-java-examples) |
0 commit comments