I working on a medium sized PostgreSQL
database with some schemas, each with some tables.
In almost every schema there are tables that represent event tables, where something that has "happened to" or was "caused by" a user is inserted. Essentially making each row in those tables an "Event".
Since I need users (and not necessarily the inserting user) to be able to find Events that have happened since they checked last, I am looking for some way of taking rows inserted into those tables (different table name and schemas) and adding them into an "Events" table.
The Events
table will have a UUID
as PK
, and a UUID
indicating what user "owns" (caused) the event to happen. Then comes the information from the table representing the "Event".
My original plan was to have a INSERT
trigger, for the tables representing the events, that inserted a new row in the Events
table with the original insert.
Of course I would also need some kind of UPDATE
trigger so that any updates made to the original row (in the original table) is also made to the row in the Events
table, but this could just as well be a deletion of the original row (in the Events
table) and then insertion of the new row.
The question is two-fold:
- Is there a better way for me to have a "Events since last checked" function? (Without implementing a horrific amount of booleans and checks and timestamps.)
- What is the best way to insert the necessary information from the separate tables, with different names, layouts and schemas, into the
Events
table?
- What is the best way to insert the necessary information from the separate tables, with different names, layouts and schemas, into the
Aucun commentaire:
Enregistrer un commentaire