Back to Flyway

Environments Namespace

documentation/Reference/Configuration/Environments Namespace.md

latest5.9 KB
Original Source

Environments are a set of associated properties used to connect to a database.

The concept of an environment has been created to allow Flyway to work easily with several different databases or configurations from a single configuration file.

Environment settings

SettingRequiredTypeDescription
urlYesStringDatabase JDBC URL.
userNoStringDatabase user name.
passwordNoStringDatabase password (usually specified using a resolver).
schemasNoString arrayThe schemas to track.
displayNameNoStringThe name of the database, as it appears in Flyway Desktop UI.
driverNoStringThe jdbc driver to use to connect to the database.
connectRetriesNoIntegerThe maximum number of retries when attempting to connect to the database.
connectRetriesIntervalNoIntegerThe maximum time between retries when attempting to connect to the database.
initSqlNoStringSQL statements to be run immediately after a database connection has been established.
provisionerDetermines the type of provisioning to use for this database.

Environment namespaces

NamespaceDescription
flywayFlyway namespace properties to override for the environment.
jdbcPropertiesJDBC properties to pass to the JDBC driver when establishing a connection.
resolversAdditional properties relating to resolvers being used in calculating necessary connection properties.

TOML Configuration

These parameters should be configured in an environments namespace.

powershell
[environments.example]
url = "jdbc:sqlite:local_database1.db"
username = "bob"
...
[environments.another_example]
url = "jdbc:sqlite:local_database2.db"
username = "jeff"
...
[environments.another_example]
locations = ["defaultLocation","customLocation"]

Resolvers

Usually you won't want to keep sensitive information in a plain text configuration file and so resolvers can be used to pull information into your configuration from a variety of external sources like environment variables and secrets managers.

Command line configuration

It is possible to define an environment on the commandline, for example:

powershell
./flyway info -environments.example.url=jdbc:sqlite:local_database.db -environment=example

Note: You define an environment using the environments (plural) namespace but you specify which environment to use with the environment (singular) parameter. It's a bit of a trip hazard but it has some logical purpose to it.

Legacy configuration

Properties that were originally part of the regular flyway configuration (-url, -user, -password) can still be used for backwards compatibility. Under the hood, Flyway will map these onto an environment named default for you and then use them like any other environment.