Starting with version 3.0.0 of tia contentserver coreCore Content Server, the database (both protocol and metadata) is managed by flywayFlyway. Flyway is a framework that allows the version management of databases using scripts and records the used ones. This allows applications to self-manage the database even when changing structure changes, migrating data is migrated, or complex sql SQL-based operations are performed.
In contrast to using JPA (Java/Jakarta Persistence API) to manage the database, flyway needs sql using Flyway requires SQL scripts for each database supported. By default we currently provide tia Core ships with scripts for H2, MSSQL server and Oracle.
Flyway concept and naming patterns
Flyway updates a database from one version to the next using so called migrations. The database migrations are done using sql use SQL-scripts which are applied and against the usage database. This is recorded tracked in a flyway Flyway history table in the database. Upon each start, the tracked executions in the history table is are compared to the existing scripts and if scripts are missing, the migrations will be against the migrations prepared. If one or more migrations have not been applied yet, they get applied.
We can use two types of files: versioned migrations and repeatable migrations.
Version migrations have the pattern V<Version>__<description>.sql
. The capital letter V is important, lowercase will not be recognized. The version can either be in the from 2_9_7
or 2.9.7
both are identical for flywayFlyway. The description can be any text, spaces must be replaced by lowercase stash and should not be too long. Those migrations are executed in the versioning order. Any already applied file must not be changed.
...
The database services are managed for each repository, therefor therefore each database-based service in the repository.cfg has an optional parameter scripts
. The default value is classpath:sql/[meta|metav2|prot]/migration/[h2|sqlserver|oracle]
depending on the service and the database vendor.
...
In the case additional scripts are required, the scripts
parameter can be used to provide them. For example for the oracle version of
This example configures the protocol service additional scripts for oracle in the location /data/custom/kgs/protocol.:
Code Block |
---|
<repo>.protocolservice.database.scripts=classpath:sql/prot/migration/oracle,filesystem:/data/custom/kgs/protocol |
In order to avoid conflicts with the versioned migrations contained by default, only repeatable migrations should be used. Otherwise it may happen, that the version number of the custom script duplicates the version number of a new script provided by kgs. Leaving a larger gap, e.g. kgs scripts end at V4_0_0
and the custom script starts at V90_0_0
, may block kgs scripts later added with V5 and so on. The order of the locations does not matter.
...
In case a database vendor not supported by default is needed, the scripts parameter can also be used. In addition to the JDBC-Driver some vendors also require an additional flyway Flyway dependency (e.g. mysql). The list of supported databases can be found here: https://documentation.red-gate.com/fd/supported-databases-184127454.html .
For example, using a custom vendor for metasaervice metaservice database v2, and the scripts are located in /kgs/data/sql/vendor
Code Block |
---|
<repo>.metaservice.databasev2.scripts=filesystem:/kgs/data/sql/vendor |
The jar JAR files for both the driver and the flyway Flyway dependency can then be placed in a lib library folder, say /kgs/lib
, and must then be added to the application , depending on the deployment, using the application-wide parameter loader.path
, e.g. for container deployments LOADER_PATH=/kgs/lib
. Read here how to apply the parameterApplication wide settings.