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

Do not escape the backslash in values stored in the objects. #2021

Merged
merged 2 commits into from Nov 15, 2021

Conversation

nvoxland
Copy link
Contributor

@nvoxland nvoxland commented Aug 4, 2021

If the output format needs them escaped, escape them then.

Fixes #1598


Dev Handoff Notes (Internal Use)

Links

Testing

  • Steps to Reproduce: Extra backslash added in the column values in the genarated sql #1598
  • Guidance:
    • The change is in how copy values into the internal objects for the insertData changes.
    • The change is independent of database or output format
    • The change only impacts insert style generated changelogs. Not CSV style ones
    • Did not add automated tests because I only removed code that did stuff, so nothing to unit test. Need better integration tests to be able to check it end to end.

Dev Verification

  • Manually tested that the insert data correctly saved to XML and {{update}}d back into the database.
  • Checked XML and csv format

Test Requirements (Liquibase Internal QA)

This bug is specific to diff-changelog and generate-changelog when --diff-types is passed to the command. When --diff-types includes ‘data,' Liquibase is incorrectly adding an escaping backslash to any containing a backslash. The bug can be replicated with the CLI and Maven interface using Liquibase 4.5.0.

Setup

  • On two Oracle instances, create a user/schema for this test.

CREATE USER LB2103 IDENTIFIED BY password
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"
ACCOUNT UNLOCK ;

GRANT UNLIMITED TABLESPACE TO LB2103;
GRANT DBA TO LB2103;

COMMIT;



* On one Oracle instance, create a table and insert a row of data including a `\` character. 
  * ```
CREATE TABLE LB2103.MY_TABLE (A_TXT CHAR(24 CHAR));
INSERT INTO LB2103.MY_TABLE (A_TXT) VALUES ('2');
INSERT INTO LB2103.MY_TABLE (A_TXT) VALUES ('\b08.* ');
COMMIT;
  • Do not create the table on the second Oracle instance.

Manual Tests: CLI

Verify generate-changelog produces INSERT changesets without adding an escaping backslash.

  • liquibase generate-changelog --changelog-file gcl-lb2103.xml --diff-types table,data
  • liquibase generate-changelog --changelog-file gcl-lb2103.yaml --diff-types table,data
  • liquibase generate-changelog --changelog-file gcl-lb2103.oracle.sql --diff-types table,data
  • liquibase generate-changelog --changelog-file gcl-lb2103.json --diff-types table,data
  • The generated changelog has three change sets (createTable MY_TABLE, insert value “2”, insert value “\b08.*”)
    • XML
    • YAML
    • Formatted SQL
    • JSON
  • There is only one backslash in the value for “\b08.*”
    • XML
    • YAML
    • Formatted SQL
    • JSON

Verify successful update using the generated-changelog.

  • Run liquibase drop-all --schemas LB2103 in between the update command for each changelog type.
  • liquibase update --changelog-file <gcl-lb2103>
    • XML
    • YAML
    • Formatted SQL
    • JSON
  • There is no error during update.

Verify Liquibase inserted the expected data values by querying the database directly.

  • SELECT * FROM LB2103.MY_TABLE;
  • The A_TXT column has values 2 and \b08.*

Verify diff-changelog produces INSERT changesets without adding an escaping backslash.

  • liquibase diff-changelog --changelog-file dcl-lb2103.xml --diff-types table,data
    • ℹ️ If you get a dropTable when you run diff-changelog, swap the url and referenceUrl values in your liquibase.properties file.
    • The diff-changelog completes without error and produces an XML changelog.
    • The changelog has three change sets (createTable and two inserts).
    • There is only one backslash in the value for “\b08.*”

Automated Tests

  • Add a new regression test to the liquibase-pro-tests suite.
  • Update the SQL from the manual tests to work for MariaDB or Postgres.
    • Oracle tests are very slow, and this is a database-agnostic bug so we’ll automate using one of the faster databases.
  • The regression test should be for both the NewCLI and Maven.
  • The regression test should validate each of the changelog formats.
  • Validate generate-changelog produces INSERT changesets without adding an escaping backslash.
    • GIVEN a table MY_TABLE populated with two rows from the data used in the manual tests.
    • WHEN I run liquibase generate-changelog --changelog-file <changelog> --diff-types table,data
    • THEN I expect the changelog to contain
      • one createTable
      • an insert changeset with value 2
      • an insert changset with value \b08.*

Github Users

┆Issue is synchronized with this Jira Bug by Unito

If the output format needs them escaped, escape them then.

Fixes #1598
@nvoxland nvoxland added this to To Do in Conditioning++ via automation Aug 4, 2021
@nvoxland nvoxland requested a review from suryaaki2 August 4, 2021 21:01
@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Aug 4, 2021
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Oct 18, 2021
@nvoxland nvoxland linked an issue Oct 19, 2021 that may be closed by this pull request
@nvoxland nvoxland changed the base branch from 4.4.x to master November 1, 2021 20:45
@nvoxland nvoxland merged commit 97c2acd into master Nov 15, 2021
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Nov 15, 2021
@nvoxland nvoxland deleted the remove-escaped-backslash-in-data-output branch November 15, 2021 15:41
@nvoxland nvoxland removed this from Done in Conditioning++ Dec 1, 2021
@nvoxland nvoxland added this to the v4.6.2 milestone Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extra backslash added in the column values in the genarated sql
3 participants