Migration with Multiple Schema

Certain services in Central-instance will only be deployed in the central (Digit) namespace but their data needs to be stored in different schema belonging to different state namespace. The migrations of foretold services need to be run in all Required schemas(i e namespaces who want to make use of the centrally deployed services). To enable the above functionality the following changes are required.

ย 

1.Migrate.sh

This file is needed for building migration docker image is located in the DB folder of resources. eg: property-services/src/main/resources/db/migrate.sh . update the file with the following contents.

#!/bin/sh baseurl=$DB_URL echo "the baseurl : $DB_URL" schemasetter="?currentSchema=" schemas=$SCHEMA_NAME echo "the schemas : $schemas" for schemaname in ${schemas//,/ } do echo "the schema name : ${baseurl}${schemasetter}${schemaname}" flyway -url=${baseurl}${schemasetter}${schemaname} -table=$SCHEMA_TABLE -user=$FLYWAY_USER -password=$FLYWAY_PASSWORD -locations=$FLYWAY_LOCATIONS -baselineOnMigrate=true -outOfOrder=true -ignoreMissingMigrations=true migrate done

ย 

2. values.yml

The DB configuration is by default provided in the common values.yml file in the helm chart and need not be edited in normal scenarios. Since we are injecting the multiple schema list for app-specific purposes all the DB-migration ENV variables should be overridden in the app-specific values.yml file.

ย 

#Values.yml of the specific service before multiple schema changes

# Init Containers Configs initContainers: dbMigration: enabled: true schemaTable: "property_services_schema" image: repository: "property-services-db"

ย 

#Values.yml of the specific service after multiple schema changes

DIGIT-DevOps/deploy-as-code/helm/charts/municipal-services/property-services/values.yaml at central-instance ยท egovernments/DIGIT-DevOps - the full updated sample file can be found here

# Init Containers Configs initContainers: dbMigration: enabled: true schemaTable: "property_services_schema" image: repository: "property-services-db" env: | {{- if index .Values "property-ismultischema-enabled" }} - name: SCHEMA_NAME value: {{ index .Values "property-schemas" | quote }} {{- end }} - name: "DB_URL" valueFrom: configMapKeyRef: name: egov-config key: db-url - name: "SCHEMA_TABLE" value: {{ .Values.initContainers.dbMigration.schemaTable | quote }} - name: "FLYWAY_USER" valueFrom: secretKeyRef: name: db key: flyway-username - name: "FLYWAY_PASSWORD" valueFrom: secretKeyRef: name: db key: flyway-password - name: "FLYWAY_LOCATIONS" valueFrom: configMapKeyRef: name: egov-config key: flyway-locations

Only the - name: SCHEMA_NAME variable needs to be added, other fields can be copied from the common values.yml as it is without any changes. The above file contains an if-else condition with two new variables

ย 

The "property-ismultischema-enabled" Boolean value to check if the feature is enabled and "property-schemas" to derive the value from respective environments YAML. This example of two variables should be named differently based on service-name to avoid conflicts.

ย 

3. Environments.yml

In the respective environmentโ€™s file add the two new variables, one for the if condition and the other field for actual values under the respective service names. line 6 and 7 are the sample values provided here.

eg :

ย