Liquibase - Commands

Liquibase Commands

Liquibase is a command line tool.

You run things from a command prompt. Usually you are in the directory that contains the liquibase project file (and changelog files)

Each command shown below is a sample of that command, and then notes on what the command does.

liquibase status

liquibase generate-changeLog –changelog-file=notes_changelog.mssql.sql

Generates a database structure into a sql file.

.mssql. - is an instruction that database is a sql server databsae.

.sql - in an instruction that output should be a sql formatted file.

Sample output

1
2
3
4
5
6
7
8
9
10
-- liquibase formatted sql

-- changeset Mark:1709703994430-1
CREATE TABLE Notes (Id bigint IDENTITY (1, 1) NOT NULL, ObjectType varchar(14) NOT NULL, ObjectId bigint NOT NULL, Dt datetime CONSTRAINT NotesDtDef DEFAULT GETDATE(), Who varchar(40) CONSTRAINT NotesWhoDef DEFAULT user_name(), NoteTypeId bigint NOT NULL, Note nvarchar(MAX), CONSTRAINT NotesPk PRIMARY KEY (Id));

-- changeset Mark:1709703994430-2
CREATE TABLE NoteTypes (Id bigint IDENTITY (1, 1) NOT NULL, ObjectType varchar(14) NOT NULL, NoteType varchar(12) NOT NULL, ShowOnNew bit CONSTRAINT NoteTypesShowOnNewDef DEFAULT 'false', CONSTRAINT NoteTypesPk PRIMARY KEY (Id));

-- changeset Mark:1709703994430-3
ALTER TABLE Notes ADD CONSTRAINT NoteTypeIdUsesNoteTypeFK FOREIGN KEY (NoteTypeId) REFERENCES NoteTypes (Id) ON UPDATE NO ACTION ON DELETE NO ACTION;

liquibase –changeLogFile=notes_changelog.xml generateChangeLog

Generates a database structure into an XML file.

.xml - output a xml file

Sample output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="Mark (generated)" id="1709790861013-1">
<createTable tableName="Notes">
<column autoIncrement="true" computed="false" name="Id" type="bigint">
<constraints nullable="false" primaryKey="true" primaryKeyName="NotesPk"/>
</column>
<column computed="false" name="ObjectType" type="varchar(14)">
<constraints nullable="false"/>
</column>
<column computed="false" name="ObjectId" type="bigint">
<constraints nullable="false"/>
</column>
<column computed="false" defaultValueComputed="getdate()" defaultValueConstraintName="NotesDtDef" name="Dt" type="datetime"/>
<column computed="false" defaultValueComputed="user_name()" defaultValueConstraintName="NotesWhoDef" name="Who" type="varchar(40)"/>
<column computed="false" name="NoteTypeId" type="bigint">
<constraints nullable="false"/>
</column>
<column computed="false" name="Note" type="nvarchar(MAX)"/>
</createTable>
</changeSet>
<changeSet author="Mark (generated)" id="1709790861013-2">
<createTable tableName="NoteTypes">
<column autoIncrement="true" computed="false" name="Id" type="bigint">
<constraints nullable="false" primaryKey="true" primaryKeyName="NoteTypesPk"/>
</column>
<column computed="false" name="ObjectType" type="varchar(14)">
<constraints nullable="false"/>
</column>
<column computed="false" name="NoteType" type="varchar(12)">
<constraints nullable="false"/>
</column>
<column computed="false" defaultValueComputed="'false'" defaultValueConstraintName="NoteTypesShowOnNewDef" name="ShowOnNew" type="bit"/>
</createTable>
</changeSet>
<changeSet author="Mark (generated)" id="1709790861013-3">
<addForeignKeyConstraint baseColumnNames="NoteTypeId" baseTableName="Notes" constraintName="NoteTypeIdUsesNoteTypeFK" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="Id" referencedTableName="NoteTypes" validate="true"/>
</changeSet>
</databaseChangeLog>