Use Flyway Placeholders with Substitution Properties
Use substitution properties to resolve Flyway placeholders in SQL migrations and apply the resolved SQL with Apply DB Schema
Configure Flyway placeholders as substitution properties on a DB Instance. Use the same SQL migration across environments, then apply the resolved SQL in a pipeline.
Before you begin
Complete the following setup before you add placeholders:
Flyway schema: Create a Flyway-compatible DB Schema and store versioned SQL migrations in Git. Go to Work with Flyway migration files to structure those files.
DB Instance: Create the DB Instance that the pipeline uses. Go to Provision Database DevOps to create a schema and instance.
Pipeline: Create a Database DevOps pipeline. Go to Create a pipeline in Database DevOps to add Apply DB Schema and Rollback DB Schema steps.
What you will learn from this topic
How Flyway placeholders map to substitution properties on a DB Instance
How to add
${name}tokens to a versioned SQL migrationHow to apply and roll back Flyway migrations after placeholders are resolved
Add placeholders to a Flyway migration
Add placeholders to a versioned SQL migration in ${name} format. The name inside the token must match a substitution property key.
The following migration contains placeholders for a table name and column lengths:
CREATE TABLE ${table_name} (
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(${name_length}) NOT NULL,
description VARCHAR(${description_length})
);Configure substitution properties
Create or update the DB Instance that the Flyway pipeline step uses. Add the key-value pairs under Substitute Properties. Do not include ${ and } in the property key. Harness passes each pair to Flyway as a placeholder with no extra mapping.
For the preceding migration, configure the following properties:
table_name:audit_eventsname_length:100description_length:255
When a Flyway step uses this DB Instance, Harness passes the properties to Flyway. Flyway resolves the migration as follows:
To use a different value in another environment, configure that environment's DB Instance. Leave the SQL migration in Git unchanged.
Apply and roll back the migration
Use Apply DB Schema and Rollback DB Schema for Flyway migrations. Do not add a native Flyway Command step unless you need a command those steps do not cover.
In the pipeline, add an Apply DB Schema step.
Set Migration Type to Flyway.
Select the Flyway DB Schema and the DB Instance that contains the substitution properties.
Run the pipeline. Harness applies the pending migrations with placeholders resolved.
To revert, add a Rollback DB Schema step that uses the same DB Schema and DB Instance.
The following pipeline applies the Flyway schema on the DB Instance that holds those properties:
Next steps
Use these pages after you configure placeholders:
Work with Flyway migration files: Structure and name Flyway migrations.
Apply DB Schema step: Apply Flyway migrations.
Rollback DB Schema step: Roll back Flyway migrations.
Substitute properties in changelogs: Liquibase equivalent on the same DB Instance UI.
Last updated
Was this helpful?