Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

memiiso/pyliquibase

Repository files navigation

pyliquibase

A Python module to use liquibase in python, using the Java Native Interface (JNI).

Documentation License contributions welcome Create Pypi Release

For full documentation, please visit https://memiiso.github.io/pyliquibase/

Installation

Python-Java integration requires Java. Ensure Java is installed on your operating system.

pip install pyliquibase

Quick Start

using command line:

pyliquibase --defaultsFile=changelogs/liquibase.properties status
pyliquibase --defaultsFile=changelogs/liquibase.properties validate
pyliquibase --defaultsFile=changelogs/liquibase.properties updateSQL
pyliquibase --defaultsFile=changelogs/liquibase.properties update

using python:

from pyliquibase import Pyliquibase

if __name__ == '__main__':
    liquibase = Pyliquibase(defaultsFile="changelogs/liquibase.properties", logLevel="INFO")
    # call execute with arguments
    liquibase.execute("status")
    liquibase.execute("rollback", "MyTag")
    # or 
    liquibase.validate()
    liquibase.status()
    liquibase.updateSQL()
    liquibase.update()
    liquibase.update_to_tag("MyTag")
    liquibase.rollback("MyTag")
    # liquibase maintenance commands
    liquibase.changelog_sync()
    liquibase.changelog_sync_to_tag("MyTag")
    liquibase.clear_checksums()
    liquibase.release_locks()

Python Java Integration

This Python library integrates with Java using the LiquibaseCommandLine class. Our Python LiquibaseCommandLine class acts as a reflection of the Java counterpart, passing Liquibase calls to the Java LiquibaseCommandLine.execute(liquibaseargs) method.

This integration leverages JPype1, a Python library for accessing Java classes. JPype starts a Java Virtual Machine (JVM) within the current process or connects to an existing JVM. For more information on JPype, please refer to their documentation: https://jpype.readthedocs.io/en/latest/.

import jpype
# ... setup classpath ...
jpype.startJVM(classpath=LIQUIBASE_CLASSPATH, convertStrings=True)
liquibase_cli = jpype.JClass("liquibase.integration.commandline.LiquibaseCommandLine")()
liquibase_cli.execute(args)

Contributors

LIQUIBASE is a registered trademark of Liquibase , INC.