Before performing any of these steps, you must be able to connect to a local or remote database, accessible via command line or IDE/GUI. View the Supported Databases topic for more information on which databases we support.
You can also view the Database Tutorials topic for more information on running each database with Liquibase.
To complete your first migration, you must create a formatted
SQL changelog in your Liquibase project directory so Liquibase can track, version, and deploy changes to your database.
To Create your Changelog
Change sets are units of change that Liquibase can execute on a database. When adding a change set, your change must be defined by both an “id” attribute and an “author” attibute. It is best practice to only include one change in each changeset.
To Add your Changeset
changelog.sqlfile, then save it.
See the Formatted SQL Changelogs topic for more information about SQL Syntax.
To deploy the changelog and your new changeset, you run the
update command. When running this command, Liquibase reads your list of change sets in order and checks the DATABASECHANGELOG table for anything that was previously run. Any changsets that have not already been applied to the database will get applied, and Liquibase will track that information.
To Apply the Change Set
liquibase --changeLogFile=changelog.sql update
Your database now contains a table called test1.
To check your database, open your database IDE to find the change that you made.
Notice that two tables were created along with test1:
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.
This topic is great when you only have a handful of SQL scripts. However, if your list of scripts becomes too large to maintain in a formatted SQL changelog, you may want to break up your scripts into smaller more manageable chunks.
See the Database Migrations with Multiple SQL Files topic for more information on how to Migrate with Multiple SQL files.
You can also learn how to create your First Migrations with Liquibase Functions.
In this tutorial we covered: