| 1 | create table user_table(
|
|---|
| 2 | id_user serial primary key,
|
|---|
| 3 | date_created_user date not null,
|
|---|
| 4 | name_user varchar(100) not null,
|
|---|
| 5 | email_user varchar(100) not null unique,
|
|---|
| 6 | password_user varchar(20) not null,
|
|---|
| 7 | telephone_user varchar(20)
|
|---|
| 8 | );
|
|---|
| 9 |
|
|---|
| 10 | create table surendee(
|
|---|
| 11 | id_user integer primary key,
|
|---|
| 12 | constraint fk_surendee_id_user foreign key (id_user)
|
|---|
| 13 | references user_table (id_user) on delete cascade
|
|---|
| 14 | );
|
|---|
| 15 |
|
|---|
| 16 | create table admin_table(
|
|---|
| 17 | id_user integer primary key,
|
|---|
| 18 | constraint fk_admin_table_id_user foreign key (id_user)
|
|---|
| 19 | references user_table (id_user) on delete cascade
|
|---|
| 20 | );
|
|---|
| 21 |
|
|---|
| 22 | create table donor(
|
|---|
| 23 | id_user integer primary key,
|
|---|
| 24 | is_from_organisation bool not null,
|
|---|
| 25 | name_organisation_donor varchar(100),
|
|---|
| 26 | constraint fk_donor_id_user foreign key (id_user)
|
|---|
| 27 | references user_table (id_user) on delete cascade
|
|---|
| 28 | );
|
|---|
| 29 |
|
|---|
| 30 | create table organisation(
|
|---|
| 31 | id_organisation serial primary key,
|
|---|
| 32 | name_organisation varchar(100) not null,
|
|---|
| 33 | email_organisation varchar(100) not null unique,
|
|---|
| 34 | billing_information varchar(20) not null unique
|
|---|
| 35 | );
|
|---|
| 36 |
|
|---|
| 37 | create table shelter(
|
|---|
| 38 | id_shelter serial primary key,
|
|---|
| 39 | address_shelter varchar(100) not null,
|
|---|
| 40 | telephone_shelter varchar(20) not null,
|
|---|
| 41 | id_organisation integer,
|
|---|
| 42 | name_shelter varchar(100) not null,
|
|---|
| 43 | email_shelter varchar(100) not null unique,
|
|---|
| 44 | constraint fk_shelter_organisation foreign key (id_organisation)
|
|---|
| 45 | references organisation (id_organisation)
|
|---|
| 46 | );
|
|---|
| 47 |
|
|---|
| 48 | create table employee(
|
|---|
| 49 | id_user integer primary key,
|
|---|
| 50 | position_employee varchar(20) not null,
|
|---|
| 51 | id_shelter integer not null,
|
|---|
| 52 | is_verified bool not null,
|
|---|
| 53 | verified_by_admin integer,
|
|---|
| 54 | constraint fk_employee_id_user foreign key (id_user)
|
|---|
| 55 | references user_table (id_user) on delete cascade,
|
|---|
| 56 | constraint fk_employee_id_shelter foreign key (id_shelter)
|
|---|
| 57 | references shelter (id_shelter) on delete cascade,
|
|---|
| 58 | constraint fk_employee_id_admin foreign key (verified_by_admin)
|
|---|
| 59 | references admin_table (id_user)
|
|---|
| 60 | );
|
|---|
| 61 |
|
|---|
| 62 | create table adopter(
|
|---|
| 63 | id_user integer primary key,
|
|---|
| 64 | free_time integer,
|
|---|
| 65 | funds integer,
|
|---|
| 66 | has_other_pets bool,
|
|---|
| 67 | has_kids bool,
|
|---|
| 68 | housing integer,
|
|---|
| 69 | physical_activity_adopters integer,
|
|---|
| 70 | will_foster bool,
|
|---|
| 71 | is_verified bool not null,
|
|---|
| 72 | verified_by_employee integer,
|
|---|
| 73 | constraint fk_adopter_id_user foreign key (id_user)
|
|---|
| 74 | references user_table (id_user) on delete cascade,
|
|---|
| 75 | constraint fk_adopter_id_employee foreign key (verified_by_employee)
|
|---|
| 76 | references employee (id_user)
|
|---|
| 77 | );
|
|---|
| 78 |
|
|---|
| 79 | create table adoption(
|
|---|
| 80 | id_adoption serial primary key,
|
|---|
| 81 | start_date date not null,
|
|---|
| 82 | end_date_foster date,
|
|---|
| 83 | approved bool not null,
|
|---|
| 84 | id_adopter integer not null,
|
|---|
| 85 | constraint fk_adoption_adopter foreign key (id_adopter)
|
|---|
| 86 | references adopter(id_user)
|
|---|
| 87 | );
|
|---|
| 88 |
|
|---|
| 89 | create table pet(
|
|---|
| 90 | id_pet serial primary key,
|
|---|
| 91 | url_pet_image varchar(200) ,
|
|---|
| 92 | age_group integer not null,
|
|---|
| 93 | size_pet integer not null,
|
|---|
| 94 | breed varchar(100) ,
|
|---|
| 95 | name_pet varchar(20) ,
|
|---|
| 96 | species integer not null,
|
|---|
| 97 | gender integer not null,
|
|---|
| 98 | can_be_fostered bool not null,
|
|---|
| 99 | id_adoption integer,
|
|---|
| 100 | id_shelter integer,
|
|---|
| 101 | constraint fk_pet_adoption foreign key (id_adoption)
|
|---|
| 102 | references adoption(id_adoption),
|
|---|
| 103 | constraint fk_pet_shelter foreign key (id_shelter)
|
|---|
| 104 | references shelter(id_shelter)
|
|---|
| 105 | );
|
|---|
| 106 |
|
|---|
| 107 | create table post(
|
|---|
| 108 | id_post serial primary key,
|
|---|
| 109 | date_post date not null,
|
|---|
| 110 | url_thumbanail varchar(200),
|
|---|
| 111 | id_pet integer not null,
|
|---|
| 112 | id_surendee integer,
|
|---|
| 113 | id_employee integer,
|
|---|
| 114 | constraint fk_post_pet foreign key (id_pet)
|
|---|
| 115 | references pet (id_pet) on delete cascade,
|
|---|
| 116 | constraint fk_post_surendee foreign key (id_surendee)
|
|---|
| 117 | references surendee (id_user),
|
|---|
| 118 | constraint fk_post_employee foreign key (id_employee)
|
|---|
| 119 | references employee (id_user),
|
|---|
| 120 | constraint chk_post_poster check (
|
|---|
| 121 | (id_surendee is not null and id_employee is null)
|
|---|
| 122 | or
|
|---|
| 123 | (id_surendee is null and id_employee is not null)
|
|---|
| 124 | )
|
|---|
| 125 | );
|
|---|
| 126 |
|
|---|
| 127 | create table category(
|
|---|
| 128 | id_category serial primary key,
|
|---|
| 129 | name_category varchar(100) not null
|
|---|
| 130 | );
|
|---|
| 131 |
|
|---|
| 132 | create table food(
|
|---|
| 133 | id_food serial primary key,
|
|---|
| 134 | manufacturer varchar(100) not null,
|
|---|
| 135 | name_food varchar(20) not null,
|
|---|
| 136 | type_food integer not null
|
|---|
| 137 | );
|
|---|
| 138 |
|
|---|
| 139 | create table therapy(
|
|---|
| 140 | id_therapy serial primary key,
|
|---|
| 141 | health_problem varchar(100) not null,
|
|---|
| 142 | start_date date,
|
|---|
| 143 | end_date date
|
|---|
| 144 | );
|
|---|
| 145 |
|
|---|
| 146 | create table vet_clinic(
|
|---|
| 147 | id_vet_clinic serial primary key,
|
|---|
| 148 | telephone_vet_clinic varchar(20) not null,
|
|---|
| 149 | address_vet_clinic varchar(100) not null,
|
|---|
| 150 | name_vet_clinic varchar(100) not null
|
|---|
| 151 | );
|
|---|
| 152 |
|
|---|
| 153 | create table personal_profile(
|
|---|
| 154 | id_pet integer primary key,
|
|---|
| 155 | friendly_to_kids integer not null,
|
|---|
| 156 | friendly_to_pets integer not null,
|
|---|
| 157 | attention integer not null,
|
|---|
| 158 | physical_activity integer not null,
|
|---|
| 159 | grooming_needed integer not null,
|
|---|
| 160 | constraint fk_personal_profile_id_pet foreign key (id_pet)
|
|---|
| 161 | references pet (id_pet) on delete cascade
|
|---|
| 162 | );
|
|---|
| 163 |
|
|---|
| 164 | create table donor_donates_to_organisation(
|
|---|
| 165 | id_user integer not null,
|
|---|
| 166 | id_organisation integer not null,
|
|---|
| 167 | constraint pk_donor_donates_to_organisation primary key
|
|---|
| 168 | (id_user, id_organisation),
|
|---|
| 169 | constraint fk_donor_donates_to_organisation_user foreign key (id_user)
|
|---|
| 170 | references donor(id_user) on delete cascade,
|
|---|
| 171 | constraint fk_donor_donates_to_organisation_organisation foreign key (id_organisation)
|
|---|
| 172 | references organisation(id_organisation) on delete cascade
|
|---|
| 173 | );
|
|---|
| 174 |
|
|---|
| 175 | create table pet_belongs_to_category(
|
|---|
| 176 | id_pet integer not null,
|
|---|
| 177 | id_category integer not null,
|
|---|
| 178 | constraint pk_pet_belongs_to_category primary key
|
|---|
| 179 | (id_pet, id_category),
|
|---|
| 180 | constraint fk_pet_belongs_to_category_pet foreign key (id_pet)
|
|---|
| 181 | references pet(id_pet) on delete cascade,
|
|---|
| 182 | constraint fk_pet_belongs_to_category_category foreign key (id_category)
|
|---|
| 183 | references category(id_category) on delete cascade
|
|---|
| 184 | );
|
|---|
| 185 |
|
|---|
| 186 | create table pet_needs_therapy(
|
|---|
| 187 | id_pet integer not null,
|
|---|
| 188 | id_therapy integer not null,
|
|---|
| 189 | constraint pk_pet_needs_therapy primary key
|
|---|
| 190 | (id_pet, id_therapy),
|
|---|
| 191 | constraint fk_pet_needs_therapy_pet foreign key (id_pet)
|
|---|
| 192 | references pet(id_pet) on delete cascade,
|
|---|
| 193 | constraint fk_pet_needs_therapy_therapy foreign key (id_therapy)
|
|---|
| 194 | references therapy(id_therapy) on delete cascade
|
|---|
| 195 | );
|
|---|
| 196 |
|
|---|
| 197 | create table pet_preferably_eats_food(
|
|---|
| 198 | id_pet integer not null,
|
|---|
| 199 | id_food integer not null,
|
|---|
| 200 | quantity_a_day integer not null,
|
|---|
| 201 | constraint pk_pet_preferably_eats_food primary key
|
|---|
| 202 | (id_pet, id_food),
|
|---|
| 203 | constraint fk_pet_preferably_eats_food_pet foreign key (id_pet)
|
|---|
| 204 | references pet(id_pet) on delete cascade,
|
|---|
| 205 | constraint fk_pet_preferably_eats_food_food foreign key (id_food)
|
|---|
| 206 | references food(id_food) on delete cascade
|
|---|
| 207 | );
|
|---|
| 208 |
|
|---|
| 209 | create table pet_needs_intervention_in_vet_clinic(
|
|---|
| 210 | id_pet integer not null,
|
|---|
| 211 | id_vet_clinic integer not null,
|
|---|
| 212 | date_of_interventing date not null,
|
|---|
| 213 | description varchar(100),
|
|---|
| 214 | constraint pk_pet_needs_intervention_in_vet_clinic primary key
|
|---|
| 215 | (id_pet, id_vet_clinic),
|
|---|
| 216 | constraint fk_pet_needs_intervention_in_vet_clinic_pet foreign key (id_pet)
|
|---|
| 217 | references pet(id_pet) on delete cascade,
|
|---|
| 218 | constraint fk_pet_needs_intervention_in_vet_clinic_vet_clinic foreign key (id_vet_clinic)
|
|---|
| 219 | references vet_clinic(id_vet_clinic) on delete cascade
|
|---|
| 220 | );
|
|---|
| 221 |
|
|---|