I am creating a database to monitor the state of application functionality. The logic is as follows:
Each application has its own list of features that I track. Each functionality belongs to only one application. There is a Functionality table that has a foreign key to the Application
Each application runs on one or more machines. Each machine can run one or more applications. This is an MTM connection, so there is a connection table for ApplicationInstance Applications with the machines.
Actual monitoring concerns ApplicationInstance queries. If a problem occurs, information about it enters the AppInstanceError table, which contains the foreign key for ApplicationInstance. If the request is successful, we get a list of the statuses of each function. So, we have a FunctionalityStatus table with foreign keys for ApplicationInstance & Functionality.
I think this is a bad design - why do we have some links to the application? What ensures that both will point to the same application? Or is there a way to provide this?
So my suggestion to fix this is to connect FunctionalityStatus with foreign keys for 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, the connection exists and is obvious, so what is normal if it is not in the database?
Is there a βbetter wayβ to solve this problem or provide invisible connections when designing data?
To make it clearer, I prepared the database design that I now have: 
The only thing missing is the connection between FunctionalityStatus and Machine. I see two ways to make such a connection:
- Add a foreign key to ApplicationInstance - then my doubts are as follows:
- How to make sure that ApplicationId from Functionality is the same as from ApplicationInstance?
- Is this duplication of data really necessary?
- Add a foreign key to the car - and doubts:
- Will there be a more accurate ApplicationInstance entry for each FunctionalityStatus entry?
- If there is an obvious connection between ApplicationInstance and FunctionalityStatus (mentioned in the first doubt), why can't we see it in the database?
- Again, data redundancy, because all ApplicationInstance records (or should be) are visible in the FunctionalityStatus table
Or maybe the whole design is screwed up, and I have to find out something completely different?