| 1 | set search_path = project;
|
|---|
| 2 |
|
|---|
| 3 | drop table if exists UserHasProgram;
|
|---|
| 4 | drop table if exists UserHasDays;
|
|---|
| 5 | drop table if exists DayHasMeal;
|
|---|
| 6 | drop table if exists MealHasIngredient;
|
|---|
| 7 | drop table if exists DayHasWorkout;
|
|---|
| 8 | drop table if exists WorkoutHasExercise;
|
|---|
| 9 | drop table if exists WorkoutProgramHasWorkout;
|
|---|
| 10 | drop table if exists PersIngrsIsOfType;
|
|---|
| 11 | drop table if exists PersExerIsOfType;
|
|---|
| 12 |
|
|---|
| 13 | drop table if exists Meal;
|
|---|
| 14 | drop table if exists Workout;
|
|---|
| 15 | drop table if exists _Day cascade;
|
|---|
| 16 | drop table if exists _User cascade;
|
|---|
| 17 | drop table if exists PersonalizedIngredient;
|
|---|
| 18 | drop table if exists Ingredient;
|
|---|
| 19 | drop table if exists PersonalizedExercise;
|
|---|
| 20 | drop table if exists Exercise;
|
|---|
| 21 | drop table if exists WorkoutProgram;
|
|---|
| 22 |
|
|---|
| 23 | drop schema if exists project cascade;
|
|---|
| 24 |
|
|---|
| 25 | create schema project;
|
|---|
| 26 |
|
|---|
| 27 | set search_path = project;
|
|---|
| 28 |
|
|---|
| 29 | create table _User (
|
|---|
| 30 | uID bigint primary key,
|
|---|
| 31 | name VARCHAR(255) not null unique,
|
|---|
| 32 | password VARCHAR(255) not null,
|
|---|
| 33 | age integer not null,
|
|---|
| 34 | height integer,
|
|---|
| 35 | weight integer,
|
|---|
| 36 | role VARCHAR(255)
|
|---|
| 37 | );
|
|---|
| 38 |
|
|---|
| 39 | create table _Day (
|
|---|
| 40 | dID bigint primary key,
|
|---|
| 41 | date date not null
|
|---|
| 42 | );
|
|---|
| 43 |
|
|---|
| 44 | create table Workout (
|
|---|
| 45 | wID bigint primary key,
|
|---|
| 46 | duration integer,
|
|---|
| 47 | name VARCHAR(255)
|
|---|
| 48 | );
|
|---|
| 49 |
|
|---|
| 50 | create table Meal (
|
|---|
| 51 | mID bigint primary key,
|
|---|
| 52 | name VARCHAR(255) not null,
|
|---|
| 53 | type VARCHAR(255) not null,
|
|---|
| 54 | uID BIGINT,
|
|---|
| 55 | foreign key (uID) references _User(uID)
|
|---|
| 56 | );
|
|---|
| 57 |
|
|---|
| 58 | create table Ingredient (
|
|---|
| 59 | iID bigint primary key,
|
|---|
| 60 | name VARCHAR(255) not null,
|
|---|
| 61 | calories integer not null,
|
|---|
| 62 | protein integer not null,
|
|---|
| 63 | carbs integer not null,
|
|---|
| 64 | fats integer not null
|
|---|
| 65 | );
|
|---|
| 66 |
|
|---|
| 67 | create table PersonalizedIngredient (
|
|---|
| 68 | piID bigint primary key,
|
|---|
| 69 | quantity integer not null
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | create table PersIngrsIsOfType (
|
|---|
| 73 | iID bigint references Ingredient(iID),
|
|---|
| 74 | piID bigint references PersonalizedIngredient(piID),
|
|---|
| 75 |
|
|---|
| 76 | constraint PersIngrsIsOfType_pkey primary key (piID, iID)
|
|---|
| 77 | );
|
|---|
| 78 |
|
|---|
| 79 | create table Exercise (
|
|---|
| 80 | eID bigint primary key,
|
|---|
| 81 | name VARCHAR(255) not null,
|
|---|
| 82 | type VARCHAR(255) not null
|
|---|
| 83 | );
|
|---|
| 84 |
|
|---|
| 85 | create table PersonalizedExercise (
|
|---|
| 86 | peID bigint primary key,
|
|---|
| 87 | reps integer,
|
|---|
| 88 | sets integer,
|
|---|
| 89 | weight integer,
|
|---|
| 90 | time integer
|
|---|
| 91 | );
|
|---|
| 92 |
|
|---|
| 93 | create table PersExerIsOfType (
|
|---|
| 94 | eID bigint references Exercise(eID),
|
|---|
| 95 | peID bigint references PersonalizedExercise(peID),
|
|---|
| 96 |
|
|---|
| 97 | constraint PersExerIsOfType_pkey primary key (peID, eID)
|
|---|
| 98 | );
|
|---|
| 99 |
|
|---|
| 100 | create table WorkoutProgram (
|
|---|
| 101 | wpID bigint primary key,
|
|---|
| 102 | name VARCHAR(255) not null
|
|---|
| 103 | );
|
|---|
| 104 |
|
|---|
| 105 | create table UserHasDays(
|
|---|
| 106 | uID bigint references _User(uID),
|
|---|
| 107 | dID bigint references _Day(dID),
|
|---|
| 108 |
|
|---|
| 109 | constraint UserHasDays_pkey primary key (dID, uID)
|
|---|
| 110 | );
|
|---|
| 111 |
|
|---|
| 112 | create table UserHasProgram(
|
|---|
| 113 | uID bigint references _User(uID),
|
|---|
| 114 | wpID bigint references WorkoutProgram(wpID),
|
|---|
| 115 |
|
|---|
| 116 | constraint UserHasProgram_pkey primary key (wpID, uID)
|
|---|
| 117 | );
|
|---|
| 118 |
|
|---|
| 119 | create table DayHasWorkout(
|
|---|
| 120 | wID bigint references Workout(wID),
|
|---|
| 121 | dID bigint references _Day(dID),
|
|---|
| 122 |
|
|---|
| 123 | constraint DayHasWorkout_pkey primary key (wID, dID)
|
|---|
| 124 | );
|
|---|
| 125 |
|
|---|
| 126 | create table WorkoutProgramHasWorkout(
|
|---|
| 127 | wID bigint references Workout(wID),
|
|---|
| 128 | wpID bigint references WorkoutProgram(wpID),
|
|---|
| 129 |
|
|---|
| 130 | constraint WorkoutProgramHasWorkout_pkey primary key (wpID, wID)
|
|---|
| 131 | );
|
|---|
| 132 |
|
|---|
| 133 | create table DayHasMeal(
|
|---|
| 134 | mID bigint references Meal(mID),
|
|---|
| 135 | dID bigint references _Day(dID),
|
|---|
| 136 |
|
|---|
| 137 | constraint DayHasMeal_pkey primary key (dID, mID)
|
|---|
| 138 | );
|
|---|
| 139 |
|
|---|
| 140 | create table MealHasIngredient(
|
|---|
| 141 | mID bigint references Meal(mID),
|
|---|
| 142 | piID bigint references PersonalizedIngredient(piID),
|
|---|
| 143 |
|
|---|
| 144 | constraint MealHasIngredient_pkey primary key (piID, mID)
|
|---|
| 145 | );
|
|---|
| 146 |
|
|---|
| 147 | create table WorkoutHasExercise(
|
|---|
| 148 | peID bigint references PersonalizedExercise(peID),
|
|---|
| 149 | wID bigint references Workout(wID),
|
|---|
| 150 |
|
|---|
| 151 | constraint WorkoutHasExercise_pkey primary key (peID, wID)
|
|---|
| 152 | );
|
|---|
| 153 |
|
|---|
| 154 | CREATE SEQUENCE _user_seq START 1;
|
|---|
| 155 | CREATE SEQUENCE _day_seq START 1;
|
|---|
| 156 | CREATE SEQUENCE _workout_seq START 1;
|
|---|
| 157 | CREATE SEQUENCE _meal_seq START 1;
|
|---|
| 158 | CREATE SEQUENCE _ingredient_seq START 1;
|
|---|
| 159 | CREATE SEQUENCE _personalized_ingredient_seq START 1;
|
|---|
| 160 | CREATE SEQUENCE _exercise_seq START 1;
|
|---|
| 161 | CREATE SEQUENCE _personalized_exercise_seq START 1;
|
|---|
| 162 | CREATE SEQUENCE _workout_program_seq START 1;
|
|---|
| 163 | CREATE SEQUENCE _pers_ingrs_is_of_type_seq START 1;
|
|---|
| 164 | CREATE SEQUENCE _pers_exer_is_of_type_seq START 1;
|
|---|