Liquibase formatted SQL changelogs and multiple files
Solution 1
You can use one XML file which contains multiple references to plain sql (see for details https://www.liquibase.org/documentation/changes/sql_file.html)
Example:
<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-3.3.xsd">
<changeSet id="init" author="author">
<sqlFile encoding="utf8" path="first_changelog.sql"/>
<sqlFile encoding="utf8" path="second_changelog.sql"/>
</changeSet>
Solution 2
So,
It seems like you do not want to use one big formatted SQL changelog in which each changeset is written in the file. Instead, if you want to have separate SQL files that you point to (that use plain SQL), you would need to have a only-touched-once changelog that looks like:
<changeLog><includeAll path="/path/to/your/sql/directory"></changeLog>
Using the includeAll
tells Liquibase to pull in all the SQL files in the directory you point to as if they were individual changeSets. See: http://www.liquibase.org/2015/09/liquibase-without-changelogs.html
P.S.: Depending on your project, you may want to look into Datical - it's a commercial solution that's built on top of Liquibase and makes this all a lot easier. You would just need to check in SQL files into source code control, and Datical has a code packager that can validate and produce an immutable artifact of database changes. You can get out of the business of managing a changeLog entirely.
Comments
-
borino almost 2 years
We are starting using liquibase for our application on the spring-boot. One of requirements use plain sql for liquibase. We have many sql files for initialization database. I check documentation https://www.liquibase.org/documentation/sql_format.html but not found information how can i create hierarchy of change log sql's files. Spring boot properties
liquibase.change-log
awaiting single file. I tried to separate file names by,
or;
all times got error from spring-boot Cannot find changelog location... So my question:
How can i declare execution of another file or files in "sql format"??
Like xml equivalent:<include file="second_changelog.sql"/>
<include file="third_changelog.sql"/>
Not worked examplefirst_changelog.sql
:
--liquibase formatted sql --changeset author_1:1 UPDATE [dbo].[customers] SET name='HD_1' WHERE id = '11'; --import file=second_changelog.sql --import file=third_changelog.sql
PS. Please do not suggest xml, because of i need only SQL
-
borino about 6 yearsThank you but It is not accepted because of requirements requirements. I need only plain sql change log files.