How to make shareable enums
Use the same field in many tables
You often need to have the same enum shared within or across entities (tables).
For example, you could use a Buy/Sell enum in both a trade table and an orders table. But you don't want to declare it twice.
A further example could be Frequency on a schedule (Daily, Weekly, Monthly, Annually etc). You would need to use this in multiple areas, such as cashflows, fixings, compounding, etc.
To create a shared enum on an entity, simply declare a shared field at the top of the tables-dictionary.kts file. For example:
tables {
val scheduleFrequency = sharedField("SCHEDULE_FREQUENCY", ENUM("Bullet","Annually","Daily","Monthly","Weekly","SemiAnnually","Quarterly"))
table(name = "TRADE", id = 11_000, audit = details(id = 11_004, sequence = "CA")) {
...
field("CASHFLOW_FREQUENCY", scheduleFrequency).default("Bullet").notNull()
field("FIXING_FREQUENCY", scheduleFrequency).default("Bullet").notNull()
field("FIXING_COMPOUNDING_FREQUENCY", scheduleFrequency).default("Bullet").notNull()
...
}
}