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

Preserve liquibase.shouldSnapshotData in the CLI #2542

Merged
merged 2 commits into from Feb 23, 2022

Conversation

nvoxland
Copy link
Contributor

Description

When using the CLI, if you set --should-snapshot-data=true but do NOT include a --data-dir flag in generate-changelog, you do not get data included in the generated changelog.

Repo Steps

Populate a database like:

create table test_table (id int);

insert into test_table values (1);
insert into test_table values (2);

Run liquibase --should-snapshot-data=true generate-changelog --changelog-file=out.xml

Expected
out.xml will include <insert> tags for test_table

Actual
output.xml does not include <insert> tags.

@nvoxland
Copy link
Contributor Author

I looked at adding a test to generateChangelog.test.groovy, but because whether Data is snapshotted by default is managed by a singleton, changing the liquibase.shouldSnapshotData flag during the test run doesn't get taken into account. Because of that, I couldn't find a good way to test it through the existing automation.

So, while this does happen to fix the CLI problem because we just run through the logic once, there is a larger problem on respecting that flag as it changes over time we should address at some point.

@XDelphiGrl XDelphiGrl self-assigned this Feb 18, 2022
@XDelphiGrl
Copy link
Contributor

XDelphiGrl commented Feb 22, 2022

This impacts generate-changelog data snapshot behavior. The --should-snapshot-data CLI property is preserved, even when the --data-output-directory property is not specified in the command. Structured changelog formats (XML, YML, JSON) include insert changetypes; the formatted SQL changelog contains insert statements.

Notes

  • There is a mistake in the official Liquibase documentation indicating the --should-snapshot-data is compatible with the snapshot command. This is not true and we will update the documentation. The only command that "gathers" data is generate-changelog.
  • GitHub issue describes the limitation of snapshot and --should-snapshot-data.

Verify generate-changelog includes insert changetypes for data when --should-snapshot-data true. PASS

  • XML PASS
    <changeSet author="erz (generated)" id="1645547823225-3">
        <insert tableName="pr2542">
            <column name="id" valueNumeric="1"/>
        </insert>
        <insert tableName="pr2542">
            <column name="id" valueNumeric="2"/>
        </insert>
    </changeSet>
  • JSON PASS
  {
    "changeSet": {
      "id": "1645547851009-3",
      "author": "erz (generated)",
      "changes": [
        {
          "insert": {
            "columns": [
              {
                "column": {
                  "name": "id",
                  "valueNumeric": 1
                }
              }]
            ,
            "tableName": "pr2542"
          }
        },
        {
          "insert": {
            "columns": [
              {
                "column": {
                  "name": "id",
                  "valueNumeric": 2
                }
              }]
            ,
            "tableName": "pr2542"
          }
        }]
      
    }
  }
  • SQL PASS
-- changeset erz:1645547865549-3
INSERT INTO pr2542 (id) VALUES (1);
INSERT INTO pr2542 (id) VALUES (2);
  • YML PASS
- changeSet:
    id: 1645547839194-3
    author: erz (generated)
    changes:
    - insert:
        columns:
        - column:
            name: id
            valueNumeric: 1
        tableName: pr2542
    - insert:
        columns:
        - column:
            name: id
            valueNumeric: 2
        tableName: pr2542

Verify generate-changelog outputs a csv file when --should-snapshot-data true AND --data-output-directory <someDir>. PASS

Verify generate-changelog includes loadData changetypes when should-snapshot-data true AND --data-output-directory <someDir>.

  • XML PASS
  • YML PASS
  • JSON PASS

I also validated update-sql, update and diff using the XML created with generate-changelog and should-snapshot-data (no data directory specified); everything worked as expected.


Test Environment
Liquibase Core: respect-should-snapshot-data/1528/224e5e, Pro: master/591/f653ec
MySQL 8.0
Windows 10
Passing Functional Tests
Internal Functional Test PR

@nvoxland nvoxland merged commit 79c0e38 into master Feb 23, 2022
@nvoxland nvoxland deleted the respect-should-snapshot-data branch February 23, 2022 20:53
@kataggart kataggart modified the milestones: On Deck, NEXT Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants