I have to design a database schema for new project. I will use PostgreSQL for the implementation of the schema.
Right now I'm stuck in a scenario where I need to handle foreign keys based on type and id. Here are the tables:
Passenger:
PassengerID
FirstName
Email
DOB
Address
Driver:
DriverID
CNIC
Vehicle
License
Status
Wallet:
WalledID
Amount
UserId
UserType
Problem: I want that every wallet row should have UserId as DriverId or PassengerID and in the type field the name of the table.
How can I achieve this with PostgreSQL? I have heard that it is possible from polymorphic association but don't know how to implement it.