forked from CatchPlus/EPIC-API-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
206 lines (181 loc) · 5.32 KB
/
schema.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
SET character_set_client=utf8;
SET character_set_connection=utf8;
SET character_set_database=utf8;
SET character_set_results=utf8;
SET character_set_server=utf8;
SET collation_connection=utf8_bin;
SET collation_database=utf8_bin;
SET collation_server=utf8_bin;
DROP TABLE IF EXISTS `epic_handles`;
CREATE TABLE `epic_handles` (
`epic_handle_id` bigint(20) NOT NULL AUTO_INCREMENT,
`handle` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
PRIMARY KEY (`epic_handle_id`),
UNIQUE KEY `handle` (`handle`)
) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
LOCK TABLES `epic_handles` WRITE;
INSERT INTO `epic_handles` VALUES (1,'10916/SARA');
UNLOCK TABLES;
DROP TABLE IF EXISTS `epic_values`;
CREATE TABLE `epic_values` (
`epic_value_id` bigint(20) NOT NULL AUTO_INCREMENT,
`epic_handle_id` bigint(20) NOT NULL,
`idx` int(11) NOT NULL,
`epic_type` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`data` blob,
`ttl_type` smallint(6) DEFAULT NULL,
`ttl` int(11) DEFAULT NULL,
`timestamp` int(11) DEFAULT NULL,
`refs` blob,
`admin_read` tinyint(1) DEFAULT NULL,
`admin_write` tinyint(1) DEFAULT NULL,
`pub_read` tinyint(1) DEFAULT NULL,
`pub_write` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`epic_value_id`),
UNIQUE KEY `epic_handle_id` (`epic_handle_id`,`idx`),
KEY `idx` (`idx`),
KEY `epic_type` (`epic_type`),
KEY `timestamp` (`timestamp`)
) ENGINE=MyISAM AUTO_INCREMENT=64 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
LOCK TABLES `epic_values` WRITE;
INSERT INTO `epic_values` VALUES (1,1,1,'URL','http://www.sara.nl/',0,86400,1325847528,'',1,1,1,0),(2,1,100,'HS_ADMIN','ó\0\0\0\n0.NA/10916\0\0\0È\0\0',0,86400,1325847528,'',1,1,1,0);
UNLOCK TABLES;
DROP TABLE IF EXISTS `handles_attic`;
CREATE TABLE `handles_attic` (
`handle` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
`idx` int(11) NOT NULL,
`type` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`data` blob,
`ttl_type` smallint(6) DEFAULT NULL,
`ttl` int(11) DEFAULT NULL,
`timestamp` int(11) DEFAULT NULL,
`refs` blob,
`admin_read` tinyint(1) DEFAULT NULL,
`admin_write` tinyint(1) DEFAULT NULL,
`pub_read` tinyint(1) DEFAULT NULL,
`pub_write` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`handle`,`idx`),
KEY `idx` (`idx`),
KEY `type` (`type`),
KEY `timestamp` (`timestamp`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
DROP TABLE IF EXISTS `nas`;
CREATE TABLE `nas` (
`na` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`na_id` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`na_id`),
UNIQUE KEY `na` (`na`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
INSERT INTO `nas` (`na`) VALUES ('0.NA/10916');
DROP VIEW IF EXISTS `handles`;
CREATE
ALGORITHM=UNDEFINED
SQL SECURITY INVOKER
VIEW `handles` AS SELECT
`handle`,
`idx`,
`epic_type` AS `type`,
`data`,
`ttl_type`,
`ttl`,
`timestamp`,
`refs`,
`admin_read`,
`admin_write`,
`pub_read`,
`pub_write`
FROM `epic_handles` NATURAL JOIN `epic_values`;
DELIMITER ;;
DROP PROCEDURE IF EXISTS `delete_handle`;;
CREATE PROCEDURE `delete_handle`(
`p_handle` VARCHAR(255) CHARACTER SET utf8
)
BEGIN
DECLARE l_epic_handle_id BIGINT;
SELECT `epic_handle_id` INTO l_epic_handle_id FROM `epic_handles` WHERE `handle` = p_handle;
DELETE FROM `epic_handles` WHERE `epic_handle_id` = l_epic_handle_id;
DELETE FROM `epic_values` WHERE `epic_handle_id` = l_epic_handle_id;
END;;
DROP PROCEDURE IF EXISTS `delete_all_handles`;;
CREATE PROCEDURE `delete_all_handles`()
BEGIN
DELETE FROM `epic_handles`;
DELETE FROM `epic_values`;
END;;
DROP PROCEDURE IF EXISTS `create_handle`;;
CREATE PROCEDURE `create_handle`(
`p_handle` VARCHAR(255) CHARACTER SET utf8,
`p_idx` INT4,
`p_epic_type` VARCHAR(255) CHARACTER SET utf8,
`p_data` BLOB,
`p_ttl_type` INT2,
`p_ttl` INT4,
`p_timestamp` INT4,
`p_refs` BLOB,
`p_admin_read` BOOL,
`p_admin_write` BOOL,
`p_pub_read` BOOL,
`p_pub_write` BOOL
)
BEGIN
DECLARE l_epic_handle_id BIGINT;
INSERT IGNORE INTO `epic_handles` (`handle`) VALUES (p_handle);
SELECT `epic_handle_id` INTO l_epic_handle_id FROM `epic_handles` WHERE `handle` = p_handle;
INSERT INTO `epic_values` (
`epic_handle_id`,
`idx`,
`epic_type`,
`data`,
`ttl_type`,
`ttl`,
`timestamp`,
`refs`,
`admin_read`,
`admin_write`,
`pub_read`,
`pub_write`
) VALUES (
l_epic_handle_id,
`p_idx`,
`p_epic_type`,
`p_data`,
`p_ttl_type`,
`p_ttl`,
`p_timestamp`,
`p_refs`,
`p_admin_read`,
`p_admin_write`,
`p_pub_read`,
`p_pub_write`
);
END;;
DROP PROCEDURE IF EXISTS `modify_value`;;
CREATE PROCEDURE `modify_value`(
`p_epic_type` VARCHAR(255) CHARACTER SET utf8,
`p_data` BLOB,
`p_ttl_type` INT2,
`p_ttl` INT4,
`p_timestamp` INT4,
`p_refs` BLOB,
`p_admin_read` BOOL,
`p_admin_write` BOOL,
`p_pub_read` BOOL,
`p_pub_write` BOOL,
`p_handle` VARCHAR(255) CHARACTER SET utf8,
`p_idx` INT4
)
BEGIN
UPDATE `handles` SET
`type` = `p_epic_type`,
`data` = `p_data`,
`ttl_type` = `p_ttl_type`,
`ttl` = `p_ttl`,
`timestamp` = `p_timestamp`,
`refs` = `p_refs`,
`admin_read` = `p_admin_read`,
`admin_write` = `p_admin_write`,
`pub_read` = `p_pub_read`,
`pub_write` = `p_pub_write`
WHERE `handle` = `p_handle` AND `idx` = `p_idx`;
END;;
DELIMITER ;