I'm working on a database schema that's driving me a little mad at the moment because I seem to be repeating the same tables to reproduce behaviour for different types.
Basically the system consists of live sensors that are monitored over a network, and loggers that are collected via a handset. The sensors and loggers are divided up into Locations, and Locations are divided up into Areas. A location can have up to 1 logger, but can have any number of live sensors.
I'll try and break the rules down:
- The system can have 0 to many Areas
- An area can have 0 to many Locations
- A Location can have 0 to 1 Loggers
- A Location can have 0 to many LiveAnalogSensors
- A Location can have 0 to many LiveSwitchSensors
- A Location can have 0 to many Actions allowed
- A LiveAnalogSensor must belong to 1 LiveSensorRelay
- A LiveSwitchSensor must belong to 1 LiveSensorRelay
- A logger can have 0 to many Readings
- A LiveAnalogSensor can have 0 to many Readings
- A LiveSwitchSensor can have 0 to many Readings
- A Reading can have an Alarm
- The system can have 0 to many Actions
- An Alarm can have 0 to 1 Action applied to it
- An Alarm can have 0 to 1 AlarmResolution
So the scenario is, a reading comes in and is stored (either via the Logger download or a live reading coming in over the network). The reading is out of range so it has an alarm code. An alarm gets generated for that reading. An action is eventually applied to it by the user. If a reading comes in that indicates the alarm condition has ended, an AlarmResolution (or AlarmEnd as I called it in the schema) entry is made linked to the Alarm to show that it has ended, and the time it has ended.
On analog alarms, whenever a new reading is higher than the last, a new "Peak" reading is stored, which is what the AnalogSensorReadingAlertPeak table is for.
That is basically it. My issue is how repetitive the schema seems for the different sensors (especially logger and analog-sensor which are basically the same) - and I seem to have a lot of 1 to 0..1 relationships, though I'm less concerned about that.
I'm after a sanity check really. I can think of ways to get rid of the repetitiveness, but it always seems to be at the expense of data integrity.
Thanks.
EDIT: I've revised the title and question slightly after the down vote as it wasn't particularly specific. I hope it's better now..