1 | drop schema if exists weservice cascade;
|
---|
2 | create schema weservice;
|
---|
3 |
|
---|
4 | -- use weservice;
|
---|
5 |
|
---|
6 | drop table if exists business_service;
|
---|
7 | drop table if exists review;
|
---|
8 | drop table if exists business;
|
---|
9 | drop table if exists service;
|
---|
10 | drop table if exists reviewer;
|
---|
11 | drop table if exists category;
|
---|
12 |
|
---|
13 |
|
---|
14 | create table category(
|
---|
15 | category_id serial primary key,
|
---|
16 | category_name varchar(150) not null
|
---|
17 |
|
---|
18 | );
|
---|
19 |
|
---|
20 | create table reviewer(
|
---|
21 | reviewer_id serial primary key,
|
---|
22 | reviewer_name varchar(150),
|
---|
23 | reviewer_verified boolean not null,
|
---|
24 | reviewer_email varchar(150) not null,
|
---|
25 | reviewer_password varchar(150) not null
|
---|
26 | );
|
---|
27 |
|
---|
28 | create table business(
|
---|
29 | business_id serial primary key,
|
---|
30 | business_name varchar(150) not null,
|
---|
31 | business_phone varchar(150),
|
---|
32 | business_descr varchar(500),
|
---|
33 | business_hours varchar(1000),
|
---|
34 |
|
---|
35 | category_id integer not null,
|
---|
36 |
|
---|
37 | constraint fk_business_category_id foreign key (category_id) references category(category_id)
|
---|
38 | );
|
---|
39 |
|
---|
40 | create table address(
|
---|
41 | address_id serial,
|
---|
42 | address_street varchar(150) not null,
|
---|
43 | address_postal_code varchar(150) not null,
|
---|
44 | address_city varchar(150) not null,
|
---|
45 | business_id integer not null,
|
---|
46 |
|
---|
47 | constraint pk_address_business primary key(business_id, address_id),
|
---|
48 |
|
---|
49 | constraint fk_business_id foreign key (business_id) references business(business_id)
|
---|
50 | );
|
---|
51 |
|
---|
52 | create table service(
|
---|
53 | service_id serial primary key,
|
---|
54 | service_name varchar(500) not null,
|
---|
55 | category_id integer not null,
|
---|
56 |
|
---|
57 | constraint fk_service_category foreign key (category_id) references category(category_id)
|
---|
58 | );
|
---|
59 |
|
---|
60 | create table review(
|
---|
61 | review_id serial primary key,
|
---|
62 | review_title varchar(150),
|
---|
63 | review_text varchar(1000),
|
---|
64 | review_stars integer,
|
---|
65 | business_id integer not null,
|
---|
66 | address_id integer not null,
|
---|
67 | reviewer_id integer not null,
|
---|
68 |
|
---|
69 |
|
---|
70 | constraint fk_business_id foreign key (business_id) references business(business_id),
|
---|
71 | constraint fk_address_id foreign key (business_id,address_id) references address(business_id, address_id),
|
---|
72 | constraint fk_reviewer_id foreign key (reviewer_id) references reviewer(reviewer_id)
|
---|
73 | );
|
---|
74 |
|
---|
75 |
|
---|
76 | create table business_service(
|
---|
77 | business_id integer not null,
|
---|
78 | service_id integer not null,
|
---|
79 |
|
---|
80 | constraint pk_business_service primary key (business_id, service_id),
|
---|
81 |
|
---|
82 | constraint fk_bs_business_id foreign key (business_id) references business(business_id),
|
---|
83 | constraint fk_bs_service_id foreign key (service_id) references service(service_id)
|
---|
84 | );
|
---|
85 |
|
---|
86 |
|
---|