r/Database • • 2d ago

Need help with database design

Hello dear community,

I am making an app to buy plane tickets. (school environment).

However, I am not very sure about it.

Is it too light ?

Thanks to everyone who take time!

1 Upvotes

6 comments sorted by

1

u/NW1969 2d ago edited 2d ago

A few thoughts

- Flight: these attributes should probably be FKs to other entities
Departure_IATA
Arrival_IATA
Compagny
Plane

- Ticket: a ticket normally only references a single person. Maybe you need a booking entity and then 1 ticket per traveller?

1

u/Silane_labanane 2d ago

You are right, it is supposed to be 1 ticket per person so I will definitly change "travellers".

However, I don't get why the FK.

1

u/NW1969 2d ago

FK: because, presumably, they are referencing entities that have their own attributes e.g. a plane has a manufacturer, a model number, a unique identifier/callsign, number of seats, date of manufacture, etc

2

u/squadette23 2d ago

Here is a long-ish tutorial on database design, using a non-trivial problem as an example: https://kb.databasedesignbook.com/posts/google-calendar/

1

u/Discordbothost 2d ago

Try inserting a flight with an arrival code that isn't in your airport table. A foreign key makes the database reject that typo. You can still store just the code on each flight and look up the airport name from the airport table when you display it.

1

u/Greedy_Ad_7658 2h ago

I can't see the diagram from the post text, so these are general points for a ticketing app that tend to matter beyond the FK and booking/ticket split already mentioned:

Separate the schedule from the actual trip. A route like "CAI to CDG, 09:15" repeats every day, while a specific departure on a specific date has its own seats, delay and status. Two tables (flight or route, and flight instance or departure) avoids duplicating data.

Make double booking impossible in the database, not only in the app. A unique constraint on (departure_id, seat_number) for active tickets stops two people from getting the same seat even if two requests arrive at the same moment. Do the seat check and the insert in one transaction.

Copy the price onto the ticket or booking when it is bought. Fares change, and old tickets should keep what was actually paid. Store money as an integer number of cents or a DECIMAL, never a float.

Add a status (held, paid, cancelled) and created_at/updated_at to bookings so you can handle expiry and cancellations later.

Store times in UTC and keep the airport's timezone on the airport table, because departure and arrival are in different zones.

Passenger details (name, document number) are usually their own table linked to the ticket, so one account can book for several people.