From 4e85e4263570209b38f4b462f98cbb58f8fed227 Mon Sep 17 00:00:00 2001 From: Adrian Velonis Date: Wed, 9 Oct 2024 16:05:30 -0500 Subject: [PATCH] PD-5174: rollbackSqlFile --- .../code/command-rollback-custom.flsnp | 5 +- .../text/changelog-changeset-attributes.flsnp | 5 ++ ...liquibase-rollback-rollback-sql-file.flsnp | 9 +++ Content/change-types/sql-file.html | 3 +- Content/concepts/changelogs/home.html | 75 +++++++++++++------ Content/concepts/changelogs/sql-format.html | 10 ++- 6 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 Content/Z_Resources/Snippets/text/liquibase-rollback-rollback-sql-file.flsnp diff --git a/Content/Z_Resources/Snippets/code/command-rollback-custom.flsnp b/Content/Z_Resources/Snippets/code/command-rollback-custom.flsnp index 458c9c9b1..8c335c923 100644 --- a/Content/Z_Resources/Snippets/code/command-rollback-custom.flsnp +++ b/Content/Z_Resources/Snippets/code/command-rollback-custom.flsnp @@ -35,10 +35,7 @@ insert into testTable values ('2','The Second', 'Country2') rollback delete from testTable where id='1' rollback delete from testTable where id='2' */ -

In 4.26.0 and later, you can also specify rollback SQL for a in a separate file using the --rollbackSqlFile statement:

--changeset liquibase-user:1
-DROP PROCEDURE hello_world;
---rollbackSqlFile:release_1.0/rollback_45895.sql
-

For more information, see Example Changelogs: SQL Format.

+
databaseChangeLog:
 - changeSet:
diff --git a/Content/Z_Resources/Snippets/text/changelog-changeset-attributes.flsnp b/Content/Z_Resources/Snippets/text/changelog-changeset-attributes.flsnp
index 338e042a3..26ca6399c 100644
--- a/Content/Z_Resources/Snippets/text/changelog-changeset-attributes.flsnp
+++ b/Content/Z_Resources/Snippets/text/changelog-changeset-attributes.flsnp
@@ -178,6 +178,11 @@
  Specifies SQL statements or  tags that describe how to rollback the .
                     For more information, see [%=General.Liquibase%] Rollback Workflow and Automatic and Custom Rollbacks.
             
+            
+                rollbackSqlFile
+                
+                 4.26.0+. Formatted SQL only. Lets you specify a SQL file to roll back rather than an inline SQL statement. For more information, see Example Changelogs: SQL Format.
+            
             
                 validCheckSum
                 
diff --git a/Content/Z_Resources/Snippets/text/liquibase-rollback-rollback-sql-file.flsnp b/Content/Z_Resources/Snippets/text/liquibase-rollback-rollback-sql-file.flsnp
new file mode 100644
index 000000000..ff8307d27
--- /dev/null
+++ b/Content/Z_Resources/Snippets/text/liquibase-rollback-rollback-sql-file.flsnp
@@ -0,0 +1,9 @@
+
+
+    
+        

In 4.26.0 and later, you can use a rollbackSqlFile statement to specify rollback SQL for a in a separate file:

--changeset liquibase-user:1
+DROP PROCEDURE hello_world;
+--rollbackSqlFile:release_1.0/rollback_45895.sql
+

In your rollbackSqlFile statement, you can specify parameters to change the behavior of your rollback, such as a unique end delimiter. For more information, see Example Changelogs: SQL Format.

+ + \ No newline at end of file diff --git a/Content/change-types/sql-file.html b/Content/change-types/sql-file.html index c9429918f..19c904886 100644 --- a/Content/change-types/sql-file.html +++ b/Content/change-types/sql-file.html @@ -41,7 +41,8 @@

Examples

-

Currently, there is no SQL Example for the sqlFile  because you can just put SQL directly into a SQL formatted .

+

There is no implementation for the sqlFile  because you can just put SQL directly into a SQL formatted .

+
databaseChangeLog:
 -  changeSet:
diff --git a/Content/concepts/changelogs/home.html b/Content/concepts/changelogs/home.html
index b5888fb2a..33800eefc 100644
--- a/Content/concepts/changelogs/home.html
+++ b/Content/concepts/changelogs/home.html
@@ -32,27 +32,8 @@ 

File formats

changetype name ( changetype attributes ); ---other element
- - - - - XML example - - -

Read more: Example Changelogs: XML Format.

