How do I track version number in budget?

1

I'm breaking my head here to get a common denominator, I have a system in Delphi with PostgreSQL, this system has a budget session

I need to track the changes made in these budgets by putting version number, ie with each change requested by the customer the seller resending a new budget has to register in the system every change.

Example: Vendor sent 10 items, customer asked to leave only 9

So the first budget would be: 1.00, but the second 1.01

I'll need to control everything, everything, even a comma.

I was thinking of cloning the tables (6 tables) that are used in that budget and saving the records on them whenever there is a update , but I see that it will be very laborious to keep this mirroring. >

I ask colleagues if they have had a need for something similar and if they can contribute ideas, I work alone so I turned to you.

    
asked by anonymous 20.02.2018 / 14:35

2 answers

1

I think cloning tables is not the best alternative. What you can do is make your main table (which I imagine is orcamento ) to be recursive.

To do this add a id_orcamento_anterior field, so you duplicate the records but not the tables.

When you want to get the latest quotes you can do something like:

SELECT * FROM orcamento a
WHERE NOT EXISTS (
    SELECT b.id_orcamento FROM orcamento b
    WHERE a.'id_orcamento' = b.'id_orcamento_anterior'
);

With the result of this query , you can also get the previous budgets through the field created.

    
20.02.2018 / 15:03
1

It's simple, consider each version as a different budget, having information that identifies which version it is. You know the last one is worth it. It may even have some mechanism to freeze edits.

Of course every time you change part of the previous one to create the new one.

It's possible to make some optimizations to make space, but it's getting complicated a little bit.

In some cases the solution of having a table with the drafts and another with the end can be useful, but complicates a little do not know if it is advantageous. would have to copy to the drafts table and remove the current one. It may be a bit simpler if you consider everything draft and only when you freeze the budget is that you copy to the definitive table and there you can no longer touch it. I do not think it pays off.

    
20.02.2018 / 15:02