To complete a migration, you must create an SQL folder in your Liquibase project folder. The SQL folder is where you will place all your your SQL scripts that Liquibase uses to track, version, and deploy changes to your database.
To use SQL script files, you must also have a database changelog file. While the SQL scripts define all of your database changes, Liquibase still requires the use of a changelog to tell it where your scripts are located. While you can use XML, JSON, YAML, or formatted SQL when creating a changelog, you must create an XML changelog to use multiple SQL Scripts.
Creating Changelog Files Manually
myChangeLog.xml
.myChangeLog.xml
file.When you have completed your work, save your file.
Generating Changelog Files
If you have an existing database, you can generate a changelog file that reflects the current state of your database. For more information on how to generate a changelog, visit the Liquibase Commands: generateChangelog topic, and read the article about Adding Liquibase on an Existing Project.
To run SQL scripts, you must tell Liquibase where your SQL scripts are located. To configure your changelog, use the includeAll
tag to point Liquibase to the correct folder.
To add SQL scripts to your SQL folder:
.sql
file.When you have completed your work, save your file.
Once you have created and configured your changelog, and have also added your SQL scripts, you are ready to deploy.
To Deploy your Script
LB_HOME/liquibase update
LB_HOME\liquibase.bat update
Note: In place of
LB_HOME
, use the folder name where you extracted Liquibase.
Your database should now contain a table called PERSON.
To check your database:
java -jar (driver-version.jar)
Note: Where (driver-version.jar) is listed, enter your driver name and version number.
Example java -jar h2-1.4.199.jar
If you used a liquibase.properties
file, enter the JDBC URL, User Name, and Password information. Notice that two tables were created:
The DATABASECHANGELOG table contains a list of all the changes that have been run against the database. The DATABASECHANGELOGLOCK table is used to make sure two machines don’t attempt to modify the database at the same time.
View the DATABASECHANGELOG Table and DATABASECHANGELOGLOCK Table topics for more information.
In this tutorial we covered: