Database - ptal/online-broker GitHub Wiki
Schema
The most interesting thing about this schema is the way we emulate an object hierarchy. We keep a trace of all the events a user (e.g. transfer between account) or the server (e.g. exchange rates update). An event (represented by the table "GameEvents") is created at some date and reference an event (OpenAccountEvents or TransferGameEvents for example). But there is no foreign key set on this field (we can't reference more than one table) so we can easily add a new event table without changing the existing database. Our design is extensible! We know what is the referenced event by looking up the eventType field and retrieving the name of the event in the GameEventsType table. The downside of this technique is that some database logic (multiple foreign keys) must be implemented in the application model, but finally, this implementation is rather simple.