A sample Liquibase setup using liquibase-maven-plugin and PostgreSQL.
- A liquibase-hierarchy example.
- How to use .csv files to insert data into tables.
- How to create tables, columns, and set restrictions (constraints).
- How to add/update columns using changesets.
- Simple rollback example.
- Extract username/password from the POM configuration.
- Creating indexes, triggers..
The changelogs/master
folder:
The master folder should contain all the 'databases'.
In this example we only work with one database, tickets
.
The database-folder(s) (e.g. master/tickets
):
A database-folder usually contain the following sub-folders:
data
: All pre-defined data (inserted into the tables) will be included here.testdata
: All pre-defined test data. Keep data and test data separated!tables
: All the tables should be defined here.indexes
: All the create-index definitions should be defined here.
Additional examples..
packages
: Any PL/SQL (e.g. in Oracle databases) should be defined here.triggers
: Any database triggers should be defined here.
- Create a tablespace named 'tickets_db'.
- Create a database named 'tickets'. (This could be done using a sql-script, but I have not included this in the example).
Open the pom.xml, and change the configuration:
<url>jdbc:postgresql://localhost/tickets</url>
: If you for some reason created a database with another name, change /tickets to your database name.<username/> / <password/>
: The username / password should not be configured here (in a real project).. :-)
Open a terminal window and run 'mvn clean install'
in the projects root-folder - magic should now happen!