forked from tango-controls/TangoDatabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_db5.sql.in
277 lines (221 loc) · 10.2 KB
/
update_db5.sql.in
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
USE tango;
#
# Create all database tables not already created
#
source create_db_tables.sql
#
# Create some temporary stored procedure
#
DROP PROCEDURE IF EXISTS tango.upd_server;
DROP PROCEDURE IF EXISTS tango.upd_device;
DROP PROCEDURE IF EXISTS tango.upd_access_address;
DROP PROCEDURE IF EXISTS tango.upd_access_device;
DROP PROCEDURE IF EXISTS tango.upd_history_ids;
delimiter |
CREATE PROCEDURE tango.upd_server (IN obj_name VARCHAR(255))
BEGIN
DECLARE nb_val INT DEFAULT 0;
SELECT count(*)
INTO nb_val
FROM tango.server
WHERE name = obj_name;
IF nb_val = 0
THEN
INSERT INTO server VALUES (obj_name,'',1,1);
END IF;
END |
CREATE PROCEDURE tango.upd_device (IN obj_name VARCHAR(255),IN domain VARCHAR(85),IN family VARCHAR(85),IN memb VARCHAR(85),IN server VARCHAR(255),IN class VARCHAR(255))
BEGIN
DECLARE nb_val INT DEFAULT 0;
SELECT count(*)
INTO nb_val
FROM tango.device
WHERE name = obj_name;
IF nb_val = 0
THEN
INSERT INTO device VALUES (obj_name,NULL,domain,family,memb,'nada','nada','nada',server,'nada',class,'nada','nada','nada','nada');
END IF;
END |
CREATE PROCEDURE tango.upd_access_address ()
BEGIN
DECLARE nb_val INT DEFAULT 0;
SELECT count(*)
INTO nb_val
FROM tango.access_address
WHERE user = '*';
IF nb_val = 0
THEN
INSERT INTO access_address VALUES ('*','*.*.*.*','FF.FF.FF.FF',20060824131221,00000000000000);
END IF;
END |
CREATE PROCEDURE tango.upd_access_device ()
BEGIN
DECLARE nb_val INT DEFAULT 0;
SELECT count(*)
INTO nb_val
FROM tango.access_device
WHERE user = '*';
IF nb_val = 0
THEN
INSERT INTO access_device VALUES ('*','*/*/*','write',20060824131221,00000000000000);
END IF;
END |
CREATE PROCEDURE tango.upd_history_ids ()
BEGIN
DECLARE table_defined INT DEFAULT 0;
DECLARE id_val INT DEFAULT -1;
SELECT count(*)
INTO table_defined
FROM information_schema.tables
WHERE table_schema = 'tango' AND table_name = 'history_ids';
IF table_defined = 1
THEN
SELECT id
INTO id_val
FROM device_history_id;
IF id_val < 1
THEN
TRUNCATE TABLE device_history_id;
INSERT INTO device_history_id SELECT id from history_ids WHERE name='device';
END IF;
SET id_val = -1;
SELECT id
INTO id_val
FROM device_attribute_history_id;
IF id_val < 1
THEN
TRUNCATE TABLE device_attribute_history_id;
INSERT INTO device_attribute_history_id SELECT id from history_ids WHERE name='device_attribute';
END IF;
SET id_val = -1;
SELECT id
INTO id_val
FROM class_history_id;
IF id_val < 1
THEN
TRUNCATE TABLE class_history_id;
INSERT INTO class_history_id SELECT id from history_ids WHERE name='class';
END IF;
SET id_val = -1;
SELECT id
INTO id_val
FROM class_attribute_history_id;
IF id_val < 1
THEN
TRUNCATE TABLE class_attribute_history_id;
INSERT INTO class_attribute_history_id SELECT id from history_ids WHERE name='class_attribute';
END IF;
SET id_val = -1;
SELECT id
INTO id_val
FROM object_history_id;
IF id_val < 1
THEN
TRUNCATE TABLE object_history_id;
INSERT INTO object_history_id SELECT id from history_ids WHERE name='object';
END IF;
END IF;
END |
delimiter ;
#
# Init the new history identifier tables from the old history_ids table
#
CALL tango.upd_history_ids();
#
# Be sure to have the device table correctly defined
#
ALTER TABLE device CHANGE alias alias VARCHAR(255) default NULL;
#
# Create entry for Tango Control Access in device table
#
CALL tango.upd_device('sys/access_control/1','sys','access_control','1','TangoAccessControl/1','TangoAccessControl');
CALL tango.upd_device('dserver/TangoAccessControl/1','dserver','TangoAccessControl','1','TangoAccessControl/1','DServer');
CALL tango.upd_server('tangoaccesscontrol/1');
#
# Create default user access
#
CALL tango.upd_access_address();
CALL tango.upd_access_device();
#
# Create entries in the property_class tables for controlled access service
#
DELETE FROM property_class WHERE class = 'Database' and name = 'AllowedAccessCmd';
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',1,'DbGetServerInfo',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',2,'DbGetServerNameList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',3,'DbGetInstanceNameList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',4,'DbGetDeviceServerClassList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',5,'DbGetDeviceList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',6,'DbGetDeviceDomainList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',7,'DbGetDeviceFamilyList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',8,'DbGetDeviceMemberList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',9,'DbGetClassList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',10,'DbGetDeviceAliasList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',11,'DbGetObjectList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',12,'DbGetPropertyList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',13,'DbGetProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',14,'DbGetClassPropertyList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',15,'DbGetClassProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',16,'DbGetDevicePropertyList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',17,'DbGetDeviceProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',18,'DbGetClassAttributeList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',19,'DbGetDeviceAttributeProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',20,'DbGetDeviceAttributeProperty2',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',21,'DbGetLoggingLevel',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',22,'DbGetAliasDevice',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',23,'DbGetClassForDevice',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',24,'DbGetClassInheritanceForDevice',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',25,'DbGetDataForServerCache',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',26,'DbInfo',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',27,'DbGetClassAttributeProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',28,'DbGetClassAttributeProperty2',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',29,'DbMysqlSelect',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',30,'DbGetDeviceInfo',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',31,'DbGetDeviceWideList',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',32,'DbImportEvent',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',33,'DbGetDeviceAlias',NULL,NULL,NULL);
INSERT INTO property_class VALUES('Database','AllowedAccessCmd',34,'DbGetCSDbServerList',NULL,NULL,NULL);
#
#
#
DELETE FROM property_class WHERE class = 'DServer' and name = 'AllowedAccessCmd';
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',1,'QueryClass',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',2,'QueryDevice',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',3,'EventSubscriptionChange',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',4,'DevPollStatus',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',5,'GetLoggingLevel',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',6,'GetLoggingTarget',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',7,'QueryWizardDevProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',8,'QueryWizardClassProperty',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',9,'QuerySubDevice',NULL,NULL,NULL);
INSERT INTO property_class VALUES('DServer','AllowedAccessCmd',10,'ZMQEventSubscriptionChange',NULL,NULL,NULL);
#
#
#
DELETE FROM property_class WHERE class = 'Starter' and name = 'AllowedAccessCmd';
INSERT INTO property_class VALUES ('Starter','AllowedAccessCmd',1,'DevReadLog',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('Starter','AllowedAccessCmd',2,'DevStart',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('Starter','AllowedAccessCmd',3,'DevGetRunningServers',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('Starter','AllowedAccessCmd',4,'DevGetStopServers',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('Starter','AllowedAccessCmd',5,'UpdateServerList',NULL,NULL,NULL);
#
#
#
DELETE FROM property_class WHERE class = 'TangoAccessControl' and name = 'AllowedAccessCmd';
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',1,'GetUsers',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',2,'GetAddressByUser',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',3,'GetDeviceByUser',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',4,'GetAccess',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',5,'GetAllowedCommands',NULL,NULL,NULL);
INSERT INTO property_class VALUES ('TangoAccessControl','AllowedAccessCmd',6,'GetAllowedCommandClassList',NULL,NULL,NULL);
#
# Delete the temporary stored procedure
#
DROP PROCEDURE IF EXISTS tango.upd_server;
DROP PROCEDURE IF EXISTS tango.upd_device;
DROP PROCEDURE IF EXISTS tango.upd_access_address;
DROP PROCEDURE IF EXISTS tango.upd_access_device;
DROP PROCEDURE IF EXISTS tango.upd_history_ids;
#
# Load the real stored procedures
#
source stored_proc.sql