· 8 years ago · Jun 29, 2018, 01:18 AM
1SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
2
3--
4-- Database: `rist`
5--
6
7-- --------------------------------------------------------
8
9--
10-- Table structure for table `categories`
11--
12
13CREATE TABLE IF NOT EXISTS `categories` (
14 `id` int(11) NOT NULL AUTO_INCREMENT,
15 `name` varchar(255) DEFAULT NULL,
16 `description` text,
17 `created_at` datetime DEFAULT NULL,
18 `updated_at` datetime DEFAULT NULL,
19 PRIMARY KEY (`id`)
20) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
21
22-- --------------------------------------------------------
23
24--
25-- Table structure for table `cities`
26--
27
28CREATE TABLE IF NOT EXISTS `cities` (
29 `id` int(11) NOT NULL AUTO_INCREMENT,
30 `name` varchar(255) DEFAULT NULL,
31 `country_id` int(11) DEFAULT NULL,
32 `created_at` datetime DEFAULT NULL,
33 `updated_at` datetime DEFAULT NULL,
34 PRIMARY KEY (`id`),
35 KEY `fk_country` (`country_id`)
36) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
37
38-- --------------------------------------------------------
39
40--
41-- Table structure for table `countries`
42--
43
44CREATE TABLE IF NOT EXISTS `countries` (
45 `id` int(11) NOT NULL AUTO_INCREMENT,
46 `name` varchar(255) DEFAULT NULL,
47 `short_name` varchar(255) DEFAULT NULL,
48 `created_at` datetime DEFAULT NULL,
49 `updated_at` datetime DEFAULT NULL,
50 `currency_sym` varchar(255) DEFAULT NULL,
51 `currency_name` varchar(255) DEFAULT NULL,
52 PRIMARY KEY (`id`)
53) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
54
55-- --------------------------------------------------------
56
57--
58-- Table structure for table `dishes`
59--
60
61CREATE TABLE IF NOT EXISTS `dishes` (
62 `id` int(11) NOT NULL AUTO_INCREMENT,
63 `name` varchar(255) DEFAULT NULL,
64 `description` text,
65 `price` float DEFAULT NULL,
66 `restaurant_id` int(11) DEFAULT NULL,
67 `menu_category_id` int(11) DEFAULT NULL,
68 `created_at` datetime DEFAULT NULL,
69 `updated_at` datetime DEFAULT NULL,
70 PRIMARY KEY (`id`),
71 KEY `restaurant_id` (`restaurant_id`),
72 KEY `menu_category_id` (`menu_category_id`)
73) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
74
75-- --------------------------------------------------------
76
77--
78-- Table structure for table `menu_categories`
79--
80
81CREATE TABLE IF NOT EXISTS `menu_categories` (
82 `id` int(11) NOT NULL AUTO_INCREMENT,
83 `name` varchar(255) DEFAULT NULL,
84 `description` text,
85 `category_id` int(11) DEFAULT NULL,
86 `created_at` datetime DEFAULT NULL,
87 `updated_at` datetime DEFAULT NULL,
88 PRIMARY KEY (`id`),
89 KEY `fk_menu_category` (`category_id`)
90) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
91
92-- --------------------------------------------------------
93
94--
95-- Table structure for table `restaurants`
96--
97
98CREATE TABLE IF NOT EXISTS `restaurants` (
99 `id` int(11) NOT NULL AUTO_INCREMENT,
100 `name` varchar(255) DEFAULT NULL,
101 `description` varchar(255) DEFAULT NULL,
102 `category_id` int(11) DEFAULT NULL,
103 `address` varchar(255) DEFAULT NULL,
104 `city_id` int(11) DEFAULT NULL,
105 `zip` int(11) DEFAULT NULL,
106 `phone` varchar(255) DEFAULT NULL,
107 `lat` float DEFAULT NULL,
108 `lon` float DEFAULT NULL,
109 `user_id` int(11) DEFAULT NULL,
110 `created_at` datetime DEFAULT NULL,
111 `updated_at` datetime DEFAULT NULL,
112 PRIMARY KEY (`id`),
113 KEY `city_id` (`city_id`),
114 KEY `fk_category` (`category_id`),
115 KEY `user_id` (`user_id`)
116) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
117
118-- --------------------------------------------------------
119
120--
121-- Table structure for table `schema_migrations`
122--
123
124CREATE TABLE IF NOT EXISTS `schema_migrations` (
125 `version` varchar(255) NOT NULL,
126 UNIQUE KEY `unique_schema_migrations` (`version`)
127) ENGINE=InnoDB DEFAULT CHARSET=utf8;
128
129-- --------------------------------------------------------
130
131--
132-- Table structure for table `users`
133--
134
135CREATE TABLE IF NOT EXISTS `users` (
136 `id` int(11) NOT NULL AUTO_INCREMENT,
137 `username` varchar(255) DEFAULT NULL,
138 `email` varchar(255) DEFAULT NULL,
139 `role` varchar(255) DEFAULT NULL,
140 `crypted_password` varchar(255) DEFAULT NULL,
141 `password_salt` varchar(255) DEFAULT NULL,
142 `persistence_token` varchar(255) DEFAULT NULL,
143 `created_at` datetime DEFAULT NULL,
144 `updated_at` datetime DEFAULT NULL,
145 PRIMARY KEY (`id`)
146) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
147
148-- --------------------------------------------------------
149
150--
151-- Table structure for table `user_sessions`
152--
153
154CREATE TABLE IF NOT EXISTS `user_sessions` (
155 `id` int(11) NOT NULL AUTO_INCREMENT,
156 `username` varchar(255) DEFAULT NULL,
157 `password` varchar(255) DEFAULT NULL,
158 `created_at` datetime DEFAULT NULL,
159 `updated_at` datetime DEFAULT NULL,
160 PRIMARY KEY (`id`)
161) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
162
163--
164-- Constraints for dumped tables
165--
166
167--
168-- Constraints for table `cities`
169--
170ALTER TABLE `cities`
171 ADD CONSTRAINT `fk_country` FOREIGN KEY (`country_id`) REFERENCES `countries` (`id`);
172
173--
174-- Constraints for table `dishes`
175--
176ALTER TABLE `dishes`
177 ADD CONSTRAINT `dishes_ibfk_1` FOREIGN KEY (`restaurant_id`) REFERENCES `restaurants` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
178 ADD CONSTRAINT `dishes_ibfk_2` FOREIGN KEY (`menu_category_id`) REFERENCES `menu_categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
179
180--
181-- Constraints for table `menu_categories`
182--
183ALTER TABLE `menu_categories`
184 ADD CONSTRAINT `fk_menu_category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`);
185
186--
187-- Constraints for table `restaurants`
188--
189ALTER TABLE `restaurants`
190 ADD CONSTRAINT `restaurants_ibfk_1` FOREIGN KEY (`city_id`) REFERENCES `cities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
191 ADD CONSTRAINT `restaurants_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
192 ADD CONSTRAINT `restaurants_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;