| 1 | set
|
|---|
| 2 | search_path = project;
|
|---|
| 3 | --Create DB Shema
|
|---|
| 4 | drop schema if exists project cascade;
|
|---|
| 5 |
|
|---|
| 6 | create schema project;
|
|---|
| 7 |
|
|---|
| 8 | drop table if exists cities cascade;
|
|---|
| 9 | drop table if exists vet_centers cascade;
|
|---|
| 10 | drop table if exists jobs cascade;
|
|---|
| 11 | drop table if exists blog_post_for_consultations cascade;
|
|---|
| 12 | drop table if exists blog_post_answers cascade;
|
|---|
| 13 | drop table if exists pet_cares cascade;
|
|---|
| 14 | drop table if exists type_of_pets cascade;
|
|---|
| 15 | drop table if exists pets cascade;
|
|---|
| 16 | drop table if exists pet_galery cascade;
|
|---|
| 17 | drop table if exists reports cascade;
|
|---|
| 18 | drop table if exists diagnostics cascade;
|
|---|
| 19 | drop table if exists manufacturers cascade;
|
|---|
| 20 | drop table if exists medecines cascade;
|
|---|
| 21 | drop table if exists pet_status cascade;
|
|---|
| 22 | drop table if exists therapy cascade;
|
|---|
| 23 | drop table if exists breeds cascade;
|
|---|
| 24 | drop table if exists products cascade;
|
|---|
| 25 | drop table if exists orders cascade;
|
|---|
| 26 | drop table if exists pets_visit_vet_centers cascade;
|
|---|
| 27 | drop table if exists products_there_are_for_pets cascade;
|
|---|
| 28 | drop table if exists product_are_made_orders cascade;
|
|---|
| 29 | drop table if exists products_available_type_of_pets cascade;
|
|---|
| 30 | drop table if exists therapy_takes_pets cascade;
|
|---|
| 31 | drop table if exists users cascade;
|
|---|
| 32 | drop table if exists roles cascade;
|
|---|
| 33 | --Create Tables
|
|---|
| 34 | create table cities(
|
|---|
| 35 | ID SERIAL,
|
|---|
| 36 | name varchar(50),
|
|---|
| 37 | adress varchar(50),
|
|---|
| 38 | phoneNumber varchar(20),
|
|---|
| 39 | constraint pk_cities primary key (ID)
|
|---|
| 40 | );
|
|---|
| 41 |
|
|---|
| 42 | create table vet_centers(
|
|---|
| 43 | ID SERIAL,
|
|---|
| 44 | name varchar(50),
|
|---|
| 45 | description varchar(150),
|
|---|
| 46 | adress varchar(50),
|
|---|
| 47 | phoneNumber varchar(15),
|
|---|
| 48 | latitude decimal,
|
|---|
| 49 | longitude decimal,
|
|---|
| 50 | workingHours varchar(50),
|
|---|
| 51 | constraint pk_vetcen primary key (ID),
|
|---|
| 52 | citiesID bigint not null,
|
|---|
| 53 | constraint fk_cities foreign key (citiesID) references cities(ID)
|
|---|
| 54 | );
|
|---|
| 55 |
|
|---|
| 56 | create table jobs(
|
|---|
| 57 | ID SERIAL,
|
|---|
| 58 | description varchar(50),
|
|---|
| 59 | predictedSalery varchar(30),
|
|---|
| 60 | constraint pk_jjobs primary key (ID),
|
|---|
| 61 | vetCentersID bigint not null,
|
|---|
| 62 | constraint fk_vetCenters foreign key ( vetCentersID) references vet_centers(ID)
|
|---|
| 63 |
|
|---|
| 64 | );
|
|---|
| 65 |
|
|---|
| 66 | create table roles(
|
|---|
| 67 | ID SERIAL,
|
|---|
| 68 | type varchar(15) not null unique,
|
|---|
| 69 | constraint pk_roles primary key (ID)
|
|---|
| 70 | );
|
|---|
| 71 |
|
|---|
| 72 | create table users(
|
|---|
| 73 | ID SERIAL,
|
|---|
| 74 | name varchar(30) not null,
|
|---|
| 75 | lastname varchar(30) not null,
|
|---|
| 76 | email varchar(30) not null unique,
|
|---|
| 77 | password varchar(30) not null unique,
|
|---|
| 78 | number varchar(15) not null unique,
|
|---|
| 79 | role_id bigint not null,
|
|---|
| 80 | jobs_id bigint default null,
|
|---|
| 81 | constraint pk_users primary key (ID),
|
|---|
| 82 | constraint fk_roles foreign key (role_id) references roles(ID),
|
|---|
| 83 | constraint fk_jobs foreign key (jobs_id) references jobs(ID)
|
|---|
| 84 |
|
|---|
| 85 | );
|
|---|
| 86 |
|
|---|
| 87 | create table blog_post_for_consultations(
|
|---|
| 88 | ID SERIAL,
|
|---|
| 89 | date_askes date,
|
|---|
| 90 | title varchar(30),
|
|---|
| 91 | description varchar(150),
|
|---|
| 92 | users_id bigint not null,
|
|---|
| 93 | constraint pk_blogPFC primary key (ID),
|
|---|
| 94 | constraint fk_users foreign key (users_id) references users(ID)
|
|---|
| 95 | );
|
|---|
| 96 | create table blog_post_answers(
|
|---|
| 97 | ID SERIAL,
|
|---|
| 98 | parent_id bigint,
|
|---|
| 99 | reply varchar(150),
|
|---|
| 100 | blogPostConsID bigint not null,
|
|---|
| 101 | usersID bigint not null,
|
|---|
| 102 | constraint pk_blogPA primary key (ID),
|
|---|
| 103 | constraint fk_blogBPFC foreign key (blogPostConsID) references blog_post_for_consultations(ID),
|
|---|
| 104 | constraint fk_users foreign key (usersID) references users(ID)
|
|---|
| 105 | );
|
|---|
| 106 |
|
|---|
| 107 | create table pet_cares(
|
|---|
| 108 | ID SERIAL,
|
|---|
| 109 | title varchar(50),
|
|---|
| 110 | description varchar(150),
|
|---|
| 111 | dateending date not null,
|
|---|
| 112 | constraint pk_petCares primary key (ID),
|
|---|
| 113 | usersID bigint not null,
|
|---|
| 114 | vetcentersID bigint not null,
|
|---|
| 115 | constraint fk_blogBPFC foreign key (usersID) references users(ID),
|
|---|
| 116 | constraint fk_vetCenters foreign key (vetcentersID) references vet_centers(ID)
|
|---|
| 117 | );
|
|---|
| 118 |
|
|---|
| 119 | create table type_of_pets(
|
|---|
| 120 | ID SERIAL,
|
|---|
| 121 | description varchar(30),
|
|---|
| 122 | name varchar(30),
|
|---|
| 123 | constraint pk_typeOfPets primary key (ID)
|
|---|
| 124 |
|
|---|
| 125 | );
|
|---|
| 126 |
|
|---|
| 127 | create table pets(
|
|---|
| 128 | ID SERIAL,
|
|---|
| 129 | color varchar(20),
|
|---|
| 130 | description varchar(50),
|
|---|
| 131 | dateOfBirthday date,
|
|---|
| 132 | constraint pk_pets primary key (ID),
|
|---|
| 133 | usersID bigint not null,
|
|---|
| 134 | typeOfPetsID bigint not null,
|
|---|
| 135 | constraint fk_typeOfPets foreign key (typeOfPetsID) references type_of_pets(ID),
|
|---|
| 136 | constraint fk_users foreign key (usersID) references users(ID)
|
|---|
| 137 | );
|
|---|
| 138 |
|
|---|
| 139 | create table pet_galery(
|
|---|
| 140 | ID SERIAL,
|
|---|
| 141 | picture varchar(1000),
|
|---|
| 142 | constraint pk_petGalery primary key (ID),
|
|---|
| 143 | petsID bigint not null,
|
|---|
| 144 | constraint fk_pets foreign key (petsID) references pets(ID)
|
|---|
| 145 | );
|
|---|
| 146 | create table reports(
|
|---|
| 147 | ID SERIAL,
|
|---|
| 148 | description varchar(150),
|
|---|
| 149 | constraint pk_reports primary key (ID),
|
|---|
| 150 | usersID bigint not null,
|
|---|
| 151 | petsID bigint not null,
|
|---|
| 152 | constraint fk_users foreign key (usersID) references users(ID),
|
|---|
| 153 | constraint fk_pets foreign key (petsID) references pets(ID)
|
|---|
| 154 | );
|
|---|
| 155 |
|
|---|
| 156 | create table diagnostics(
|
|---|
| 157 | ID SERIAL,
|
|---|
| 158 | description varchar(200),
|
|---|
| 159 | constraint pk_diagnostics primary key (ID),
|
|---|
| 160 | usersID bigint not null,
|
|---|
| 161 | constraint fk_users foreign key (usersID) references users(ID)
|
|---|
| 162 | );
|
|---|
| 163 |
|
|---|
| 164 | create table manufacturers(
|
|---|
| 165 | ID SERIAL,
|
|---|
| 166 | name varchar(50) not null,
|
|---|
| 167 | description varchar(200),
|
|---|
| 168 | city varchar(50),
|
|---|
| 169 | state varchar(50),
|
|---|
| 170 | constraint pk_manufacturers primary key (ID)
|
|---|
| 171 |
|
|---|
| 172 | );
|
|---|
| 173 |
|
|---|
| 174 | create table medecines(
|
|---|
| 175 | ID SERIAL,
|
|---|
| 176 | name varchar(50) not null,
|
|---|
| 177 | description varchar(200),
|
|---|
| 178 | constraint pk_medecines primary key (ID),
|
|---|
| 179 | diagnosticsID bigint not null,
|
|---|
| 180 | manufacturersID bigint not null,
|
|---|
| 181 | constraint fk_diagnostics foreign key (diagnosticsID) references diagnostics(ID),
|
|---|
| 182 | constraint fk_manufacturers foreign key (manufacturersID) references manufacturers(ID)
|
|---|
| 183 | );
|
|---|
| 184 |
|
|---|
| 185 | create table pet_status(
|
|---|
| 186 | ID SERIAL,
|
|---|
| 187 | type varchar(30),
|
|---|
| 188 | node varchar(200),
|
|---|
| 189 | constraint pk_pet_status primary key (ID)
|
|---|
| 190 | );
|
|---|
| 191 |
|
|---|
| 192 | create table therapy(
|
|---|
| 193 | ID SERIAL,
|
|---|
| 194 | description varchar(150),
|
|---|
| 195 | appoitmentDate date,
|
|---|
| 196 | constraint pk_therapy primary key (ID),
|
|---|
| 197 | diagnosticsID bigint not null,
|
|---|
| 198 | pet_statusID bigint not null,
|
|---|
| 199 | constraint fk_pet_status foreign key (pet_statusID) references pet_status(ID),
|
|---|
| 200 | constraint fk_diagnostics foreign key (diagnosticsID) references diagnostics(ID)
|
|---|
| 201 | );
|
|---|
| 202 |
|
|---|
| 203 | create table breeds(
|
|---|
| 204 | ID SERIAL,
|
|---|
| 205 | name varchar(50),
|
|---|
| 206 | constraint pk_breeds primary key(ID),
|
|---|
| 207 | constraint fk_type_of_pets foreign key (ID) references type_of_pets(ID) on delete cascade
|
|---|
| 208 | );
|
|---|
| 209 |
|
|---|
| 210 | create table products(
|
|---|
| 211 | ID SERIAL,
|
|---|
| 212 | name varchar(50),
|
|---|
| 213 | description varchar(150),
|
|---|
| 214 | price varchar(50),
|
|---|
| 215 | isActive bool,
|
|---|
| 216 | dateAdded date,
|
|---|
| 217 | category varchar(50),
|
|---|
| 218 | constraint pk_products primary key (ID)
|
|---|
| 219 | );
|
|---|
| 220 |
|
|---|
| 221 | create table orders(
|
|---|
| 222 | ID SERIAL,
|
|---|
| 223 | quantity int,
|
|---|
| 224 | constraint pk_orders primary key(ID)
|
|---|
| 225 | );
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 | create table pets_visit_vet_centers(
|
|---|
| 229 | id_pets bigint not null,
|
|---|
| 230 | id_vet_centers bigint not null,
|
|---|
| 231 | constraint pk_pets_visit_vet_centers primary key (id_pets, id_vet_centers),
|
|---|
| 232 | constraint fk_pet_visit_vet_centers_pet foreign key (id_pets) references pets(ID) on delete cascade,
|
|---|
| 233 | constraint fk_pet_visit_vet_centers_vetcenters foreign key (id_vet_centers) references vet_centers(ID) on delete cascade
|
|---|
| 234 | );
|
|---|
| 235 |
|
|---|
| 236 | create table products_there_are_for_pets(
|
|---|
| 237 | id_products bigint not null,
|
|---|
| 238 | id_pets bigint not null,
|
|---|
| 239 | constraint pk_products_there_are_for_pets primary key (id_products, id_pets),
|
|---|
| 240 | constraint fk_products_there_are_for_pets_pets foreign key (id_pets) references pets(ID) on delete cascade,
|
|---|
| 241 | constraint fk_products_there_are_for_pets_products foreign key (id_products) references products(ID) on delete cascade
|
|---|
| 242 | );
|
|---|
| 243 |
|
|---|
| 244 | create table product_are_made_orders(
|
|---|
| 245 | id_products bigint not null,
|
|---|
| 246 | id_orders bigint not null,
|
|---|
| 247 | constraint pk_product_are_made_orders primary key (id_products, id_orders),
|
|---|
| 248 | constraint fk_product_are_made_orders_product foreign key (id_products) references products(ID) on delete cascade,
|
|---|
| 249 | constraint fk_product_are_made_orders_orders foreign key (id_orders) references orders(ID) on delete cascade
|
|---|
| 250 | );
|
|---|
| 251 |
|
|---|
| 252 | create table products_available_type_of_pets(
|
|---|
| 253 | id_products bigint not null,
|
|---|
| 254 | id_type_of_pets bigint not null,
|
|---|
| 255 | constraint pk_products_available_type_of_pets primary key (id_products, id_type_of_pets),
|
|---|
| 256 | constraint fk_products_available_type_of_pets_type_of_pets foreign key (id_type_of_pets) references type_of_pets(ID) on delete cascade,
|
|---|
| 257 | constraint fk_products_available_type_of_pets_products foreign key (id_products) references products(ID) on delete cascade
|
|---|
| 258 | );
|
|---|
| 259 |
|
|---|
| 260 | create table therapy_takes_pets(
|
|---|
| 261 | id_therapy bigint not null,
|
|---|
| 262 | id_pets bigint not null,
|
|---|
| 263 | constraint pk_therapy_takes_pets primary key (id_therapy, id_pets),
|
|---|
| 264 | constraint fk_therapy_takes_pets_pets foreign key (id_pets) references pets(ID) on delete cascade,
|
|---|
| 265 | constraint fk_therapy_takes_pets_therapy foreign key (id_therapy) references therapy(ID) on delete cascade
|
|---|
| 266 | );
|
|---|
| 267 |
|
|---|