Skip to main content

SureInk Database (sureink-database)

Overview

The sureink-database module is the central repository for managing the database schema for the entire SureInk Platform. It uses Liquibase to define, track, and apply all database changes in a version-controlled manner.

This module is not a runnable microservice. Instead, other microservices that require database access (e.g., sureink-cloud-msa, sureink-customer) should include this module as a Maven dependency to ensure they can apply the correct and consistent database schema upon startup.

Status: Placeholder

As of now, this module is a placeholder. It has been set up with the necessary liquibase-core dependency, but it does not yet contain any database changelog files. The instructions below outline how this module is intended to be used.

Technology Stack

  • Database Migration: Liquibase
  • Build System: Apache Maven

Intended Usage

1. Adding Database Changes

All database schema changes (e.g., creating tables, adding columns, defining constraints, inserting seed data) should be implemented as Liquibase changesets.

  1. Create a new changelog file for your feature or schema change. It is recommended to use a structured naming convention, for example:

    • YYYY-MM-DD-feature-name.xml
    • v1.1-add-new-table.xml
  2. Place the new changelog file in the standard Liquibase directory structure, which should be created here:

    src/main/resources/db/changelog/
  3. Include the new changelog file in the master changelog file, db.changelog-master.xml, which should be located at src/main/resources/db/changelog/db.changelog-master.xml.

2. Example Master Changelog (db.changelog-master.xml)

A master changelog file should be created at src/main/resources/db/changelog/db.changelog-master.xml. It will orchestrate all other changelogs.

<?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-latest.xsd">

<!-- Include initial schema setup -->
<include file="db/changelog/v1.0-initial-schema.xml"/>

<!-- Include subsequent changes here -->
<!-- <include file="db/changelog/YYYY-MM-DD-feature-name.xml"/> -->

</databaseChangeLog>

3. Integrating with Other Microservices

To enable a microservice to manage its database schema using this module:

  1. Add sureink-database as a dependency in the microservice's pom.xml:

    <dependency>
    <groupId>com.sureink</groupId>
    <artifactId>sureink-database</artifactId>
    <version>1.0-SNAPSHOT</version>
    </dependency>
  2. Configure the microservice's application.properties or application.yml to point to the master changelog file and enable Liquibase:

    # Enable Liquibase
    spring.liquibase.enabled=true
    # Path to the master changelog file (classpath will resolve to the dependency's resources)
    spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

This setup ensures that whenever a microservice starts, it will automatically check the database and apply any necessary changes defined in this central sureink-database module.