-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChat app SQL template.sql
174 lines (133 loc) · 5.9 KB
/
Chat app SQL template.sql
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# ************************************************************
# Sequel Pro SQL dump
# Version 4541
#
# http://www.sequelpro.com/
# https://github.com/sequelpro/sequelpro
#
# Host: 157.230.119.65 (MySQL 5.7.25-0ubuntu0.18.04.2)
# Database: chatapp
# Generation Time: 2019-03-21 23:19:27 +0000
# ************************************************************
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Dump of table channel_perm_user
# ------------------------------------------------------------
DROP TABLE IF EXISTS `channel_perm_user`;
CREATE TABLE `channel_perm_user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`userid` int(11) unsigned NOT NULL,
`channelid` int(11) unsigned NOT NULL,
`perm` varchar(128) NOT NULL DEFAULT 'none' COMMENT 'none=nothing full CRUD; deny=blocked;readonly=read only;private = full crud and only shown when enabled to that user; private_readonly = readonly of a hidden channel',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `c2c` (`channelid`),
KEY `u2cperm` (`userid`),
CONSTRAINT `c2c` FOREIGN KEY (`channelid`) REFERENCES `channels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `u2cperm` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table channels
# ------------------------------------------------------------
DROP TABLE IF EXISTS `channels`;
CREATE TABLE `channels` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`description` varchar(256) DEFAULT NULL,
`groupid` int(11) unsigned NOT NULL,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `group2channel` (`groupid`),
CONSTRAINT `group2channel` FOREIGN KEY (`groupid`) REFERENCES `group` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table group
# ------------------------------------------------------------
DROP TABLE IF EXISTS `group`;
CREATE TABLE `group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(128) NOT NULL DEFAULT '',
`Description` varchar(200) DEFAULT NULL,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
LOCK TABLES `group` WRITE;
/*!40000 ALTER TABLE `group` DISABLE KEYS */;
INSERT INTO `group` (`id`, `Name`, `Description`, `created_at`, `updated_at`)
VALUES
(1,'hello','test',NULL,NULL),
(2,'GROUP2','teest',NULL,NULL),
(3,'test','eee',NULL,NULL);
/*!40000 ALTER TABLE `group` ENABLE KEYS */;
UNLOCK TABLES;
# Dump of table messages
# ------------------------------------------------------------
DROP TABLE IF EXISTS `messages`;
CREATE TABLE `messages` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`message` text NOT NULL,
`message_type` varchar(100) DEFAULT 'txt',
`channelid` int(11) unsigned NOT NULL,
`userid` int(11) unsigned NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
# Dump of table user2group
# ------------------------------------------------------------
DROP TABLE IF EXISTS `user2group`;
CREATE TABLE `user2group` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`groupid` int(11) unsigned NOT NULL,
`userid` int(11) unsigned NOT NULL,
`perm` varchar(128) DEFAULT NULL COMMENT 'admin: administrator; moderator: moderator; user:user',
PRIMARY KEY (`id`),
KEY `u2u` (`userid`),
KEY `g2g` (`groupid`),
CONSTRAINT `g2g` FOREIGN KEY (`groupid`) REFERENCES `group` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `u2u` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
LOCK TABLES `user2group` WRITE;
/*!40000 ALTER TABLE `user2group` DISABLE KEYS */;
INSERT INTO `user2group` (`id`, `groupid`, `userid`, `perm`)
VALUES
(1,1,1,'admin'),
(2,1,3,'visitor'),
(3,2,1,'visitor'),
(4,3,1,'visitor');
/*!40000 ALTER TABLE `user2group` ENABLE KEYS */;
UNLOCK TABLES;
# Dump of table users
# ------------------------------------------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL DEFAULT '',
`username` varchar(32) DEFAULT '',
`password` varchar(256) NOT NULL DEFAULT '',
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`update_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` (`id`, `email`, `username`, `password`, `created_at`, `update_at`)
VALUES
(1,'[email protected]','a','',NULL,NULL),
(2,'[email protected]','b','',NULL,NULL),
(3,'[email protected]','joe','',NULL,NULL);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;