Is it possible to make postgres automatically update the column definition of an auditory table?
I have the following question, I am using audit tables for some entities in my project so for instance if there is a "people" table there will be a "public_people_audit" table (where "public" is the schema where the table is and "audit" is just a suffix that was chosen).
Now the thing is that when someone from the team modifies the "people" table and adds a column to it they may forget to do it on the auditory table and the system will fail because it will try to insert the new column value in the audit table and it won't 开发者_如何学Pythonfind it.
I know that the team should be careful and put the modification in both tables, but if there could be a way of automating this so if someone makes an "ALTER TABLE people ADD COLUMN foo VARCHAR(10)" the same command will be executed on the public_people_audit table it would be very helpful.
The short answer: no.
The longer answer is you can automate this by create a quick script. Make a simple text file listing a few tables that need auditing. The script reads the text file, looks at the columns in the base tables, and makes sure any missing columns are added to the audit table.
精彩评论