Earlier quoted context omitted.
I would avoid using database triggers for business logic. In the app (Django or whatever) after inserting news item, call a service (async) that matches users, sends alerts
Agreed. Triggers always feel really clever and powerful, but they live outside your regular application code and are therefor more or less invisible. This will eventually break the law of least surprise. On top of that, triggers are hard to test.
The Ultimate Guide to PostgreSQL Data Change Tracking
11–20 of 27 posts
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#12Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#13Is write-ahead log something new in PostgreSQL? I recall SQL Server being able to do log shipping since the 90s.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#14Another technique not discussed is to create an md5 hash of each record and to keep track of added and deleted hashes. The d hash would exist as an additional column on each table being tracked.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#15I’ve done some of this with an event sourcing system, but not the query rewriting. All my reads use the “latest view”, but the app uses functions to write to the underlying scheme rather than doing “simple” DML.
I wondered if keeping the storage as append only under the hood would keep the app layer simple.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#16Another technique not discussed is to create an md5 hash of each record and to keep track of added and deleted hashes. The d hash would exist as an additional column on each table being tracked.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#17Has anyone ever implemented a schema where you define a view to return the latest instance of each resource, and it maps INSERT, UPDATE and DELETE to an append only table underneath? I’ve done some of this with an event sourcing system, but not the query rewriting. All my reads use the “latest view”, but the app uses functions to write to the underlying scheme rather than doing “simple” DML. I wondered if keeping the…
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#18- https://aiven.io/blog/two-dimensional-time-with-bitemporal-d...
- https://github.com/scalegenius/pg_bitemporal
4 timestamps and some ugly queries.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#19Has anyone ever implemented a schema where you define a view to return the latest instance of each resource, and it maps INSERT, UPDATE and DELETE to an append only table underneath? I’ve done some of this with an event sourcing system, but not the query rewriting. All my reads use the “latest view”, but the app uses functions to write to the underlying scheme rather than doing “simple” DML. I wondered if keeping the…
In general for most apps you'd rather have 2 writes (write to table and write to audit table) than 1 write to the event log and hard to scale reads.
Re: The Ultimate Guide to PostgreSQL Data Change Tracking
#20Is write-ahead log something new in PostgreSQL? I recall SQL Server being able to do log shipping since the 90s.