Skip to content

Add an IncludeAll Filter

Prerequisites

Implementing Liquibase extensions requires an understanding of Java. You will be creating classes, overriding methods, and working with inheritance hierarchies.

Project Setup

If you have not already created a repository to hold your code, see Your First Extension in the Getting Started guide.

Overview

By default, Liquibase's [includeAll] tag will include all valid changelog files in the referenced path which are valid changelog files. If you would like to limit the files, you can specify the filter attribute pointing to a class that implements the liquibase.changelog.IncludeAllFilter interface.

Note

If you would like to control the ordering of files included, see Add an IncludeAll Comparator

Example

Suppose you have a changelog directory containing many files and a process where you will sometimes want to archive a changelog file by changing the extension to .bak.xml. When you archive those files, you no longer want them executed by Liquibase.

If you create a class like this:

package com.example.includeall;

import liquibase.changelog.IncludeAllFilter;

public class NoBakFilesFilter implements IncludeAllFilter {

    @Override
    public boolean include(String changeLogPath) {
        return !changeLogPath.contains(".bak.");
    }
}

and add it to your Liquibase classpath, you can reference it in the filter attribute on your includeAll like this:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
    <includeAll path="com/example/changelogs/" filter="com.example.includeall.NoBakFilesFilter"/>
</databaseChangeLog>

Tip

Unlike other extensions, there is no need to register your class in the META-INF/services directory.