Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do placeholders work in Flyway?

Tags:

flyway

I'm evaluating Flyway for use in my project. Our current SQL scripts contain placeholders for things like URLs which will have a different domain names depending on the environment (dev, qa, prod).

Specifically, we might have INSERT statements like

INSERT INTO FEED VALUES ('app.${env.token}.company.org/feed1', 'My Feed');

${env.token} needs to be replaced with 'dev', 'qa', or 'prod'.

We have about 50 different properties that could potentially need replacement in SQL scripts. The properties all reside in one or two properties files.

Is there a way to run the Flyway Ant migration task so that it pulls the replacement tokens and values from a properties file? Something along the lines of the Ant filter task?

like image 752
gangsta Avatar asked Feb 23 '12 17:02

gangsta


People also ask

What are Flyway placeholders?

Script Migration Placeholders Flyway Teams. Much like SQL placeholders, Flyway supports placeholder replacement in script migrations. Placeholders can be read through environment variables in your chosen scripting language and by default are prefixed by FP__ and suffixed by __ .

Does Flyway automatically create schema?

If not specified in schemas, Flyway will automatically attempt to create and clean this schema first. This schema will also be the default for the database connection (provided the database supports this concept).

How does Flyway baseline work?

Baseline is for introducing Flyway to existing databases by baselining them at a specific version. This will cause Migrate to ignore all migrations up to and including the baseline version. Newer migrations will then be applied as usual.

Where are Flyway migrations stored?

By default Flyway will look for migrations on the classpath under db/migration, which on a Maven project means src/main/resources/db/migration. You can however also use a location starting with the filesystem: prefix that can be anywhere on your disk.


1 Answers

Currently when supplying placeholders as properties, the property name should be prefixed with flyway.placeholders.

For example the ${env.token} placeholder can be specified directly as this Ant property: flyway.placeholders.env.token

There is currently no support for passing a property file directly, without using prefixes for the property names. Feel free to raise an issue in the Issue Tracker. :-)

like image 129
Axel Fontaine Avatar answered Oct 06 '22 23:10

Axel Fontaine