@@ -53,12 +53,13 @@ static Stream<Arguments> dialectProvider() {
5353 Arguments .of (SqlDialect .MYSQL , "mysql" ),
5454 Arguments .of (SqlDialect .SQLSERVER , "sqlserver" ),
5555 Arguments .of (SqlDialect .ORACLE , "oracle" ),
56- Arguments .of (SqlDialect .POSTGRESQL , "postgresql" )
56+ Arguments .of (SqlDialect .POSTGRESQL , "postgresql" ),
57+ Arguments .of (SqlDialect .MARIADB , "mariadb" )
5758 );
5859 }
5960
6061 private TestContext setupTest (SqlDialect sqlDialect , String dialectName ) throws SQLException {
61- JdbcDatabaseContainer <?> container = createContainer (dialectName );
62+ JdbcDatabaseContainer <?> container = SqlAuditTestHelper . createContainer (dialectName );
6263 container .start ();
6364
6465 HikariConfig config = new HikariConfig ();
@@ -68,7 +69,7 @@ private TestContext setupTest(SqlDialect sqlDialect, String dialectName) throws
6869 config .setDriverClassName (container .getDriverClassName ());
6970 DataSource dataSource = new HikariDataSource (config );
7071
71- createTables (dataSource , sqlDialect );
72+ SqlAuditTestHelper . createTables (dataSource , sqlDialect );
7273
7374 return new TestContext (dataSource , container , sqlDialect );
7475 }
@@ -119,102 +120,20 @@ public String getDatabaseName() {
119120 .withDatabaseName ("testdb" )
120121 .withUsername ("test" )
121122 .withPassword ("test" );
123+ case "mariadb" :
124+ return new MariaDBContainer <>("mariadb:11.3.2" )
125+ .withDatabaseName ("testdb" )
126+ .withUsername ("testuser" )
127+ .withPassword ("testpass" );
122128 default :
123129 throw new IllegalArgumentException ("Unsupported dialect: " + dialectName );
124130 }
125131 }
126132
127- private void createTables (DataSource dataSource , SqlDialect dialect ) throws SQLException {
128- try (Connection conn = dataSource .getConnection ()) {
129- dropTablesIfExist (conn , dialect );
130-
131- String createTestTable = getCreateTestTableSql (dialect );
132- conn .createStatement ().execute (createTestTable );
133-
134- String createLockTable = getCreateLockTableSql (dialect );
135- conn .createStatement ().execute (createLockTable );
136- }
137- }
138-
139- private void dropTablesIfExist (Connection conn , SqlDialect dialect ) throws SQLException {
140- String [] tables = {"flamingockAuditLog" , "test_table" , "flamingockLock" };
141- for (String table : tables ) {
142- try {
143- String dropSql = getDropTableSql (table , dialect );
144- conn .createStatement ().execute (dropSql );
145- } catch (SQLException e ) {
146- // Ignore if table doesn't exist
147- }
148- }
149- }
150-
151- private String getDropTableSql (String tableName , SqlDialect dialect ) {
152- if (dialect == SqlDialect .ORACLE ) {
153- return "DROP TABLE " + tableName + " CASCADE CONSTRAINTS" ;
154- }
155- return "DROP TABLE IF EXISTS " + tableName ;
156- }
157-
158- private String getCreateTestTableSql (SqlDialect dialect ) {
159- switch (dialect ) {
160- case MYSQL :
161- case SQLSERVER :
162- return "CREATE TABLE test_table (" +
163- "id VARCHAR(255) PRIMARY KEY, " +
164- "name VARCHAR(255), " +
165- "field1 VARCHAR(255), " +
166- "field2 VARCHAR(255))" ;
167- case POSTGRESQL :
168- return "CREATE TABLE test_table (" +
169- "id VARCHAR(255) PRIMARY KEY," +
170- "name VARCHAR(255)," +
171- "field1 VARCHAR(255)," +
172- "field2 VARCHAR(255))" ;
173- case ORACLE :
174- return "CREATE TABLE test_table (" +
175- "id VARCHAR2(255) PRIMARY KEY, " +
176- "name VARCHAR2(255), " +
177- "field1 VARCHAR2(255), " +
178- "field2 VARCHAR2(255))" ;
179- default :
180- throw new UnsupportedOperationException ("Dialect not supported: " + dialect );
181- }
182- }
183-
184- private String getCreateLockTableSql (SqlDialect dialect ) {
185- switch (dialect ) {
186- case MYSQL :
187- return "CREATE TABLE flamingockLock (" +
188- "`key` VARCHAR(255) PRIMARY KEY, " +
189- "status VARCHAR(32), " +
190- "owner VARCHAR(255), " +
191- "expires_at TIMESTAMP)" ;
192- case POSTGRESQL :
193- return "CREATE TABLE flamingockLock (" +
194- "\" key\" VARCHAR(255) PRIMARY KEY," +
195- "status VARCHAR(32)," +
196- "owner VARCHAR(255)," +
197- "expires_at TIMESTAMP)" ;
198- case SQLSERVER :
199- return "CREATE TABLE flamingockLock (" +
200- "[key] VARCHAR(255) PRIMARY KEY, " +
201- "status VARCHAR(32), " +
202- "owner VARCHAR(255), " +
203- "expires_at DATETIME)" ;
204- case ORACLE :
205- return "CREATE TABLE flamingockLock (" +
206- "\" key\" VARCHAR2(255) PRIMARY KEY, " +
207- "status VARCHAR2(32), " +
208- "owner VARCHAR2(255), " +
209- "expires_at TIMESTAMP)" ;
210- default :
211- throw new UnsupportedOperationException ("Dialect not supported: " + dialect );
212- }
213- }
214-
215133 private Class <?>[] getChangeClasses (String dialectName , String scenario ) {
216134 switch (dialectName ) {
217135 case "mysql" :
136+ case "mariadb" :
218137 if ("happyPath" .equals (scenario )) {
219138 return new Class <?>[]{
220139 io .flamingock .community .sql .changes .mysql .happyPath ._001__create_index .class ,
@@ -442,7 +361,7 @@ void failedWithRollback(SqlDialect sqlDialect, String dialectName) throws Except
442361 }
443362
444363 // Verify index exists
445- verifyIndexExists (context );
364+ SqlAuditTestHelper . verifyIndexExists (context );
446365
447366 // Verify partial data
448367 try (Connection conn = context .dataSource .getConnection ();
@@ -531,76 +450,14 @@ void failedWithoutRollback(SqlDialect sqlDialect, String dialectName) throws Exc
531450 }
532451
533452 // Verify index exists and data state
534- verifyIndexExists (context );
453+ SqlAuditTestHelper . verifyIndexExists (context );
535454 verifyPartialDataState (context );
536455 }
537456 } finally {
538457 tearDown (context );
539458 }
540459 }
541460
542- private void verifyIndexExists (TestContext context ) throws SQLException {
543- try (Connection conn = context .dataSource .getConnection ()) {
544- String indexCheckSql = getIndexCheckSql (context .dialect );
545- try (PreparedStatement ps = conn .prepareStatement (indexCheckSql )) {
546- switch (context .dialect ) {
547- case ORACLE :
548- ps .setString (1 , "IDX_STANDALONE_INDEX" );
549- ps .setString (2 , "TEST_TABLE" );
550- break ;
551- case POSTGRESQL :
552- ps .setString (1 , "idx_standalone_index" );
553- break ;
554- case MYSQL :
555- case MARIADB :
556- ps .setString (1 , "test_table" );
557- ps .setString (2 , "idx_standalone_index" );
558- break ;
559- case SQLSERVER :
560- case SYBASE :
561- ps .setString (1 , "idx_standalone_index" );
562- break ;
563- case H2 :
564- case HSQLDB :
565- case DERBY :
566- case SQLITE :
567- ps .setString (1 , "idx_standalone_index" );
568- break ;
569- default :
570- ps .setString (1 , "idx_standalone_index" );
571- break ;
572- }
573-
574- try (ResultSet rs = ps .executeQuery ()) {
575- boolean indexExists = rs .next ();
576- assertTrue (indexExists , "Index idx_standalone_index should exist" );
577- }
578- }
579- }
580- }
581-
582- private String getIndexCheckSql (SqlDialect dialect ) {
583- switch (dialect ) {
584- case POSTGRESQL :
585- return "SELECT indexname FROM pg_indexes WHERE indexname = ?" ;
586- case MYSQL :
587- case MARIADB :
588- return "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_NAME = ? AND INDEX_NAME = ?" ;
589- case ORACLE :
590- return "SELECT INDEX_NAME FROM USER_INDEXES WHERE INDEX_NAME = ? AND TABLE_NAME = ?" ;
591- case SQLSERVER :
592- case SYBASE :
593- return "SELECT name FROM sys.indexes WHERE name = ?" ;
594- case H2 :
595- case HSQLDB :
596- case DERBY :
597- case SQLITE :
598- return "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE INDEX_NAME = ?" ;
599- default :
600- return "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.INDEXES WHERE INDEX_NAME = ?" ;
601- }
602- }
603-
604461 private void verifyPartialDataState (TestContext context ) throws SQLException {
605462 try (Connection conn = context .dataSource .getConnection ();
606463 PreparedStatement ps = conn .prepareStatement ("SELECT name FROM test_table WHERE id = ?" )) {
@@ -619,16 +476,4 @@ private void verifyPartialDataState(TestContext context) throws SQLException {
619476 }
620477 }
621478 }
622-
623- private static class TestContext {
624- final DataSource dataSource ;
625- final JdbcDatabaseContainer <?> container ;
626- final SqlDialect dialect ;
627-
628- TestContext (DataSource dataSource , JdbcDatabaseContainer <?> container , SqlDialect dialect ) {
629- this .dataSource = dataSource ;
630- this .container = container ;
631- this .dialect = dialect ;
632- }
633- }
634479}
0 commit comments