I am pretty new to database schema design. So this may sounds trivial to experts
I am designing a app that store photo for each trip I created. So, I have one table storing trips and one table storing some photos belonging to each trips.
So, things seems easy for designing this table . And below are my drafted schema
Trips
ID
title
created_at
Photos
ID
title
created_at
image_location
trip_id
Here is the problem: If I would like to show the order of photos, I can make use of the attribute of created_at in Photos. But what if one day I would like to rearrange the order of images or I inadvertently assign the photos with wrong order at the first time I add it into the trip.
What I come up with is that I try to make an column called order_no in Photos, so when there is new photos added, its order_no would be increased by one and assigned to it.
Photos
ID
title
created_at
trip_id
order_no
However, the problem is that I will have to update every order_no to keep the sequence order consistent when there is a new rearrangement
For example , I would like to rearrange the position of photo4 , the original order is like below
1 photo1
2 photo2
3 photo3
4 [photo4]
1 [photo4]
2 photo1 (order_no need to be changed from 1 to 2)
3 photo2 (order_no need to be changed from 2 to 3)
4 photo3 (order_no need to be changed from 3 to 4)
Is there a consistent way to implement this ?
Thanks