Skip to main content

Database Migrations

Managing schema changes across environments.

Overview

Database migrations are a way to manage changes to your database schema over time. They allow you to version-control your database structure and ensure that all environments (development, staging, production) are in sync. LibreApps Desktop uses Liquibase for this purpose.

How it Works

  1. Change Log: You define your database changes (tables, columns, indexes) in a YAML, XML, or JSON file called a "change log".
  2. Change Sets: Each individual change is wrapped in a "change set" with a unique ID and author.
  3. Execution: When the microservice starts up, Liquibase checks the DATABASECHANGELOG table to see which change sets have already been applied.
  4. Update: Any new change sets are executed in order, and the DATABASECHANGELOG table is updated.

Example Change Set

databaseChangeLog:
- changeSet:
id: 1
author: jetstart
changes:
- createTable:
tableName: users
columns:
- column:
name: id
type: bigint
autoIncrement: true
constraints:
primaryKey: true
- column:
name: username
type: varchar(255)
constraints:
nullable: false
unique: true

Benefits

  • Version Control: Keep your database schema in sync with your application code.
  • Automation: Automatically apply schema changes during deployment.
  • Rollback: Easily revert changes if something goes wrong.
  • Consistency: Ensure that all developers and environments are using the same database structure.

Best Practices

  • Do this: Create a new change set for every database change.
  • Do this: Use descriptive IDs and comments for your change sets.
  • Don't do this: Manually modify the database schema in production; always use migrations.