Skip to content

Commit e0b79e5

Browse files
Fezlightodrotbohm
authored andcommitted
GH-836 - Add support for MariaDB database.
1 parent 0c2f79a commit e0b79e5

File tree

8 files changed

+75
-0
lines changed

8 files changed

+75
-0
lines changed

spring-modulith-events/spring-modulith-events-jdbc/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
<scope>test</scope>
105105
</dependency>
106106

107+
<dependency>
108+
<groupId>org.testcontainers</groupId>
109+
<artifactId>mariadb</artifactId>
110+
<scope>test</scope>
111+
</dependency>
112+
107113
<dependency>
108114
<groupId>org.testcontainers</groupId>
109115
<artifactId>mssqlserver</artifactId>
@@ -140,6 +146,12 @@
140146
<scope>test</scope>
141147
</dependency>
142148

149+
<dependency>
150+
<groupId>org.mariadb.jdbc</groupId>
151+
<artifactId>mariadb-java-client</artifactId>
152+
<scope>test</scope>
153+
</dependency>
154+
143155
</dependencies>
144156

145157
</project>

spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/DatabaseType.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ boolean isSchemaSupported() {
5050
}
5151
},
5252

53+
MARIADB("mariadb", "MariaDB") {
54+
55+
@Override
56+
Object uuidToDatabase(UUID id) {
57+
return id.toString();
58+
}
59+
60+
@Override
61+
UUID databaseToUUID(Object id) {
62+
return UUID.fromString(id.toString());
63+
}
64+
65+
@Override
66+
boolean isSchemaSupported() {
67+
return false;
68+
}
69+
},
70+
5371
POSTGRES("postgresql", "PostgreSQL"),
5472

5573
MSSQL("sqlserver", "Microsoft SQL Server") {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS EVENT_PUBLICATION
2+
(
3+
ID VARCHAR(36) NOT NULL,
4+
LISTENER_ID VARCHAR(512) NOT NULL,
5+
EVENT_TYPE VARCHAR(512) NOT NULL,
6+
SERIALIZED_EVENT VARCHAR(4000) NOT NULL,
7+
PUBLICATION_DATE TIMESTAMP(6) NOT NULL,
8+
COMPLETION_DATE TIMESTAMP(6) DEFAULT NULL NULL,
9+
PRIMARY KEY (ID),
10+
INDEX EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX (COMPLETION_DATE)
11+
);

spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerIntegrationTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ class Postgres extends WithInitEnabled {}
123123
@ActiveProfiles("mysql")
124124
class MySQL extends WithInitEnabled {}
125125

126+
@Nested
127+
@ActiveProfiles("mariadb")
128+
class MariaDB extends WithInitEnabled {}
129+
126130
@Nested
127131
@ActiveProfiles("mssql")
128132
class MSSQL extends WithInitEnabled {}

spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerUnitTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ void rejectsExplicitSchemaNameForMySql(String schema) {
4747
assertThatIllegalStateException().isThrownBy(() -> createInitializer(withSchema(schema), DatabaseType.MYSQL));
4848
}
4949

50+
// GH-836
51+
@ParameterizedTest
52+
@ValueSource(strings = { "", "test" })
53+
void rejectsExplicitSchemaNameForMariDB(String schema) {
54+
assertThatIllegalStateException().isThrownBy(() -> createInitializer(withSchema(schema), DatabaseType.MARIADB));
55+
}
56+
5057
// GH-804
5158
@ParameterizedTest
5259
@ValueSource(strings = { "", "test" })

spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ class MysqlWithNoDefinedSchemaName extends WithNoDefinedSchemaName {}
469469
@WithMySql
470470
class MysqlWithDeleteCompletion extends WithDeleteCompletion {}
471471

472+
// MariaDB
473+
474+
@WithMariaDB
475+
class MariaDBWithNoDefinedSchemaName extends WithNoDefinedSchemaName {}
476+
477+
@WithMariaDB
478+
class MariaDBWithDeleteCompletion extends WithDeleteCompletion {}
479+
472480
@Value
473481
private static final class TestEvent {
474482
String eventId;
@@ -493,6 +501,11 @@ private static final class Sample {}
493501
@Retention(RetentionPolicy.RUNTIME)
494502
@interface WithMySql {}
495503

504+
@Nested
505+
@ActiveProfiles("mariadb")
506+
@Retention(RetentionPolicy.RUNTIME)
507+
@interface WithMariaDB {}
508+
496509
@Nested
497510
@ActiveProfiles("postgres")
498511
@Retention(RetentionPolicy.RUNTIME)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.datasource.url=jdbc:tc:mariadb:11.5.2:///events
2+
spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver

src/docs/antora/modules/ROOT/pages/appendix.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ include::{jdbc-schema-base}/schema-hsqldb.sql[]
203203
include::{jdbc-schema-base}/schema-mysql.sql[]
204204
----
205205

206+
[[schemas.mariadb]]
207+
=== MariaDB
208+
209+
[source, sql]
210+
----
211+
include::{jdbc-schema-base}/schema-mariadb.sql[]
212+
----
213+
206214
[[schemas.postgresql]]
207215
=== PostgreSQL
208216

0 commit comments

Comments
 (0)