Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-161 SQL Server syntax incorrectly allows CASCADE with dropSchema #1850

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,12 @@ object SchemaUtils {
* **Note** that when you are using Mysql or MariaDB, this will fail if you try to drop a schema that
* contains a table that is referenced by a table in another schema.
*
* @sample org.jetbrains.exposed.sql.tests.shared.SchemaTests
* @sample org.jetbrains.exposed.sql.tests.shared.SchemaTests.testDropSchemaWithCascade
*
* @param schemas the names of the schema
* @param cascade flag to drop schema and all of its objects and all objects that depend on those objects.
* You don't have to specify this option when you are using Mysql or MariaDB
* because whether you specify it or not, all objects in the schema will be dropped.
* **Note** This option is not supported by MySQL, MariaDB, or SQL Server, so all objects in the schema will be
* dropped regardless of the flag's value.
* @param inBatch flag to perform schema creation in a single batch
*/
fun dropSchema(vararg schemas: Schema, cascade: Boolean = false, inBatch: Boolean = false) {
Expand Down
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}"
bog-walk marked this conversation as resolved.
Show resolved Hide resolved

override fun createIndex(index: Index): String {
if (index.functions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.jetbrains.exposed.sql.vendors.currentDialect
import org.junit.Assume
Expand Down Expand Up @@ -56,6 +55,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
Loading