Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2398 from liquibase/escape-names-in-getTables
Escape schema/tablenames in metadata.getTables()
- Loading branch information
Showing
2 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...base-integration-tests/src/test/groovy/liquibase/snapshot/JdbcDatabaseSnapshotTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package liquibase.snapshot | ||
|
||
import liquibase.Scope | ||
import liquibase.database.DatabaseFactory | ||
import liquibase.database.jvm.JdbcConnection | ||
import liquibase.extension.testing.testsystem.DatabaseTestSystem | ||
import liquibase.extension.testing.testsystem.TestSystemFactory | ||
import liquibase.statement.SqlStatement | ||
import liquibase.statement.core.RawSqlStatement | ||
import liquibase.structure.core.Table | ||
import liquibase.structure.core.View | ||
import org.junit.Rule | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import java.sql.Connection | ||
|
||
class JdbcDatabaseSnapshotTest extends Specification { | ||
|
||
@Rule | ||
public DatabaseTestSystem h2 = Scope.currentScope.getSingleton(TestSystemFactory).getTestSystem("h2") | ||
|
||
@Unroll | ||
def "getTables and getViews works with underscores in schema names"() { | ||
when: | ||
def connection = h2.getConnection() | ||
def db = DatabaseFactory.instance.findCorrectDatabaseImplementation(new JdbcConnection(connection)) | ||
db.execute([ | ||
new RawSqlStatement("create schema if not exists \"TEST_SCHEMA\""), | ||
new RawSqlStatement("create schema if not exists \"TEST-SCHEMA\""), | ||
new RawSqlStatement("create table if not exists \"TEST-SCHEMA\".test_table (id int)"), | ||
new RawSqlStatement("create view if not exists \"TEST-SCHEMA\".test_view as select * from \"TEST-SCHEMA\".test_table"), | ||
] as SqlStatement[], null) | ||
|
||
then: | ||
SnapshotGeneratorFactory.instance.has(new Table(null, "TEST-SCHEMA", "TEST_TABLE"), db) | ||
!SnapshotGeneratorFactory.instance.has(new Table(null, "TEST_SCHEMA", "TEST_TABLE"), db) | ||
|
||
SnapshotGeneratorFactory.instance.has(new View(null, "TEST-SCHEMA", "TEST_VIEW"), db) | ||
!SnapshotGeneratorFactory.instance.has(new View(null, "TEST_SCHEMA", "TEST_VIEW"), db) | ||
|
||
cleanup: | ||
db.execute([ | ||
new RawSqlStatement("drop schema \"test_schema\" if exists"), | ||
new RawSqlStatement("drop schema \"test-schema\" if exists"), | ||
] as SqlStatement[], null) | ||
} | ||
} |