This is a more general database design question than what might be appropriate for this forum, but I thought I’d ask anyway as there’s lots of talented developers here.
I’m trying to implement what I’m calling (for lack of a better term) a change authorization table for our recipe data tables. We have a few master recipe segment data tables that I need to protect from unauthorized changes. We also have a recipe table for each segment table to give the segments some context.
An example of a segment table:
Segment | TemperatureSP | Minutes | GuaranteedSoak | MaxCooling | DisableBurners | EndOfRecipe
---------+---------------+---------+----------------+------------+----------------+-------------
1 | 1135 | 3 | t | f | f | f
2 | 1135 | 117 | f | f | f | f
3 | 1135 | 90 | f | f | f | f
4 | 550 | 1 | f | f | f | t
5 | 1135 | 3 | t | f | f | f
6 | 1135 | 117 | f | f | f | f
7 | 1135 | 175 | f | f | f | f
8 | 550 | 1 | f | f | f | t
9 | 1135 | 3 | t | f | f | f
And here’s an example of the recipe table that gives the previous one context:
recipe_number | segment_range | description
---------------+---------------+--------------------------------------------------------------
1 | [1,5) | 2 hours at 1135, 1:30 hours ramp down to 550
5 | [5,9) | 2 hours at 1135, 2:55 hours ramp down to 550
9 | [9,13) | 3 hours at 1135, 4:25 hours ramp down to 550
13 | [13,17) | 4 hours at 1135, 5:50 hours ramp down to 550
17 | [17,21) | 4 hours at 1350, 3:30 hours ramp down to 1000
What I’m considering doing is adding a table to hold authorized changes. Something like the following:
CREATE TABLE change_authorization (
table_changed text,
item_id_changed int,
change_date date,
person_authorizing_change text,
change_description text
);
table_changed would refer to one of the recipe tables, and the item_id would refer to the recipe number being changed. The person and description would be just text describing the change event (this is the record I need to keep and display later).
What I would like to do is write some sort of trigger function that would disallow updates to the segment table, unless the segment belongs to a recipe that has a current (change_date = today) change authorization entry.
Has anyone dealt with a similar situation? Does this seem like a logical approach to recording the change authorizations? Or am I creating a monster here?