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

Add offline mode support for rollbackSQL <tag> #2222

Merged
merged 2 commits into from Feb 14, 2022

Conversation

msimko81
Copy link

@msimko81 msimko81 commented Nov 17, 2021

Fix for the {{OfflineChangeLogHistoryService}}

  • populate tag to the changelog.

[https://github.com//issues/2219|https://github.com//issues/2219]

<!--- This environment context section helps us quickly review your PR.
Please take a minute to fill-out this information. -->

h2. Environment

Liquibase Version:
4.6.1 (but also affecting previous versions)
Liquibase Integration & Version:
CLI & Java API
Database Vendor & Version:
MS SQL Server (but also affecting others)
Operating System Type & Version:
Ubuntu Linux (but also affecting others)

h2. Pull Request Type

<!--- What types of changes does your code introduce?
Put an {{x}} in all the boxes that apply:
If this PR fixes an existing GH issue, edit the next line to add "closes #XXXX" to auto-link.
If this PR fixes an existing CORE Jira issue, note that as well, although there will be no auto-linking. -->

h2. Description

The liquibase offline mode doesn't support {{rollbackSQL }} functionality. The reason is the tag value is not persisted in the {{databasechangelog.csv}} as a result of {{updateSQL}} operation. The tag column only contains empty values, also for changeset containing {{tagDatabase}} command.

h2. Steps To Reproduce

Assume the following {{changelog.xml}}:

{code:java}












{code}

apply the above changelog using the offline mode: {{liquibase --changeLogFile=changelog.xml --url=offline:mssql updateSQL}}

try to perform {{rollbackSQL }} operation: {{liquibase --changeLogFile=changelog.xml --url=offline:mssql rollbackSQL 1.0}}

h2. Actual Behavior

The first step produces {{liquibasechangelog.csv}} with two entries. The second one, with id {{release-1.0}}, contains empty tag. However, the tag of this entry shall be {{1.0}} (as is the state of the database table in corresponding online mode case).

The {{rollbackSQL}} operation fails with the error message: {{Unexpected error running Liquibase: Could not find tag '1.0' in the database}}.

Note: if I manually change the CSV file generated by the first step and specify the tag for the second entry (to mimic the online mode behaviour), the second operation is successful and behaves as expected.

h2. Expected/Desired Behavior

The tag value shall be populated in offline mode (i.e. present in {{liquibasechangelog.csv}}) in order to enable {{rollbackSQL }} operation.

h2. Fast Track PR Acceptance Checklist:

<!--- Completing these speeds up the acceptance of your pull request -->
<!--- Put an {{x}} in all the boxes that apply. -->
<

!--- If you're unsure about any of these, just ask us in a comment. We're here to help|width=200,height=183!

-->

  • Build is successful and all new and existing tests pass
  • Added [Unit Test(s)|https://liquibase.jira.com/wiki/spaces/LB/pages/1274937609/How+to+Write+Liquibase+Core+Unit+Tests]
  • Added [Integration Test(s)|https://liquibase.jira.com/wiki/spaces/LB/pages/1276608569/How+to+Write+Liquibase+Core+Integration+Tests]
  • Added [Test Harness Test(s)|https://github.com/liquibase/liquibase-test-harness/pulls]
  • Documentation Updated

h2. Need Help?

Come chat with us on our [discord channel|https://discord.com/channels/700506481111597066/700506481572839505]


h2. Dev Handoff Notes (Internal Use)

h4. Links

h4. Testing

h4. Dev Verification

Verified that with the change, running {{liquibase rollback-sql --tag 1.0}} only returns SQL to roll back the changeset as well as other changesets after it. But not ones before.

My sample changelog:

{code:java}



<changeSet author="nathan" id="2">
    <createTable tableName="test2">
        <column name="id" type="int"/>
    </createTable>
</changeSet>

<changeSet id="release-1.0" author="miro">
    <tagDatabase tag="1.0"/>
</changeSet>

<changeSet author="nathan" id="3">
    <createTable tableName="test3">
        <column name="id" type="int"/>
    </createTable>
</changeSet>{code}

Manual Tests
Use this changelog:

        <changeSet  author="Liquibase"  id="1">
        	<createTable tableName="test_table_1">
            		<column name="some_col" type="VARCHAR2(50 BYTE)"/>
        	</createTable>
    	</changeSet>

	<changeSet  author="Liquibase"  id="2">
        	<tagDatabase tag="myTag"/>
    	</changeSet>

	<changeSet  author="Liquibase"  id="3">
        	<createTable tableName="test_table_2">
            		<column name="some_col" type="VARCHAR2(50 BYTE)"/>
        	</createTable>
    	</changeSet>

	<changeSet  author="Liquibase"  id="4">
        	<tagDatabase tag="2.0"/>
    	</changeSet>

	<changeSet  author="Liquibase"  id="5">
        	<createTable tableName="test_table_3">
            		<column name="some_col" type="VARCHAR2(50 BYTE)"/>
        	</createTable>
    	</changeSet>

Verify generated changelog contains correct tag names when using offline mode.

  • liquibase update-sql --url offline:postgres --changeLog-file changelog.xml
  • generated databasechangelog.csv correctly contains tag names myTag and 2.0 for changesets with id 2 and 4

Verify rollback-sql command correctly rolls back changes.

  • liquibase rollback-sql 2.0 --url offline:postgres --changeLogFile changelog.xml
  • rollback-sql is successful
  • changesets with id 4 and 5 are removed from databasechangelog.csv
  • liquibase rollback-sql myTag --url offline:postgres --changeLogFile changelog.xml
  • rollback-sql is successful
  • changesets with id 2 and 3 are removed from databasechangelog.csv

┆Issue is synchronized with this Jira Bug by Unito

Fix for the `OfflineChangeLogHistoryService` - populate tag to the changelog.

liquibase#2219
@molivasdat
Copy link
Contributor

Hi @msimko81 Thanks for adding this PR. We will add it to the list of PRs to process.

A member of the Liquibase team will take a look at your contribution and may suggest:

The PR will be prioritized according to our internal development and testing capacity.

We’ll let you know when it’s ready to move to the next step or if any changes are needed.

@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Dec 22, 2021
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Dec 28, 2021
@yodzhubeiskyi
Copy link
Contributor

Test Results
Verify generated changelog contains correct tag names when using offline mode. PASS

-- Changeset lb2198-changelog.xml::1::Liquibase
CREATE TABLE test_table_1 (some_col VARCHAR(50));

-- Changeset lb2198-changelog.xml::2::Liquibase
-- Changeset lb2198-changelog.xml::3::Liquibase
CREATE TABLE test_table_2 (some_col VARCHAR(50));

-- Changeset lb2198-changelog.xml::4::Liquibase
-- Changeset lb2198-changelog.xml::5::Liquibase
CREATE TABLE test_table_3 (some_col VARCHAR(50));

Liquibase command 'update-sql' was executed successfully.

Verify rollback-sql command correctly rolls back changes. PASS

-- Rolling Back ChangeSet: lb2198-changelog.xml::5::Liquibase
DROP TABLE test_table_3;

-- Rolling Back ChangeSet: lb2198-changelog.xml::4::Liquibase
Liquibase command 'rollback-sql' was executed successfully.
-- Rolling Back ChangeSet: lb2198-changelog.xml::3::Liquibase
DROP TABLE test_table_2;

-- Rolling Back ChangeSet: lb2198-changelog.xml::2::Liquibase
Liquibase command 'rollback-sql' was executed successfully.

Liquibase version [Core: //master/1049/76cf69/2021-12-23 07:02+0000, Pro: master/320/3630fa/2021-12-23T04:37:10Z] #1049

@nvoxland nvoxland changed the base branch from master to 1_9 February 14, 2022 14:50
@nvoxland nvoxland changed the base branch from 1_9 to master February 14, 2022 14:50
@nvoxland nvoxland merged commit 7403ec2 into liquibase:master Feb 14, 2022
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Feb 14, 2022
@nvoxland nvoxland added this to the v4.8.0 milestone Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Liquibase offline mode doesn't support rollbackSQL <tag> operation
5 participants