Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kambojankit/springboot

A spring boot seed for quick setup
https://github.com/kambojankit/springboot

Last synced: 9 days ago
JSON representation

A spring boot seed for quick setup

Awesome Lists containing this project

README

        

# Liquibase
##Introduction
Liquibase is a database migration tool. It allows us to write database migration scripts in `XML, YAML, JSON, SQL`.
This allows for developers to write scripts:
- which are schema and data agnostic of database.
- which allow to apply different changes to different environment.
- with ability to rollback from certain changesets.


## Basics
Here we will cover some of the basic concepts of Liquibase
### Changelog
A changelog is used to specify all the changes that occur to the database. We can
add all changes directly to this file, or specify other files/folder where those changes
can be read from and applied.

```$xslt

```

### Changeset
These are the atomic changes that will be applied to the database.
Each change set is uniquely defined by the `id`, `author` and `package` of the file where changeset is defined.
Each changeset is run as a single transaction by liquibase.

```$xslt








```

## Internals
The Liquibase creates 2 tables, `DATABASECHANGELOG` and `DATABASECHANGELOGLOCK`, for its metadata storage.

`DATABASECHANGELOG` keeps records of what all changeset have been applied on the database.
In the table create, liquibase creates the `MD5SUM` column to store Checksum of each changeset that has been applied.
When applying new changes, it compares the checksum of existing changesets to what has already been applied to the database.
This step ensures that the existing changesets have not been modified. If the checksum is different, Liquibase fails.
This is a step that guarantees that a changeset once applied is immutable and that any changes to a database schema
should be applied as a new changeset.

`DATABASECHANGELOGLOCK`is a way mutex works. Liquibase tries to acquire a lock from this table. It makes sure that no
other migrations are going on. If it fails to acquire the lock, the migration step fails.

## Integration with Spring-Boot

- `Maven` configurations needed

```$xslt

org.liquibase
liquibase-core


mysql
mysql-connector-java


```
- `Organise` changeset files: We can achieve this by having all changelog files, in a changelog folder in resources and
including all the changelog there in the main changelog file, as shown below
```$xslt















```
- Setting `Properties`: Add the below details to ``application.properties``
```$properties
spring.datasource.url=jdbc:mysql://localhost:3306/db_example
spring.datasource.username=db-username
spring.datasource.password=db-pass

# This tells spring not to create database on its own, so that liquibase can takeover.
spring.jpa.hibernate.ddl-auto=none
liquibase.change-log=classpath:db/liquibase-changelog.xml
liquibase.enabled=true
```