Skip to content

Commit

Permalink
Check that db supports schema creation within withSchema function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Oct 4, 2022
1 parent 0b0363a commit a5471b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ abstract class DatabaseTestsBase {
Assume.assumeTrue(toTest.isNotEmpty())
toTest.forEach { testDB ->
withDb(testDB) {
SchemaUtils.createSchema(*schemas)
try {
statement()
commit() // Need commit to persist data before drop schemas
} finally {
val cascade = it != TestDB.SQLSERVER
SchemaUtils.dropSchema(*schemas, cascade = cascade)
commit()
if (currentDialectTest.supportsCreateSchema) {
SchemaUtils.createSchema(*schemas)
try {
statement()
commit() // Need commit to persist data before drop schemas
} finally {
val cascade = it != TestDB.SQLSERVER
SchemaUtils.dropSchema(*schemas, cascade = cascade)
commit()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ class DDLTests : DatabaseTestsBase() {
fun createTableWithForeignKeyToAnotherSchema() {
val one = prepareSchemaForTest("one")
val two = prepareSchemaForTest("two")
withSchemas(excludeSettings = listOf(TestDB.SQLITE), schemas = arrayOf(two, one)) {
withSchemas(two, one) {
SchemaUtils.create(TableFromSchemeOne)
if (currentDialectTest is OracleDialect) {
exec("GRANT SELECT ON ${TableFromSchemeOne.tableName} to TWO;")
Expand Down Expand Up @@ -994,7 +994,7 @@ class DDLTests : DatabaseTestsBase() {
override val primaryKey = PrimaryKey(arrayOf(idA, idB))
}

withSchemas(excludeSettings = listOf(TestDB.SQLITE), schemas = arrayOf(one)) {
withSchemas(one) {
SchemaUtils.create(tableA, tableB)
tableA.insert { it[idA] = 1; it[idB] = 1 }
tableB.insert { it[idA] = 1; it[idB] = 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class SchemaTests : DatabaseTestsBase() {
val schema2 = Schema("redundant")
val schemasTryingToCreate = listOf(schema1, schema1, schema2)

withSchemas(excludeSettings = listOf(TestDB.SQLITE), schemas = arrayOf(schema1, schema1, schema2)) {
withSchemas(schema1, schema1, schema2) {
val toCreate = schemasTryingToCreate.filterNot { it.exists() }
/** schema1 and schema2 have been created, so there is no remaining schema to be created */
assertTrue(toCreate.isEmpty())
Expand Down

0 comments on commit a5471b7

Please sign in to comment.