W
W
wawa2018-02-28 09:16:52
PostgreSQL
wawa, 2018-02-28 09:16:52

Keep history of database table changes via app or trigger?

There is a sign

CREATE TABLE "user" (
  ...
  "name" text,
  "last_update" timestamptz,
  ...
);

And there is a plate for storing the history of changes of the previous one:
CREATE TABLE "user_history" (
  ...
  "name" text,
  "update" timestamptz,
  ...
);

The question is: what is the best (correct) way to organize the saving of history in user_history when the user changes - at the application level (I write in python) or by a trigger (I use Postgres)?
What do you recommend? What are the +/- for both options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-02-28
@wawa

Definitely a trigger. Implementation at the app level is bad in that any other app of yours that may appear in the future will have to implement this feature. Having entered the database "by hand" and changing user data, you will have no history left. But the use of triggers solves this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question