The purpose of this document is to guide you through the process of creating a new Liquibase project with H2 on a Windows machine. In this tutorial, you will generate an example project and follow the instructions to apply and learn concepts associated with creating new Liquibase Projects with H2.
<?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-3.8.xsd">
</databaseChangeLog>
changeLogFile: myChangeLog.xml
url: jdbc:h2:file:./h2tutorial
username: admin
password: password
classpath: h2-1.4.200.jar
Note: In this properties file example, the driver jar file is “h2-1.4.200.jar” under the classpath: property. Please rename it to match the one that you have previously downloaded accordingly.
<?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-3.8.xsd">
<changeSet id="1" author="bob">
<createTable tableName="department">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="active" type="boolean"
defaultValueBoolean="true"/>
</createTable>
</changeSet>
</databaseChangeLog>
Note: This create table change set is XML format. The corresponding SQL statement should look like the following:
CREATE TABLE "department"
("id" number(*,0),
"name" VARCHAR2(50 BYTE),
"active" NUMBER(1,0) DEFAULT 1
);
Open the command prompt. Navigate to the LiquibaseH2 directory.
Run the following command:
From a database UI Tool, for example: “DBeaver” check your database changes. You should see a new “department**” table added to the database. For example:
SELECT * FROM public.department;
ID | NAME | ACTIVE |
---|---|---|
NULL | NULL | NULL |
Also, you should see two more tables:
ID | AUTHOR | FILENAME | DATEEXECUTED | ORDEREXECUTED | EXECTYPE | MDSUM | … |
---|---|---|---|---|---|---|---|
1 | bob | dbchangelog.xml | date&time |
1 | EXECUTED | checksumvalue |
… |