<?xml version="1.0" encoding="UTF-8"?>  
-
-
-    <preCondition>
-        <preConditionName  preConditionAttribute="value">
-    </preCondition>
-
-    <changeSet  id="value"  author="value">
-        <changeTypeName  changeTypeAttribute="value">
-            <nestedElementName  elementAttribute="value">
-        </changeTypeName>
-    </changeSet>
-</databaseChangeLog>
+--rollback <SQL statement> +--rollbackSqlFile path:<filepath>
@@ -60,7 +41,7 @@

File formats

YAML example -

Read more: Example Changelogs: YAML Format.

databaseChangeLog:
+                

Read more: Example Changelogs: YAML Format.

databaseChangeLog:
   -  preCondition:
       -  preConditionName:
           preConditionAttribute:  value
@@ -69,6 +50,12 @@ 

File formats

id: value author: value changes: + - changeTypeName: + changeTypeAttribute: value + nestedElementGroup: + - nestedElementName: + nestedElementAttribute: value + rollback: - changeTypeName: changeTypeAttribute: value nestedElementGroup: @@ -81,7 +68,7 @@

File formats

JSON example -

Read more: Example Changelogs: JSON Format.

{
+                

Read more: Example Changelogs: JSON Format.

{
     "databaseChangeLog": [
       {
         "preCondition": [
@@ -103,12 +90,26 @@ 

File formats

"nestedElementGroup": [ { "nestedElementName": { - "NestedElementAttribute": "value" + "nestedElementAttribute": "value" } } ] } } + ], + "rollback": [ + { + "changeTypeName": { + "changeTypeAttribute": "value", + "nestedElementGroup": [ + { + "nestedElementName": { + "nestedElementAttribute": "value" + } + } + ] + } + } ] } } @@ -116,6 +117,32 @@

File formats

}
+ + + XML example + + +

Read more: Example Changelogs: XML Format.

<?xml version="1.0" encoding="UTF-8"?>  
+
+
+    <preCondition>
+        <preConditionName  preConditionAttribute="value">
+    </preCondition>
+
+    <changeSet  id="value"  author="value">
+        <changeTypeName  changeTypeAttribute="value">
+            <nestedElementName  elementAttribute="value">
+        </changeTypeName>
+
+        <rollback>
+            <changeTypeName  changeTypeAttribute="value">
+                <nestedElementName  elementAttribute="value">
+            </changeTypeName>
+        </rollback>
+    </changeSet>
+</databaseChangeLog>
+
+

For additional formats, see Example Changelogs: Other Formats.

Runtime logic

When you run a database update, the migrator detects the file type from the file extension and then parses the header. checks any global preconditions specified. If any of the global preconditions fail, exits with an error message explaining what failed. Preconditions can be typically used for both documenting and enforcing expectations or assumptions. For example, you can specify the DBMS to be run against the or the user you should log in to run changes.

diff --git a/Content/concepts/changelogs/sql-format.html b/Content/concepts/changelogs/sql-format.html index 8373af55a..77942157d 100644 --- a/Content/concepts/changelogs/sql-format.html +++ b/Content/concepts/changelogs/sql-format.html @@ -149,14 +149,16 @@

Preconditions

Preconditions can be specified for each . Currently, only the SQL check precondition is supported.

--preconditions onFail:HALT onError:HALT
 --precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM my_table

Rollback actions

-

s may include statements to be applied when rolling back the . Rollback statements have the following format:

--changeset liquibase-user:1
+        

Specify SQL with rollback

+

Your s may include statements to be applied when rolling back the . Rollback statements have the following format:

--changeset liquibase-user:1
 DROP PROCEDURE hello_world;
 --rollback SQL STATEMENT
-

SQL file

-

In 4.26.0 and later, you can also specify a SQL file to execute in a rollback. This requires a license key. For example:

--changeset liquibase-user:1
+        

Specify a SQL file with rollbackSqlFile

+

In 4.26.0 and later, you can use a rollbackSqlFile statement to specify a SQL file to execute in a rollback. A rollbackSqlFile statement in a formatted SQL  behaves the same way as a rollback statement, except that rollbackSqlFile points to a file instead of inline SQL. rollbackSqlFile requires a license key. For example:

--changeset liquibase-user:1
 DROP PROCEDURE hello_world;
 --rollbackSqlFile path:release_1.0/rollback_45895.sql
-

This is equivalent to using the sqlFile  in an XML, YAML, or JSON . In your rollbackSqlFile statement, you can specify the following parameters to change the behavior of your rollback:

+

Specifying rollbackSqlFile in a formatted SQL  is equivalent to using the sqlFile  in an XML, YAML, or JSON to roll back a statement.

+

In your rollbackSqlFile statement, you can specify the following parameters to change the behavior of your rollback: