I'm creating the database for monitoring status of applications' functionalities. The logic is following:
Each application has its own, specific list of functionalities that I'm monitoring. Each functionality belongs to only one application. There is a Functionality table that has foreign key to Application
Each application runs on one or more machines. Each machine can run one or more applications. This is MTM connection, so there is ApplicationInstance table connection Applications with Machines.
The actual monitoring is about querying ApplicationInstance. If there is a problem, information about it goes to AppInstanceError table, wich holds foreign key to ApplicationInstance. If the query is successful, we get a list of statuses of each functionality. So we have a FunctionalityStatus table with foreign keys to ApplicationInstance & Functionality.
I think this is kind of bad design - why do we have multiple reference to Application? What guarantees that both will point to the same Application? Or is there any way to ensure this?
So my proposition of fix is to connect FunctionalityStatus with foreign keys to Machines & Functionality. But in this case they define ApplicationInstance so what is the guarantee of having ApplicationInstance for each pair? Shouldn't they be connected somehow? In the real world connection exists and is obvious, so is it OK not to have it in database?
Is there a "propper way" of solving this problem, or of ensuring connections invisible from data design?
To make it more clear I prepared design of DB that I have now:
The only thing that is missing is a connection from FunctionalityStatus to Machine. I see two ways ow making such a connection:
- Add foreign key to ApplicationInstance - then my doubts are:
- How to make sure that ApplicationId from Functionality is the same that one from ApplicationInstance?
- Isn this data duplication really needed?
- Add foreign key to Machine - and doubts:
- Will there be a propper ApplicationInstance record for every FunctionalityStatus record?
- If there is an obvious connection between ApplicationInstance and FunctionalityStatus (mentioned in first doubt) whu can't we see it in database?
- Again data redundancy becouse all ApplicationInstance records are (or should be) visible in FunctionalityStatus table
Or maybe the whole design is screwed up and I should figure out something totally else?