Broadleaf Microservices
  • v1.0.0-latest-prod

Schema Changes and Required Data

Overview

The TMForum Extensions module expands on the base Broadleaf framework to introduce additional functionality. In service of this, the module may introduce additional DB tables/views and/or required seed data.

Schema Changes

If the module requires database schema changes such as a new table or view, it will be introduced via changelogs following the naming convention db/changelog/{service-name}.tmforum.required.{db-platform}.changelog-master.xml. For example, a PostgreSQL changelog for CatalogServices would be defined in the TMForum Catalog Services Extension module, and would be named db/changelog/catalog.tmforum.required.postgresql.changelog-master.xml.

Each module also contains a META-INF/extension.changelogs file that the Broadleaf starter/initializr configuration will read to detect whether/where the changelog needs to be enabled. This file will assign schema-changing changelogs a very high precedence to ensure that they run after the base framework changelogs but before all other changelogs (including those for required seed data or from client extensions).

The end result should be that in client projects, after flex:generate is run, src/main/resources/db/changelog/{service-name}.flex.{db-platform}.changelog-master.yaml may look something like this:

Example CatalogServices catalog.flex.postgresql.changelog-master.yaml file
databaseChangeLog:
- changeSet:
id: schema-catalog
author: broadleaf-changelog-generation-plugin
changes:
- sql:
sql: create schema if not exists "catalog"
- include: # Applies the base framework schema changelog
file: db/changelog/catalog.flexdemo.postgresql.changelog-master.yaml
author: broadleaf-changelog-generation-plugin
- include: # Applies the TMForum schema changelog
file: db/changelog/catalog.tmforum.required.postgresql.changelog-master.xml
author: broadleaf-changelog-generation-plugin
# Other extension changelogs appear here to apply afterward...

Required Data

Aside from schema changes, modules may also require certain records to exist in the database for proper functionality. This is considered 'required data' or 'required seed data'. Examples of this include permissions/scopes in AuthenticationServices, or admin menu items in AdminNavigationServices.

If the module needs 'required data', it will be introduced via changelogs following the naming convention db/changelog/{service-name}.tmforum.required.data.changelog.xml. For example, a changelog for AuthenticationServices would be defined in the TMForum Authentication Services Extension module, and would be named db/changelog/auth.tmforum.required.data.changelog.xml.

Similar to what’s discussed in the Schema Changes section, the META-INF/extension.changelogs file is also used to drive when these 'required data' changelogs apply. The file will assign required data changelogs a higher precedence to ensure that they run after the base framework changelogs and base starter required data changelogs, but before all other changelogs (such as those from client extensions).

The end result should be that in client projects, after flex:generate is run, src/main/resources/db/changelog/{service-name}.flex.{db-platform}.changelog-master.yaml may look something like this:

Example AuthenticationServices src/main/resources/db/changelog/auth.flex.postgresql.changelog-master.yaml file
databaseChangeLog:
- changeSet:
    id: schema-auth
    author: broadleaf-changelog-generation-plugin
    changes:
    - sql:
        sql: create schema if not exists "auth"
- include: # Applies the base framework schema changelog
    file: db/changelog/auth.flexdemo.postgresql.changelog-master.yaml
    author: broadleaf-changelog-generation-plugin
- include: # Applies the base starter required data changelog
    file: db/changelog/auth.starter.required.data.changelog.xml
    author: broadleaf-changelog-generation-plugin
- include: # Applies the TMForum required data changelog
    file: db/changelog/auth.tmforum.required.data.changelog.xml
    author: broadleaf-changelog-generation-plugin
# Other extension changelogs appear here to apply afterward...