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
Escape schema/tablenames in metadata.getTables() #2398
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff81879
Escape schema/tablenames in metadata.getTable() to handle names with …
nvoxland dc47726
Escape schema/tablenames in metadata.getTable() to handle names with …
nvoxland f6d9a4c
Merge remote-tracking branch 'origin/master' into escape-names-in-get…
nvoxland fd08168
Added test for getTables and getViews with an underscore in the table…
nvoxland File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup of the schemas and objects makes for a really nice, readable test validation. I wish I'd thought of this when I was doing the manual tests! :) Thanks for the test, @nvoxland.