GH-804 - Support for schema initialization on Microsoft SQL Server.

Original pull request: GH-808.
This commit is contained in:
Øyvind Johannessen
2024-09-10 09:32:24 +02:00
committed by Oliver Drotbohm
parent 100c1ab198
commit a1f2eb0482
6 changed files with 60 additions and 1 deletions

View File

@@ -104,6 +104,18 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mssqlserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>

View File

@@ -45,7 +45,20 @@ enum DatabaseType {
}
},
POSTGRES("postgresql", "PostgreSQL");
POSTGRES("postgresql", "PostgreSQL"),
MSSQL("sqlserver", "Microsoft SQL Server"){
@Override
Object uuidToDatabase(UUID id) {
return id.toString();
}
@Override
UUID databaseToUUID(Object id) {
return UUID.fromString(id.toString());
}
};
static final String SCHEMA_NOT_SUPPORTED = "Setting the schema name not supported on MySQL!";
@@ -86,6 +99,7 @@ enum DatabaseType {
case MYSQL -> throw new IllegalArgumentException(SCHEMA_NOT_SUPPORTED);
case H2, HSQLDB -> "SET SCHEMA " + schema;
case POSTGRES -> "SET search_path TO " + schema;
case MSSQL -> ""; // No equivalent schema-switching command in MSSQL
};
}
}

View File

@@ -0,0 +1,12 @@
IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'EVENT_PUBLICATION')
CREATE TABLE EVENT_PUBLICATION
(
ID VARCHAR(36) NOT NULL,
LISTENER_ID VARCHAR(512) NOT NULL,
EVENT_TYPE VARCHAR(512) NOT NULL,
SERIALIZED_EVENT VARCHAR(MAX) NOT NULL,
PUBLICATION_DATE DATETIME2(6) NOT NULL,
COMPLETION_DATE DATETIME2(6) NULL,
PRIMARY KEY (ID),
INDEX EVENT_PUBLICATION_BY_COMPLETION_DATE_IDX (COMPLETION_DATE)
);

View File

@@ -122,4 +122,8 @@ class DatabaseSchemaInitializerIntegrationTests {
@Nested
@ActiveProfiles("mysql")
class MySQL extends WithInitEnabled {}
@Nested
@ActiveProfiles("mssql")
class MSSQL extends WithInitEnabled {}
}

View File

@@ -453,6 +453,16 @@ class JdbcEventPublicationRepositoryIntegrationTests {
@WithPostgres
class PostgresWithDeleteCompletion extends WithDeleteCompletion {}
// MSSQL
@WithMssql
class MssqlWithNoDefinedSchemaName extends WithNoDefinedSchemaName {}
@WithMssql
class MssqlWithEmptySchemaName extends WithEmptySchemaName {}
@WithMssql
class MssqlWithDeleteCompletion extends WithDeleteCompletion {}
// MySQL
@WithMySql
@@ -489,4 +499,9 @@ class JdbcEventPublicationRepositoryIntegrationTests {
@ActiveProfiles("postgres")
@Retention(RetentionPolicy.RUNTIME)
@interface WithPostgres {}
@Nested
@ActiveProfiles("mssql")
@Retention(RetentionPolicy.RUNTIME)
@interface WithMssql {}
}

View File

@@ -0,0 +1,2 @@
spring.datasource.url=jdbc:tc:sqlserver:2022-latest:///events;encrypt=false;TC_ACCEPT_LICENSE=accept
spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver