Skip to content

Commit

Permalink
fix: EXPOSED-580 MigrationsUtils.statementsRequiredForDatabaseMigrati…
Browse files Browse the repository at this point in the history
…on throws an error when a table is passed that does not already exist in the database (#2271)

The problem was in the `existingIndices` function. For some dialects, querying indices for a table that does not exist throws an error. This is fixed in the `statementsRequiredForDatabaseMigration` function by passing only tables that exist when invoking the `mappingConsistenceRequiredStatements` function.
  • Loading branch information
joc-a authored Oct 14, 2024
1 parent 58d96f0 commit b0a7aed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exposed-migration/src/main/kotlin/MigrationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object MigrationUtils {

val modifyTablesStatements = logTimeSpent("Checking mapping consistence", withLogs) {
mappingConsistenceRequiredStatements(
tables = tables,
tables = tablesToAlter.toTypedArray(),
withLogs
).filter { it !in (createStatements + alterStatements) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ class DatabaseMigrationTests : DatabaseTestsBase() {
}
}

@Test
fun testCreateStatementsGeneratedForTablesThatDoNotExist() {
val tester = object : Table("tester") {
val bar = char("bar")
}

withDb {
val statements = MigrationUtils.statementsRequiredForDatabaseMigration(tester, withLogs = false)
assertEquals(1, statements.size)
assertEquals(
"CREATE TABLE ${addIfNotExistsIfSupported()}${tester.nameInDatabaseCase()} " +
"(${"bar".inProperCase()} CHAR NOT NULL)",
statements.first()
)
}
}

@Test
fun testDropUnmappedColumnsStatementsIdentical() {
val t1 = object : Table("foo") {
Expand Down

0 comments on commit b0a7aed

Please sign in to comment.