-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
116 lines (87 loc) · 2.85 KB
/
schema.sql
File metadata and controls
116 lines (87 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
CREATE DATABASE IF NOT EXISTS shadowfax;
DROP TABLE IF EXISTS business_review;
DROP TABLE IF EXISTS business_service;
DROP TABLE IF EXISTS business_tags;
DROP TABLE IF EXISTS service;
DROP TABLE IF EXISTS tag;
DROP TABLE IF EXISTS review;
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS business;
CREATE TABLE business (
id int(11) AUTO_INCREMENT PRIMARY KEY,
name varchar(256) NOT NULL,
city varchar(256) NOT NULL,
primary_email varchar(256) NOT NULL,
primary_phone varchar(256) NOT NULL,
latitude varchar(10) DEFAULT NULL,
longitude varchar(10) DEFAULT NULL,
overall_rating int(11) DEFAULT NULL
);
--
-- Table structure for table user
--
CREATE TABLE user (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(256) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Table structure for table reviews
--
CREATE TABLE review (
id int(11) AUTO_INCREMENT PRIMARY KEY,
rating int(11) DEFAULT NULL,
comment varchar(256) DEFAULT NULL,
user_id int(11) DEFAULT NULL,
FOREIGN KEY (user_id) REFERENCES user(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table business_review
--
CREATE TABLE business_review (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
review_id int(11) DEFAULT NULL,
user_id int(11) DEFAULT NULL,
FOREIGN KEY (review_id) REFERENCES review(id),
FOREIGN KEY (user_id) REFERENCES user(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table services
--
CREATE TABLE service (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(256) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table business_service
--
CREATE TABLE business_service (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
service_id int(11) DEFAULT NULL ,
business_id int(11) DEFAULT NULL ,
FOREIGN KEY (business_id) REFERENCES business(id),
FOREIGN KEY (service_id) REFERENCES service(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table tags
--
CREATE TABLE tag (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(256) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table business_tags
--
CREATE TABLE business_tags (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
tag_id int(11) DEFAULT NULL ,
business_id int(11) DEFAULT NULL ,
CONSTRAINT uc_tag_business UNIQUE (tag_id, business_id),
FOREIGN KEY (business_id) REFERENCES business(id),
FOREIGN KEY (tag_id) REFERENCES tag(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------