Skip to content

Commit

Permalink
#535 SchemaUtils.createMissingTablesAndColumns doesn't correctly chec…
Browse files Browse the repository at this point in the history
…k constraints in H2

sqlite create unique index broken
  • Loading branch information
Tapac committed Mar 30, 2019
1 parent 62925f8 commit 73cbc57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ object SchemaUtils {
}
commit()
}
val executedStatements = createStatements + alterStatements
logTimeSpent("Checking mapping consistence") {
for (statement in checkMappingConsistence(*tables).filter { it !in statements }) {
for (statement in checkMappingConsistence(*tables).filter { it !in executedStatements }) {
exec(statement)
}
commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class SQLiteDialect : VendorDialect(dialectName, SQLiteDataTypeProvider, SQ

override fun createIndex(index: Index): String {
val originalCreateIndex = super.createIndex(index.copy(unique = false))
return if (index.unique) originalCreateIndex.replace("INDEX", "UNIQUE INDEX")
return if (index.unique) originalCreateIndex.replace("CREATE INDEX", "CREATE UNIQUE INDEX")
else originalCreateIndex
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,23 @@ class DDLTests : DatabaseTestsBase() {
assertEquals(0, query.count())
}
}

@Test
fun createTableWithMultipleIndexes() {
withDb {
SchemaUtils.createMissingTablesAndColumns(MultipleIndexesTable)
}
}

object MultipleIndexesTable: Table("H2_MULTIPLE_INDEXES") {
val value1 = varchar("value1", 255)
val value2 = varchar("value2", 255)

init {
uniqueIndex("index1", value1, value2)
uniqueIndex("index2", value2, value1)
}
}
}

private fun String.inProperCase(): String = TransactionManager.currentOrNull()?.let { tm ->
Expand Down

0 comments on commit 73cbc57

Please sign in to comment.