Occasionally it can be helpful to parameterize a migration depending on an environment. Flyway supports the concept of placeholders to help with that.
Flyway provides default placeholders, whose values are automatically populated:
${flyway:defaultSchema}= The default schema for Flyway${flyway:user}= The user Flyway will use to connect to the database${flyway:database}= The name of the database from the connection url${flyway:timestamp}= The time that Flyway parsed the script, formatted as 'yyyy-MM-dd HH:mm:ss'${flyway:filename}= The filename of the current script${flyway:workingDirectory}= The user working directory as defined by the 'user.dir' System Property${flyway:table}= The name of the Flyway schema history table${flyway:environment}= The name of the environment configured for this script execution
Example of usage in a migration script for Postgres:
DO $$
BEGIN
IF '${flyway:user}' = 'test-account' THEN
EXECUTE 'ALTER TABLE foo.bar OWNER TO test-role';
END IF;
END
$$Custom placeholders can also be configured. Example for Spring Boot custom Flyway placeholder configuration:
spring:
flyway:
placeholders:
test-placeholder: something