Skip to main content

How do I add a new value to a service configuration?

Objective: This article explains how to add a new unencrypted value to a service configuration i.e TradingConfiguration.

Steps:

  1. Add the new property to the service's configuration model.
    • modules/<module>/core/models/configuration.ts
  2. Seed the database with a default value for the new property.
    • services/<service>/api/migrations/scripts/

Example:

// Add the new property to the service's configuration model:

export class MyConfiguration extends BaseModel {
...

newProperty: number

static collection = 'Singletons'
static id = 'MyConfiguration'
}
// Migration script to seed the configuration with the default value:

import { MyConfiguration } from '@hectare/platform.modules.<module>.core'
import { DocumentStore } from 'ravendb'

export const up = async (store: DocumentStore) => {
const session = store.openSession()
const config = await session.load<MyConfiguration>(MyConfiguration.id)

// Check if the property exists, if not, seed it with a default value.
if (!Object.prototype.hasOwnProperty.call(config, 'newProperty')) {
model.newProperty = 123
}

await session.saveChanges()
}

export const down = async () => {}

Related Articles: