Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AMBERMW13 committed Jan 8, 2025
2 parents 4fef059 + 6021e10 commit c1ae367
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ <h2><code>liquibase_utilities</code>
<td>
<p>Returns the SQL associated with this change that <MadCap:variable name="General.Liquibase" /> would deploy to your database. The function returns any inline SQL (<a href="../../../concepts/changelogs/sql-format.html">formatted SQL</a> or <code><MadCap:xref href="../../../change-types/sql.html">sql</MadCap:xref></code>&#160;<MadCap:variable name="General.changetypes" />) or SQL within referenced files (<code><MadCap:xref href="../../../change-types/sql-file.html">sqlFile</MadCap:xref></code>) it finds. Otherwise, it generates SQL from any modeled <MadCap:variable name="General.changetypes" />s (like <code><MadCap:xref href="../../../change-types/create-table.html">createTable</MadCap:xref></code>) it finds, similar to running the <code><MadCap:xref href="../../../commands/update/update-sql.htm">update-sql</MadCap:xref></code> command.</p>
<p>Does not include <MadCap:variable name="General.Liquibase" />-specific SQL, like updates to the <MadCap:xref href="../../../concepts/tracking-tables/databasechangelog-table.html">[%=General.databasechangelog%] table</MadCap:xref>.</p>
<p>Example:</p><pre xml:space="preserve"><code class="language-python">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
<p>Example:</p><pre xml:space="preserve"><code class="language-python">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</code></pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h3><MadCap:variable name="General.Liquibase" /> modules</h3>
</ul>
<p>For a list of <MadCap:variable name="General.Liquibase" /> modules and functions you can call on, see <MadCap:xref href="liquibase-api-python-modules.htm">[%=General.Liquibase%] API Python Modules</MadCap:xref>.</p>
<h3>Python libraries</h3>
<p>If you're new to Python, read the <a href="https://docs.python.org/3/tutorial/index.html">official Python tutorial</a> before writing any scripts. See <a href="https://docs.python.org/3/library/index.html#library-index">Python Standard Library</a> for information on built-in functions. You can always import these at the beginning of your script.</p>
<p><MadCap:variable name="General.Liquibase" /> comes pre-installed with a GraalPy virtual environment. In addition to the built-in <a href="liquibase-api-python-modules.htm"><MadCap:variable name="General.Liquibase" /> modules</a>, the built-in virtual environment contains the following Python modules that aren't part of the Python Standard Library:</p>
<p>If you're new to Python, read the <a href="https://docs.python.org/3/tutorial/index.html">official Python tutorial</a> before writing any scripts. See the <a href="https://docs.python.org/3/library/index.html#library-index">Python Standard Library</a> for information on built-in functions. You can always import these at the beginning of your script.</p>
<p><MadCap:variable name="General.Liquibase" /> comes pre-installed with a GraalPy virtual environment. In addition to the built-in <a href="liquibase-api-python-modules.htm"><MadCap:variable name="General.Liquibase" /> modules</a>, this virtual environment contains the following Python modules that aren't part of the Python Standard Library:</p>
<MadCap:snippetBlock src="../../../Z_Resources/Snippets/text/checks-python-native-modules.flsnp" />
<p>However, you <b>cannot</b> install additional modules in the built-in virtual environment because it is packaged in the <MadCap:variable name="General.Liquibase" /> checks extension JAR file. To install additional modules, you must <b>create your own virtual environment</b> and install them yourself, including a package containing the <MadCap:variable name="General.Liquibase" /> API. For more information, see <MadCap:xref href="python-virtual-environment.htm">Create a Python Virtual Environment</MadCap:xref>.</p>
<h3>Looping behavior</h3>
Expand All @@ -34,12 +34,12 @@ <h3>Looping behavior</h3>
</ul>
<p class="note" MadCap:autonum="&lt;b&gt;Note: &lt;/b&gt;">If you write a custom policy check that is individually performance-heavy, and you have a very large <MadCap:variable name="General.changelog" /> or database, <MadCap:variable name="General.Liquibase" /> may take a long time to run your custom check against all objects.</p>
<h3>Script status</h3>
<p>Your Python script doesn't need to return a value. <MadCap:variable name="General.Liquibase" /> uses a <code class="language-text">Status</code> object to track the state of your check:</p>
<p>Your Python script doesn't need to return a value. <MadCap:variable name="General.Liquibase" /> uses an object called <code class="language-text">Status</code> to track the state of your check:</p>
<ul>
<li>Whether the check has triggered (fired)</li>
<li>The message to display as output</li>
</ul>
<p>At the point in your script where the check should trigger, use the <MadCap:variable name="General.Liquibase" />&#160;<code class="language-text">liquibase_utilities</code> to modify the <code class="language-text">Status</code> object:</p><pre><code class="language-python">if [trigger condition]:
<p>At the point in your script where the check should trigger, use the <code class="language-text">liquibase_utilities</code> module to modify the <code class="language-text">Status</code> object:</p><pre><code class="language-python">if [trigger condition]:
liquibase_utilities.get_status().fired = True
liquibase_utilities.get_status().message = liquibase_utilities.get_script_message()
sys.exit(1)
Expand All @@ -55,9 +55,9 @@ <h3>Script status</h3>
<h2>Sample scripts</h2>
<div class="js-tabs">
<ul class="js-tablist" data-hx="h3">
<li class="js-tablist__item"><a href="#changelog_example" id="label_changelog_example" class="js-tablist__link">Changelog check pseudocode</a>
<li class="js-tablist__item"><a href="#changelog_example" id="label_changelog_example" class="js-tablist__link">Changelog check</a>
</li>
<li class="js-tablist__item"><a href="#database_example" id="label_database_example" class="js-tablist__link">Database check pseudocode</a>
<li class="js-tablist__item"><a href="#database_example" id="label_database_example" class="js-tablist__link">Database check</a>
</li>
</ul>
<div id="changelog_example" class="js-tabcontent"><pre xml:space="preserve"><code class="language-python"># This script checks for the phrase "DELETE FROM" without "WHERE"
Expand Down

0 comments on commit c1ae367

Please sign in to comment.