Skip to content

Commit

Permalink
fix: EXPOSED-161 SQL Server syntax incorrectly allows CASCADE with dr…
Browse files Browse the repository at this point in the history
…opSchema

Using dropSchema() with cascade set to true in SQL Server throws a syntax excep>
because cascade is not supported.

Edit syntax to remove cascade.
Add unit test.
  • Loading branch information
bog-walk committed Aug 30, 2023
1 parent 7c8d8a2 commit ad64e60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,7 @@ open class SQLServerDialect : VendorDialect(dialectName, SQLServerDataTypeProvid
appendIfNotNull(" AUTHORIZATION ", schema.authorization)
}

override fun dropSchema(schema: Schema, cascade: Boolean): String = buildString {
append("DROP SCHEMA ", schema.identifier)

if (cascade) {
append(" CASCADE")
}
}
override fun dropSchema(schema: Schema, cascade: Boolean): String = "DROP SCHEMA ${schema.identifier}"

override fun createIndex(index: Index): String {
if (index.functions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ class SchemaTests : DatabaseTestsBase() {
}
}

@Test
fun testDropSchemaWithCascade() {
withDb {
if (currentDialect.supportsCreateSchema) {
val schema = Schema("TEST_SCHEMA")
SchemaUtils.createSchema(schema)
assertTrue(schema.exists())

SchemaUtils.dropSchema(schema, cascade = true)
assertFalse(schema.exists())
}
}
}

@Test
fun `table references table with same name in other database in mysql`() {
withDb(listOf(TestDB.MYSQL, TestDB.MARIADB)) {
Expand Down

0 comments on commit ad64e60

Please sign in to comment.