Tutorial - Use placeholders to allow for conditional data insertion
Published 24 January 2025
Learn about adding a new versioned migration script to the project folder. Create a new Versioned migration script with placeholders and save it to your project.
Example:- # If your target databases have different names, you can use the default flyway:database placeholder
- IF (${flyway:database} == "HR_DEV")
- INSERT INTO TBL_ENVIRONMENT VALUES ("DEV");
- ELSE IF (${flyway:database} == "HR_TEST")
- INSERT INTO TBL_ENVIRONMENT VALUES ("TEST");
- ELSE IF (${flyway:database} == "HR_STAGE" || ${flyway:database} == "HR_PROD" )
- INSERT INTO TBL_ENVIRONMENT VALUES ("PROD");
- END IF
Learn more about placeholders.
When this versioned migration script is deployed to a target environment, it will replace the placeholder with it's corresponding value and run the correct insert statement.