· 9 years ago · Nov 15, 2016, 10:50 AM
1
2CREATE TABLE `posts` (
3 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
4 `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
5 `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
6 `title` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
7 `user_id` int(10) unsigned NOT NULL,
8 `post_id` int(10) unsigned DEFAULT NULL,
9 `childcount` int(10) unsigned NOT NULL DEFAULT '0',
10 `level` int(10) unsigned NOT NULL DEFAULT '0',
11 `content` text COLLATE utf8_unicode_ci,
12 `readcount` int(10) unsigned NOT NULL DEFAULT '0',
13 `thread_id` int(10) unsigned DEFAULT NULL,
14 PRIMARY KEY (`id`),
15 KEY `fk_thread_user_id` (`user_id`),
16 KEY `fk_posts_post_id` (`post_id`),
17 KEY `fk_thread_id` (`thread_id`),
18 CONSTRAINT `fk_posts_post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
19 CONSTRAINT `fk_thread_id` FOREIGN KEY (`thread_id`) REFERENCES `threads` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
20 CONSTRAINT `fk_thread_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
21) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
22/*!40101 SET character_set_client = @saved_cs_client */;
23
24--
25-- Table structure for table `rooms`
26--
27
28DROP TABLE IF EXISTS `rooms`;
29/*!40101 SET @saved_cs_client = @@character_set_client */;
30/*!40101 SET character_set_client = utf8 */;
31CREATE TABLE `rooms` (
32 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
33 `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
34 `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
35 `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
36 PRIMARY KEY (`id`)
37) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
38/*!40101 SET character_set_client = @saved_cs_client */;
39
40--
41-- Table structure for table `threads`
42--
43
44DROP TABLE IF EXISTS `threads`;
45/*!40101 SET @saved_cs_client = @@character_set_client */;
46/*!40101 SET character_set_client = utf8 */;
47CREATE TABLE `threads` (
48 `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
49 `room_id` int(10) unsigned NOT NULL,
50 `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
51 `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
52 `lastpost` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
53 PRIMARY KEY (`ID`),
54 KEY `room_id` (`room_id`),
55 CONSTRAINT `room_id` FOREIGN KEY (`room_id`) REFERENCES `rooms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
56) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
57/*!40101 SET character_set_client = @saved_cs_client */;