This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alphdb_create.sql
193 lines (151 loc) · 6.36 KB
/
alphdb_create.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
CREATE DATABASE IF NOT EXISTS alph DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE alph;
CREATE TABLE `ACCOUNT` (
`idaccount` int NOT NULL AUTO_INCREMENT,
`status` bit NOT NULL,
`hyperpower` bit NOT NULL,
`email` varchar(254) NOT NULL UNIQUE,
`username` varchar(36) NOT NULL UNIQUE,
`password` varchar(60) NOT NULL,
`code` char(100),
`createddate` DATETIME NOT NULL,
`editeddate` DATETIME,
PRIMARY KEY (`idaccount`)
);
CREATE TABLE `TERMINAL_DIRECTORY` (
`iddir` int NOT NULL AUTO_INCREMENT,
`terminal` char(17) NOT NULL,
`parent` int,
`name` varchar(255) NOT NULL,
`chmod` int(3) NOT NULL,
`owner` int NOT NULL,
`group` int NOT NULL,
`createddate` DATETIME NOT NULL,
`editeddate` DATETIME,
PRIMARY KEY (`iddir`)
);
CREATE TABLE `TERMINAL_FILE` (
`idfile` int NOT NULL AUTO_INCREMENT,
`terminal` char(17) NOT NULL,
`parent` int,
`name` varchar(255),
`data` TEXT,
`chmod` int(3) NOT NULL,
`owner` int NOT NULL,
`group` int NOT NULL,
`createddate` DATETIME NOT NULL,
`editeddate` DATETIME,
PRIMARY KEY (`idfile`)
);
CREATE TABLE `TERMINAL` (
`mac` char(17) NOT NULL,
`account` int NOT NULL,
`localnetwork` char(17),
PRIMARY KEY (`mac`)
);
CREATE TABLE `NETWORK` (
`mac` char(17) NOT NULL,
`ipv4` varchar(15) NOT NULL UNIQUE,
`ipv6` varchar(45) NOT NULL UNIQUE,
PRIMARY KEY (`mac`)
);
CREATE TABLE `PORT` (
`network` char(17) NOT NULL,
`port` int NOT NULL,
`status` int NOT NULL,
`ip` varchar(15) NOT NULL,
`ipport` int NOT NULL,
PRIMARY KEY (`network`,`port`)
);
CREATE TABLE `PRIVATEIP` (
`network` char(17) NOT NULL,
`terminal` char(17) NOT NULL,
`ip` varchar(15) NOT NULL,
PRIMARY KEY (`network`,`terminal`)
);
CREATE TABLE `TERMINAL_USER` (
`idterminal_user` int NOT NULL AUTO_INCREMENT,
`terminal` char(17) NOT NULL,
`uid` int NOT NULL,
`gid` int NOT NULL,
`status` bit NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`idterminal_user`)
);
CREATE TABLE `TERMINAL_GROUP` (
`idterminal_group` int NOT NULL AUTO_INCREMENT,
`terminal` char(17) NOT NULL,
`gid` int NOT NULL,
`status` bit NOT NULL,
`groupname` varchar(255) NOT NULL,
PRIMARY KEY (`idterminal_group`)
);
CREATE TABLE `TERMINAL_GROUP_LINK` (
`terminal_user` int NOT NULL,
`terminal_group` int NOT NULL,
PRIMARY KEY (`terminal_user`,`terminal_group`)
);
CREATE TABLE `TERMINAL_USER_HISTORY` (
`idhistory` int NOT NULL AUTO_INCREMENT,
`terminal_user` int NOT NULL,
`account` int NOT NULL,
`status` bit NOT NULL,
`command` TEXT NOT NULL,
`date` DATETIME NOT NULL,
PRIMARY KEY (`idhistory`)
);
CREATE TABLE `CONFIG` (
`key` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`key`)
);
CREATE TABLE `ACCOUNT_GROUP_LINK` (
`account` int NOT NULL,
`groupid` int NOT NULL,
PRIMARY KEY (`account`,`groupid`)
);
CREATE TABLE `REFERENTIAL` (
`idreferential` int NOT NULL AUTO_INCREMENT,
`type` bit NOT NULL,
`code` varchar(255) NOT NULL UNIQUE,
`category` int,
`value` TEXT,
PRIMARY KEY (`idreferential`)
);
CREATE TABLE `GROUP` (
`idgroup` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`idgroup`)
);
CREATE TABLE `PERMISSION` (
`code` int NOT NULL,
`idgroup` int NOT NULL,
`value` bit NOT NULL,
PRIMARY KEY (`code`,`idgroup`)
);
ALTER TABLE `TERMINAL_DIRECTORY` ADD CONSTRAINT `TERMINAL_DIRECTORY_fk0` FOREIGN KEY (`terminal`) REFERENCES `TERMINAL`(`mac`);
ALTER TABLE `TERMINAL_DIRECTORY` ADD CONSTRAINT `TERMINAL_DIRECTORY_fk1` FOREIGN KEY (`parent`) REFERENCES `TERMINAL_DIRECTORY`(`iddir`);
ALTER TABLE `TERMINAL_DIRECTORY` ADD CONSTRAINT `TERMINAL_DIRECTORY_fk2` FOREIGN KEY (`owner`) REFERENCES `TERMINAL_USER`(`idterminal_user`);
ALTER TABLE `TERMINAL_DIRECTORY` ADD CONSTRAINT `TERMINAL_DIRECTORY_fk3` FOREIGN KEY (`group`) REFERENCES `TERMINAL_GROUP`(`idterminal_group`);
ALTER TABLE `TERMINAL_FILE` ADD CONSTRAINT `TERMINAL_FILE_fk0` FOREIGN KEY (`terminal`) REFERENCES `TERMINAL`(`mac`);
ALTER TABLE `TERMINAL_FILE` ADD CONSTRAINT `TERMINAL_FILE_fk1` FOREIGN KEY (`parent`) REFERENCES `TERMINAL_DIRECTORY`(`iddir`);
ALTER TABLE `TERMINAL_FILE` ADD CONSTRAINT `TERMINAL_FILE_fk2` FOREIGN KEY (`owner`) REFERENCES `TERMINAL_USER`(`idterminal_user`);
ALTER TABLE `TERMINAL_FILE` ADD CONSTRAINT `TERMINAL_FILE_fk3` FOREIGN KEY (`group`) REFERENCES `TERMINAL_GROUP`(`idterminal_group`);
ALTER TABLE `TERMINAL` ADD CONSTRAINT `TERMINAL_fk0` FOREIGN KEY (`account`) REFERENCES `ACCOUNT`(`idaccount`);
ALTER TABLE `TERMINAL` ADD CONSTRAINT `TERMINAL_fk1` FOREIGN KEY (`localnetwork`) REFERENCES `NETWORK`(`mac`);
ALTER TABLE `PORT` ADD CONSTRAINT `PORT_fk0` FOREIGN KEY (`network`) REFERENCES `NETWORK`(`mac`);
ALTER TABLE `PRIVATEIP` ADD CONSTRAINT `PRIVATEIP_fk0` FOREIGN KEY (`network`) REFERENCES `NETWORK`(`mac`);
ALTER TABLE `PRIVATEIP` ADD CONSTRAINT `PRIVATEIP_fk1` FOREIGN KEY (`terminal`) REFERENCES `TERMINAL`(`mac`);
ALTER TABLE `TERMINAL_USER` ADD CONSTRAINT `TERMINAL_USER_fk0` FOREIGN KEY (`terminal`) REFERENCES `TERMINAL`(`mac`);
ALTER TABLE `TERMINAL_USER` ADD CONSTRAINT `TERMINAL_USER_fk1` FOREIGN KEY (`gid`) REFERENCES `TERMINAL_GROUP`(`idterminal_group`);
ALTER TABLE `TERMINAL_GROUP` ADD CONSTRAINT `TERMINAL_GROUP_fk0` FOREIGN KEY (`terminal`) REFERENCES `TERMINAL`(`mac`);
ALTER TABLE `TERMINAL_GROUP_LINK` ADD CONSTRAINT `TERMINAL_GROUP_LINK_fk0` FOREIGN KEY (`terminal_user`) REFERENCES `TERMINAL_USER`(`idterminal_user`);
ALTER TABLE `TERMINAL_GROUP_LINK` ADD CONSTRAINT `TERMINAL_GROUP_LINK_fk1` FOREIGN KEY (`terminal_group`) REFERENCES `TERMINAL_GROUP`(`idterminal_group`);
ALTER TABLE `TERMINAL_USER_HISTORY` ADD CONSTRAINT `TERMINAL_USER_HISTORY_fk0` FOREIGN KEY (`terminal_user`) REFERENCES `TERMINAL_USER`(`idterminal_user`);
ALTER TABLE `TERMINAL_USER_HISTORY` ADD CONSTRAINT `TERMINAL_USER_HISTORY_fk1` FOREIGN KEY (`account`) REFERENCES `ACCOUNT`(`idaccount`);
ALTER TABLE `ACCOUNT_GROUP_LINK` ADD CONSTRAINT `ACCOUNT_GROUP_LINK_fk0` FOREIGN KEY (`account`) REFERENCES `ACCOUNT`(`idaccount`);
ALTER TABLE `ACCOUNT_GROUP_LINK` ADD CONSTRAINT `ACCOUNT_GROUP_LINK_fk1` FOREIGN KEY (`groupid`) REFERENCES `GROUP`(`idgroup`);
ALTER TABLE `REFERENTIAL` ADD CONSTRAINT `REFERENTIAL_fk0` FOREIGN KEY (`category`) REFERENCES `REFERENTIAL`(`idreferential`);
ALTER TABLE `PERMISSION` ADD CONSTRAINT `PERMISSION_fk0` FOREIGN KEY (`code`) REFERENCES `REFERENTIAL`(`idreferential`);
ALTER TABLE `PERMISSION` ADD CONSTRAINT `PERMISSION_fk1` FOREIGN KEY (`idgroup`) REFERENCES `GROUP`(`idgroup`);