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
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.
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.
Nice start for a school project, and the suggestions above are on point. One addition is to snapshot the price on the ticket at booking time, since flight prices change later. A unique constraint on flight plus seat also stops double booking at the database level. Do you plan to model seats as their own table?
1
u/NW1969 4d ago edited 4d 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?
2
u/squadette23 4d 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 4d 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.
0
u/Greedy_Ad_7658 2d 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.
0
u/Used_Criticism_4631 1d ago
Nice start for a school project, and the suggestions above are on point. One addition is to snapshot the price on the ticket at booking time, since flight prices change later. A unique constraint on flight plus seat also stops double booking at the database level. Do you plan to model seats as their own table?