memiiso / pyliquibase

Use liquibase java application within python
Apache License 2.0
46 stars 17 forks source link

How to use pyliquibase without liquibase.properties? #83

Closed Pasha54 closed 3 weeks ago

Pasha54 commented 3 weeks ago

I have different configuration files for different environment. How can use the environment specific configuration directly to create Pyliquibase object rather than using a liquibase.properties file?

ismailsimsek commented 3 weeks ago

@Pasha54 it is possible to use it with env variables. See liquibase parametters and related ENV variables here https://docs.liquibase.com/parameters/home.html

example

os.environ["LIQUIBASE_COMMAND_CHANGELOG_FILE"] = "resources/changelog-2.xml"
os.environ["LIQUIBASE_COMMAND_USERNAME"] = ""
os.environ["LIQUIBASE_COMMAND_PASSWORD"] = ""
os.environ["LIQUIBASE_COMMAND_URL"] = "jdbc:sqlite::memory:"
os.environ["LIQUIBASE_COMMAND_DRIVER"] = "org.sqlite.JDBC"
lb = Pyliquibase(version=self.TEST_LIQUIBASE_VERSION)
lb.updateSQL()
Pasha54 commented 3 weeks ago

@ismailsimsek Thanks for answering, this was helpful. I also found out that we could just pass the same as arguments using addarg method. e.g.

    liquibase = Pyliquibase(
            defaultsFile = /path/to/liquibase.properties
        )
    liquibase.addarg("--url", f'jdbc:mysql://{db_config.get("host")}:{db_config.get("port")}/{db_config.get("databaseName")}')
    liquibase.addarg("--username", db_config.get("user"))
    liquibase.addarg("--password", db_config.get("password"))

    if db_config.get("liquibase.auto-update.enabled"):
        liquibase.update()