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-625 SchemaUtils.listTables() retrieves tables for the default schema only #2301

Merged
merged 1 commit into from
Nov 13, 2024
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 @@ -51,13 +51,9 @@ abstract class VendorDialect(

override fun getDatabase(): String = catalog(TransactionManager.current())

/**
* Returns a list with the names of all the defined tables with schema prefixes if database supports it.
* This method always re-read data from DB.
* Using `allTablesNames` field is the preferred way.
*/
/** Returns a list with the names of all the defined tables with schema prefixes if the database supports it. */
override fun allTablesNames(): List<String> = TransactionManager.current().connection.metadata {
tableNamesByCurrentSchema(null).tableNames
getAllTableNamesCache().flatMap { it.value }
}

override fun tableExists(table: Table): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.tests.currentDialectTest
import org.jetbrains.exposed.sql.tests.inProperCase
import org.jetbrains.exposed.sql.tests.shared.Category
import org.jetbrains.exposed.sql.tests.shared.Item
import org.jetbrains.exposed.sql.tests.shared.assertEqualCollections
import org.jetbrains.exposed.sql.tests.shared.assertEquals
import org.jetbrains.exposed.sql.tests.shared.assertTrue
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.vendors.MysqlDialect
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.jetbrains.exposed.sql.vendors.SQLServerDialect
import org.junit.Test
import java.util.*
import kotlin.test.assertFails
Expand Down Expand Up @@ -590,10 +594,21 @@ class CreateTableTests : DatabaseTestsBase() {
SchemaUtils.create(OneTable)
assertEquals(true, OneTable.exists())
assertEquals(false, OneOneTable.exists())

val defaultSchemaName = when (currentDialectTest) {
is SQLServerDialect -> "dbo"
is OracleDialect -> testDb.user
is MysqlDialect -> testDb.db!!.name
else -> "public"
}
assertTrue(SchemaUtils.listTables().any { it.equals("$defaultSchemaName.${OneTable.tableName}", ignoreCase = true) })

SchemaUtils.createSchema(one)
SchemaUtils.create(OneOneTable)
assertEquals(true, OneTable.exists())
assertEquals(true, OneOneTable.exists())

assertTrue(SchemaUtils.listTables().any { it.equals(OneOneTable.tableName, ignoreCase = true) })
} finally {
SchemaUtils.drop(OneTable, OneOneTable)
val cascade = testDb != TestDB.SQLSERVER
Expand Down
Loading