Mark A-2 as complete: Create domain hierarchy tables for events and tournaments, add Flyway migration script and tests for V2 schema; update roadmap with completed tasks.
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
package at.mocode.entries.service.migration
|
||||
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle
|
||||
import org.testcontainers.containers.PostgreSQLContainer
|
||||
import org.testcontainers.junit.jupiter.Container
|
||||
import org.testcontainers.junit.jupiter.Testcontainers
|
||||
import java.sql.Connection
|
||||
|
||||
@Testcontainers
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class DomainHierarchyMigrationTest {
|
||||
|
||||
companion object {
|
||||
@Container
|
||||
@JvmStatic
|
||||
val postgres = PostgreSQLContainer<Nothing>("postgres:16-alpine").apply {
|
||||
withDatabaseName("meldestelle")
|
||||
withUsername("test")
|
||||
withPassword("test")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `tenant migration creates domain hierarchy tables`() {
|
||||
val schema = "event_test"
|
||||
|
||||
// Run tenant migrations (V1 + V2)
|
||||
Flyway.configure()
|
||||
.dataSource(postgres.jdbcUrl, postgres.username, postgres.password)
|
||||
.locations("classpath:db/tenant")
|
||||
.schemas(schema)
|
||||
.baselineOnMigrate(true)
|
||||
.load()
|
||||
.migrate()
|
||||
|
||||
java.sql.DriverManager.getConnection(postgres.jdbcUrl, postgres.username, postgres.password).use { conn ->
|
||||
setSearchPath(conn, schema)
|
||||
val expected = setOf(
|
||||
"veranstaltungen",
|
||||
"turniere",
|
||||
"bewerbe",
|
||||
"abteilungen",
|
||||
"teilnehmer_konten",
|
||||
"turnier_kassa"
|
||||
)
|
||||
val actual = loadTables(conn, schema, expected)
|
||||
assertEquals(expected, actual, "Alle erwarteten Tabellen müssen existieren")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setSearchPath(conn: Connection, schema: String) {
|
||||
conn.createStatement().use { st -> st.execute("SET search_path TO \"$schema\"") }
|
||||
}
|
||||
|
||||
private fun loadTables(conn: Connection, schema: String, expected: Set<String>): Set<String> {
|
||||
val sql = """
|
||||
select table_name
|
||||
from information_schema.tables
|
||||
where table_schema = ? and table_type = 'BASE TABLE'
|
||||
""".trimIndent()
|
||||
return conn.prepareStatement(sql).use { ps ->
|
||||
ps.setString(1, schema)
|
||||
ps.executeQuery().use { rs ->
|
||||
val names = mutableSetOf<String>()
|
||||
while (rs.next()) names += rs.getString(1)
|
||||
names.retainAll(expected)
|
||||
names
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user