Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ziarv's avatar
Level 1

Database structure for all states of order.

Hi everyone I have a specific requirement from the client. we have an order table that contains all the information related to order such as calculations. The order table has hasMany relationship with order items just like a regular order database structure. After order fullfilment many fields from order table and order items table will be changed now client want to see the original order which was placed as new. Please guide me what is best approch for that.

0 likes
10 replies
Tray2's avatar

Are you talking about cloning an old order into a new one?

1 like
ziarv's avatar
Level 1

@Tray no lets say i have a order which has 2 items and grand total of 100. then user edited the order now order has 4 items and 200 total. we want to see original order with calculations

Tray2's avatar

@ziarv Ah, ok so you are talking about some kind of versioning of the order?

I would probably use database triggers for that, to copy the relevant information to a log table. or maybe add a version to the orders table, and use that to show what is needed.

ziarv's avatar
Level 1

@Tray2 yes this came to my mind like there will be a order_history and order_item_history table but is that a good approch because they have lot of orders its a ERP system

martinbean's avatar

is that a good approch because they have lot of orders its a ERP system

@ziarv Well you’re going to have to store this mess order revisions somewhere. And databases are kinda made to hold lots of data.

1 like
ziarv's avatar
Level 1

@martinbean yes i had a very bad experience of storing data in mysql as json. it increase database size that is why i am little concerned

martinbean's avatar

@ziarv Why JSON? Store data relationally in a relational database. Don‘t just smash it in a JSON blob.

Unfortunately, you can’t magically store things without it taking space. Of course the more data you store, the larger your database becomes. Rows should only be a few bytes in size, though.

1 like

Please or to participate in this conversation.