From e91b4f61923bd9515df3681fa6d07f149be95fbe Mon Sep 17 00:00:00 2001 From: Adrian Velonis Date: Wed, 8 Jan 2025 16:24:27 -0600 Subject: [PATCH 1/4] PD-5537 --- .../custom-policy-checks/liquibase-api-python-modules.htm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content/liquibase-pro/policy-checks/custom-policy-checks/liquibase-api-python-modules.htm b/Content/liquibase-pro/policy-checks/custom-policy-checks/liquibase-api-python-modules.htm index 2c4330437..999382621 100644 --- a/Content/liquibase-pro/policy-checks/custom-policy-checks/liquibase-api-python-modules.htm +++ b/Content/liquibase-pro/policy-checks/custom-policy-checks/liquibase-api-python-modules.htm @@ -220,8 +220,8 @@

liquibase_utilities

Returns the SQL associated with this change that would deploy to your database. The function returns any inline SQL (formatted SQL or sql ) or SQL within referenced files (sqlFile) it finds. Otherwise, it generates SQL from any modeled s (like createTable) it finds, similar to running the update-sql command.

Does not include -specific SQL, like updates to the [%=General.databasechangelog%] table.

-

Example:

changes = liquibase_utilities.get_changes() # get the changes we're looking at
-sql = liquibase_utilities.generate_sql(change[0]) # get the first change in the list
+                        

Example:

changes = liquibase_utilities.get_changes()
+sql = liquibase_utilities.generate_sql(change[0])
 if "something bad" in sql:
     status.fired = True
     sys.exit(1) # exit from the check
From 4665ebfce427298c94fd304562e6555284bd80ae Mon Sep 17 00:00:00 2001 From: Adrian Velonis Date: Wed, 8 Jan 2025 16:25:53 -0600 Subject: [PATCH 2/4] PD-5537 --- .../policy-checks/custom-policy-checks/sample-scripts.htm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm index 1b446a547..16cccf868 100644 --- a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm +++ b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm @@ -55,9 +55,9 @@

Script status

Sample scripts

# This script checks for the phrase "DELETE FROM" without "WHERE"

From 904738a80bab3786ef0143c133bde2f719d92cd8 Mon Sep 17 00:00:00 2001
From: Adrian Velonis 
Date: Wed, 8 Jan 2025 17:14:23 -0600
Subject: [PATCH 3/4] PD-5537

---
 .../policy-checks/custom-policy-checks/sample-scripts.htm   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
index 16cccf868..5c3560e56 100644
--- a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
+++ b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
@@ -22,7 +22,7 @@ 

modules

For a list of modules and functions you can call on, see [%=General.Liquibase%] API Python Modules.

Python libraries

-

If you're new to Python, read the official Python tutorial before writing any scripts. See Python Standard Library for information on built-in functions. You can always import these at the beginning of your script.

+

If you're new to Python, read the official Python tutorial before writing any scripts. See the Python Standard Library for information on built-in functions. You can always import these at the beginning of your script.

comes pre-installed with a GraalPy virtual environment. In addition to the built-in modules, the built-in virtual environment contains the following Python modules that aren't part of the Python Standard Library:

However, you cannot install additional modules in the built-in virtual environment because it is packaged in the checks extension JAR file. To install additional modules, you must create your own virtual environment and install them yourself, including a package containing the API. For more information, see Create a Python Virtual Environment.

@@ -34,12 +34,12 @@

Looping behavior

If you write a custom policy check that is individually performance-heavy, and you have a very large or database, may take a long time to run your custom check against all objects.

Script status

-

Your Python script doesn't need to return a value. uses a Status object to track the state of your check:

+

Your Python script doesn't need to return a value. uses an object called Status to track the state of your check:

  • Whether the check has triggered (fired)
  • The message to display as output
-

At the point in your script where the check should trigger, use the  liquibase_utilities to modify the Status object:

if [trigger condition]:
+        

At the point in your script where the check should trigger, use the liquibase_utilities module to modify the Status object:

if [trigger condition]:
     liquibase_utilities.get_status().fired = True
     liquibase_utilities.get_status().message = liquibase_utilities.get_script_message()
     sys.exit(1)

From 6021e10b82b6c3c3f383df879ae5745402b67096 Mon Sep 17 00:00:00 2001
From: Adrian Velonis 
Date: Wed, 8 Jan 2025 17:15:18 -0600
Subject: [PATCH 4/4] PD-5537

---
 .../policy-checks/custom-policy-checks/sample-scripts.htm       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
index 5c3560e56..5963a3cb2 100644
--- a/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
+++ b/Content/liquibase-pro/policy-checks/custom-policy-checks/sample-scripts.htm
@@ -23,7 +23,7 @@ 

modules

For a list of modules and functions you can call on, see [%=General.Liquibase%] API Python Modules.

Python libraries

If you're new to Python, read the official Python tutorial before writing any scripts. See the Python Standard Library for information on built-in functions. You can always import these at the beginning of your script.

-

comes pre-installed with a GraalPy virtual environment. In addition to the built-in modules, the built-in virtual environment contains the following Python modules that aren't part of the Python Standard Library:

+

comes pre-installed with a GraalPy virtual environment. In addition to the built-in modules, this virtual environment contains the following Python modules that aren't part of the Python Standard Library:

However, you cannot install additional modules in the built-in virtual environment because it is packaged in the checks extension JAR file. To install additional modules, you must create your own virtual environment and install them yourself, including a package containing the API. For more information, see Create a Python Virtual Environment.

Looping behavior