This is the repo that holds all the SQL queries used in this project (creating the database, seeding it with test data, and 10 queries for testing).
- Create a new Postgres database (can be done through pgAdmin).
- Run all the queries in the
ddl.sql
file to create all the tables needed. - Run all the queries in the
seed.sql
file to insert test data into the database. - To test this database, you can use the 10 queries written in the
queries.sql
, with each having a description of what they do.
These are the general assumptions I made when approaching this assignment:
- Every gym member, trainer, and admin have an account, and that account is strored in the
users
table. To differencitate them, a colunm namedaccount_type
is used. - Only members have loyalty points, and since I didn't to have a
loyalty_points
colunm in theusers
table that would benull
for trainers and admin, I decided to create a seperate table (loyalty_points
) that refereces the user through itsmember_id
colunm - Events (stored in the
events
) take place in a room (in therooms
table). This is done through theroom_id
in theevents
table. - Multiple users can attend multiple events (i.e. multiple people can attend the same event as well), so a join table
users_events
is use that references theuser_id
andevent_id
. - A single member can have many health goals, and this reflected in the
health_goals
table referencing theuser
through itsuser_id
. - Multiple members can do multiple workouts (stored in the
workouts
table). This is done through theusers_workouts
table by referencing theworkout_id
anduser_id
. Since users can also write notes based on the workouts, it made sense to put thenotes
colunm on theusers_workouts
table itself, since thenotes
belongs to the user in relation to the workout and not the workout itself. - Members can also have multiple training sessionis with multiple trainers (and multiple members can be in the same session). This is done by having a
users_sessions
table that refences the member throughmemeber_id
and the trainer throughtrainer_id
.