For the complete documentation index, see llms.txt. This page is also available as Markdown.

Substituting Properties in Changelogs

Learn how to substitute properties in Liquibase changelogs using built-in and custom configurations in Harness DB DevOps.

It allows you to define placeholders in your changelog files (such as ${property.name}) and later replace these placeholders with actual values when the changelog is executed. This mechanism is especially useful for managing configurations and ensuring flexibility in database migration scripts.

It decouples your database migration logic from environment-specific values, making the whole process of versioning and deploying database changes far more efficient and scalable.

IMPORTANT

Minimum versions required

  • db-devops-service - 11.35.x

  • drone-liquibase - plugins/drone-liquibase:1.2.0-4.27

  • drone-liquibase-mongo - plugins/drone-liquibase:1.2.0-4.27-mongo

  • drone-liquibase-spanner - plugins/drone-liquibase:1.2.0-4.27-spanner

The tokens to replace in your changelog are described using the ${property-name} syntax. The supported format includes alphanumeric characters, +, -, . , and _. Example ${property+name}

Uses

  1. Environment-specific Names

  2. Reusability

  3. Separation of Concerns

  4. Consistency Across Environments

  5. Dynamic Configuration

Let us have a look at the below example to understand the above-mentioned uses.

Here is the YAML for the example:

Property substitution in changelogs

You can set property values from the instance, while creating & updating the instance. Here is the process:

The tokens of above example will get replaced by the property values, once you run update command.

Here is the updated YAML:

Property substitution behavior

Unresolved properties

If the content of ${property-name} does not match a property, it is left as-is, and it is not removed. Once a property has been set, it cannot be changed. Only the first definition is used, others will fail with checksum error.

Let us look at the below changeset:

if ${column.updatedBy} is missing in substitute properties, the token will not be replaced, and it is left as-is:

Escape property substitution

If you do not want a ${property-name} placeholder to be replaced, add a colon : right after the ${.

For example, ${:property-name} will always stay as ${property-name}, even if property-name is defined. It is often useful when you want to show an example without real substitution:

Here is YAML example:

```yaml databaseChangeLog: - changeSet: id: 2 author: bikram changes: - comment: "Create table for schema ${:schema.name}" ```

You can use property substitution in sql and sqlFile change types. Liquibase calculates the checksum after substitution for sql, but before substitution for sqlFile. This impacts attributes like runOnChange.

For example, if you set an environment variable ENV_EXAMPLE=value and use it in both sql and sqlFile changesets, then update the database, the value is substituted. If you later change ENV_EXAMPLE=new_value and run update again, only the sql changeset reruns, because its checksum reflects the substituted value.

Next steps

Last updated

Was this helpful?