Issue with Custom Policy Check in Liquibase using Python Script

Hello everyone,

I’m currently trying to implement a custom policy check in Liquibase using a Python script. In my code, I need to calculate the number of rows in a table. If I use a constant value for this variable, the code works correctly, but I am unable to retrieve this value directly from the database.

I understand that I need to perform a query within the script to get the value, but this is where I’m encountering issues. I have tried using the subprocess library with the “execute-sql” command from Liquibase without success.

I would appreciate any guidance or suggestions on how to achieve this. Is there a recommended way to perform database queries within a custom policy check script in Liquibase that I might be missing?

Thank you in advance for your help.

Hi SantiagoB, thanks for posting your question. If you open a support ticket with Liquibase, we will be happy to provide the working code to you.

https://support.liquibase.com

You can find examples of Regex and Python policy checks here: https://github.com/liquibase/custom_policychecks