-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatRoom.sql
160 lines (153 loc) · 7.29 KB
/
chatRoom.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
CREATE DATABASE IF NOT EXISTS `chatRoom`;
USE `chatRoom`;
/*!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 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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 */;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
DROP TABLE IF EXISTS `board`;
CREATE TABLE IF NOT EXISTS `board` (
`creator` int not null,
`number` int NOT NULL AUTO_INCREMENT,
`name` varchar(50) not null,
`image` varchar(20) not null,
`channelof` int not null default -1,
`public` tinyint not null default 0,
`dm` tinyint not null default 0,
`readonly` tinyint not null default 0,
PRIMARY KEY (`number`),
KEY(`name`)
);
CREATE INDEX get_channels ON `board`(`channelof`) USING HASH;
INSERT INTO board(`number`,`creator`, `name`, `public`, `image`,`channelof`,`dm`,`readonly`) VALUES(-1, -1, "Default Board", 0, "misc.png",-1,0,0);
INSERT INTO board(`creator`, `name`, `public`, `image`,`channelof`,`dm`,`readonly`) VALUES(-1, "Everything Else", 1, "everythingelse.png",-1,0,0);
INSERT INTO board(`creator`, `name`, `public`, `image`,`channelof`,`dm`,`readonly`) VALUES(-1, "SAS4", 1, "sas4.png",-1,0,0);
INSERT INTO board(`creator`, `name`, `public`, `image`,`channelof`,`dm`,`readonly`) VALUES(-1, "Skyblock", 1, "skyblock.png",-1,0,0);
INSERT INTO board(`creator`, `name`, `public`, `image`,`channelof`,`dm`,`readonly`) VALUES(1, "Hydar", 0, "misc.png",-1,0,0);
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`id` int NOT NULL AUTO_INCREMENT,
`username` varchar(50) not null,
`password` varbinary(32) not null,
`addr` varbinary(16) not null DEFAULT x'7f000001',
`pfp` varchar(100) not null,
`permission_level` enum("water_hydar","great_white","yeti","skeleton","reserved2") not null,
`created_date` bigint not null default 0,
`pings` tinyint not null,
`volume` tinyint not null,
`pingvolume` tinyint not null,
`vcvolume` tinyint not null,
PRIMARY KEY (`id`),
KEY (`username`),
KEY (`addr`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `ban`;
CREATE TABLE IF NOT EXISTS `ban`(
`id` int,
`type` enum("user","message","addr"),
`addr` varbinary(16) not null,
PRIMARY KEY(`addr`),
KEY(`id`)
);
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO user(`username`, `id`, `password`, `pfp`, `permission_level`, `pings`, `volume`, `pingvolume`, `vcvolume`) VALUES("Deleted User",-1,"hydarhydar", "images/hydar2.png", "water_hydar", 0, 50, 50, 50);
INSERT INTO user(`username`, `id`, `password`, `pfp`, `permission_level`, `pings`, `volume`, `pingvolume`, `vcvolume`) VALUES("Raye",2,"raye", "images/r.png", "water_hydar", 0, 50, 50, 50);
INSERT INTO user(`username`, `id`, `password`, `pfp`, `permission_level`, `pings`, `volume`, `pingvolume`, `vcvolume`) VALUES("Guest",3,"skeleton", "images/emp.png", "skeleton", 0, 50, 50, 50);
SELECT * FROM user;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
DROP TABLE IF EXISTS `post`;
CREATE TABLE IF NOT EXISTS `post` (
`contents` varchar(3000) not null,
`id` int NOT NULL AUTO_INCREMENT not null,
`board` int not null,
`created_date` bigint not null,
`addr` varbinary(16),/*nullable*/
CONSTRAINT `board_posts_post` FOREIGN KEY (`board`) REFERENCES `board` (`number`) ON DELETE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*ALTER TABLE `post` AUTO_INCREMENT = 0;*/
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO post(`contents`, `id`, `board`, `created_date`) VALUES ("Hydar", -1, -1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
DROP TABlE IF EXISTS `posts`;
CREATE TABLE IF NOT EXISTS `posts` (
`user` int,
`post` int not null,
PRIMARY KEY (`post`),
CONSTRAINT `user_posts_post` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE SET NULL,
CONSTRAINT `post_posted` FOREIGN KEY (`post`) REFERENCES `post` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO posts(`user`, `post`) VALUES (-1, -1);
DROP TABLE IF EXISTS `isin`;
CREATE TABLE IF NOT EXISTS `isin` (
`user` int not null,
`board` int not null,
`lastvisited` bigint not null,
PRIMARY KEY (`user`, `board`),
CONSTRAINT `user_is_in` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE CASCADE,
CONSTRAINT `is_in_board` FOREIGN KEY (`board`) REFERENCES `board` (`number`) ON DELETE CASCADE
);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (-1, -1, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (-1, 1, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (-1, 2, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (-1, 3, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (2, 1, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (2, 2, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (2, 3, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (2, 4, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (3, 1, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (3, 2, 0);
INSERT INTO isin(`user`, `board`, `lastvisited`) VALUES (3, 3, 0);
DROP TABLE IF EXISTS `invitedto`;
CREATE TABLE IF NOT EXISTS `invitedto` (
`user` int not null,
`board` int not null,
PRIMARY KEY (`user`, `board`),
CONSTRAINT `user_invited_to` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE CASCADE,
CONSTRAINT `invited_to_board` FOREIGN KEY (`board`) REFERENCES `board` (`number`) ON DELETE CASCADE
);
DROP TABLE IF EXISTS `file`;
CREATE TABLE IF NOT EXISTS `file` (
`path` CHAR(16) not null,
`filename` VARCHAR(64) not null,
`user` int,
`board` int,
`post` int,
`size` bigint not null,
`date` bigint not null,
PRIMARY KEY (`path`),
CONSTRAINT `file_attached_to` FOREIGN KEY (`post`) REFERENCES `post` (`id`) ON DELETE SET NULL,
CONSTRAINT `file_uploaded_by` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE SET NULL,
CONSTRAINT `file_in_board` FOREIGN KEY (`board`) REFERENCES `board` (`number`) ON DELETE SET NULL
);
/*
show create table posts;
ALTER TABLE posts DROP FOREIGN KEY `posts_ibfk_1`;
ALTER TABLE posts MODIFY COLUMN `user` int null;
ALTER TABLE posts ADD CONSTRAINT `user_posts_post` FOREIGN KEY (`user`) REFERENCES `user` (`id`) ON DELETE SET NULL;
ALTER TABLE posts DROP FOREIGN KEY `post_posted`;
ALTER TABLE posts ADD CONSTRAINT `post_posted` FOREIGN KEY (`post`) REFERENCES `post` (`id`) ON DELETE CASCADE;
ALTER TABLE posts DROP PRIMARY KEY, ADD PRIMARY KEY (`post`);
*/
/*
SELECT path, filename, size FROM `file`WHERE user = ? AND post <> -1 ORDER BY post ;
SELECT COUNT(*),SUM(size) FROM `file` WHERE user = 1;
*/
SELECT * FROM invitedto;
SELECT * FROM user;
SELECT * FROM board;
SELECT * FROM isin;
SELECT * FROM post;
SELECT * FROM `file`;
SELECT * FROM posts;
SELECT posts.user FROM posts;