99 |
rodolico |
1 |
/* this is only for upgrades */
|
|
|
2 |
create or replace table temp as select * from attrib;
|
|
|
3 |
/* end start upgrades */
|
|
|
4 |
|
101 |
rodolico |
5 |
create or replace table attrib (
|
99 |
rodolico |
6 |
attrib_id int(10) unsigned NOT NULL auto_increment,
|
|
|
7 |
attrib_category_id int unsigned default 1 references attrib_category( attrib_category_id ),
|
|
|
8 |
name varchar(64) not null unique COMMENT 'the visible displayed name',
|
101 |
rodolico |
9 |
added_date date not null COMMENT 'date record was added',
|
102 |
rodolico |
10 |
multiples char(1) default null comment 'set to true if ultiple entries are allowed',
|
101 |
rodolico |
11 |
removed_date date default NULL COMMENT 'date record was deleted or supserceded',
|
|
|
12 |
keyname varchar(32) comment 'used for sysinfo really needs to be separate table',
|
99 |
rodolico |
13 |
PRIMARY KEY (attrib_id)
|
101 |
rodolico |
14 |
) comment 'attributes that can be applied to a device';
|
99 |
rodolico |
15 |
|
101 |
rodolico |
16 |
create or replace table attrib_category (
|
|
|
17 |
attrib_category_id int unsigned not null auto_increment,
|
|
|
18 |
name varchar(64),
|
|
|
19 |
added_date date not null comment 'When this category was added',
|
|
|
20 |
primary key (attrib_category_id)
|
|
|
21 |
) comment 'just allows us to categorize attributes';
|
|
|
22 |
|
|
|
23 |
CREATE or replace TABLE attrib_device (
|
99 |
rodolico |
24 |
attrib_device_id int unsigned not null auto_increment,
|
|
|
25 |
device_id int(10) unsigned NOT NULL REFERENCES device(device_id),
|
|
|
26 |
attrib_id int(10) unsigned NOT NULL REFERENCES attrib(attrib_id),
|
|
|
27 |
value text COMMENT 'The actual value of this attribute.',
|
101 |
rodolico |
28 |
added_date date NOT NULL COMMENT 'date record was added',
|
|
|
29 |
removed_date date default NULL,
|
99 |
rodolico |
30 |
PRIMARY KEY (attrib_device_id)
|
|
|
31 |
) COMMENT='links devices and their attributes together';
|
|
|
32 |
|
|
|
33 |
insert into attrib_category values ( 1,'General',now() );
|
|
|
34 |
|
106 |
rodolico |
35 |
/* add some indicies */
|
|
|
36 |
alter table attrib add index (name);
|
|
|
37 |
alter table attrib add index (added_date,removed_date);
|
|
|
38 |
|
|
|
39 |
alter table attrib_device add index (device_id);
|
|
|
40 |
alter table attrib_device add index (added_date,removed_date);
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
99 |
rodolico |
44 |
/* set up the _system table to plug in the module */
|
|
|
45 |
/* this is required, and officially installs the module */
|
|
|
46 |
insert into _system ( group_name,key_name,theValue,added_date) values ( 'Modules', 'Attributes', 'modules/attributes/', now() );
|
|
|
47 |
/* we will provide data to the main screen via a callback routine. In this case, function view is located in callable.php */
|
100 |
rodolico |
48 |
insert into _system( group_name,key_name,theValue,added_date ) values ( 'device view', 'Attributes', 'callable.php:attributeView', now() );
|
99 |
rodolico |
49 |
|
|
|
50 |
/* This has a menu entry, so add it */
|
|
|
51 |
/* first, make sure we don't have any danglies */
|
|
|
52 |
/* create three menu options. First one is the main menu option (ie, no parent_id) */
|
|
|
53 |
insert into menu( url, caption, parent_id) values ('/modules/attributes' , 'Attributes', null);
|
|
|
54 |
/* two additional menu options for bulk_load and editing the license_product table */
|
|
|
55 |
insert into menu( url,caption,parent_id) select '/modules/attributes/bulk_load.html','Bulk Load',menu_id from menu where caption = 'Attributes';
|
|
|
56 |
insert into menu( url,caption,parent_id) select '/modules/attributes/dmidecode_load.html','Load dmidecode file',menu_id from menu where caption = 'Attributes';
|
|
|
57 |
insert into menu( url,caption,parent_id) select '/modules/attributes/edit_device_attributes.html','Edit Device',menu_id from menu where caption = 'Attributes';
|
|
|
58 |
|
|
|
59 |
/* give all administrators the new menu */
|
|
|
60 |
insert into login_menu
|
|
|
61 |
select null,login_id,menu_id
|
|
|
62 |
from login,menu
|
|
|
63 |
where
|
|
|
64 |
login.removed_date is null
|
|
|
65 |
and login.where_clause = '1=1'
|
|
|
66 |
and (
|
|
|
67 |
menu.caption = 'Attributes'
|
|
|
68 |
or menu.parent_id = (select menu_id from menu where caption = 'Attributes')
|
|
|
69 |
)
|
|
|
70 |
;
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
/* do this only for upgrades */
|
|
|
74 |
insert into attrib (attrib_id,name,added_date,removed_date,keyname) select * from temp;
|
|
|
75 |
insert into attrib_device select device_attrib_id,device_id,attrib_id,value,added_date,removed_date from device_attrib;
|
|
|
76 |
|
103 |
rodolico |
77 |
update attrib set multiples = '1' where name in ( 'Alias','MAC Address','Mass Storage','Memory','Note', 'Power Supply' );
|
102 |
rodolico |
78 |
|
99 |
rodolico |
79 |
drop table temp;
|
|
|
80 |
drop table device_attrib;
|
102 |
rodolico |
81 |
|
|
|
82 |
update attrib set name = 'CPU Cores' where name = 'Cores per CPU';
|
|
|
83 |
|
|
|
84 |
update attrib set name = 'Firmware Revision' where name = 'Boot ROM Version';
|
|
|
85 |
update report set screen_report = null where name in ( 'Device Attributes', 'Device PCI' );
|
|
|
86 |
|
|
|
87 |
update attrib_device set attrib_id = 5 where attrib_id = 45;
|
|
|
88 |
update attrib set name = 'CPU Manufacturer',multiples=null where attrib_id = 45;
|
|
|
89 |
|
|
|
90 |
update attrib_device
|
|
|
91 |
set removed_date = now()
|
|
|
92 |
where
|
|
|
93 |
attrib_device_id in (
|
|
|
94 |
select toremove
|
|
|
95 |
from
|
|
|
96 |
(select
|
|
|
97 |
device_id,
|
|
|
98 |
min(attrib_device_id) toremove,
|
|
|
99 |
count(*)
|
|
|
100 |
from
|
|
|
101 |
attrib_device k
|
|
|
102 |
where
|
|
|
103 |
attrib_id = 5
|
|
|
104 |
and removed_date is null
|
|
|
105 |
group by device_id
|
|
|
106 |
having count(*) > 1) as j
|
|
|
107 |
);
|
|
|
108 |
|
|
|
109 |
|
99 |
rodolico |
110 |
/* end of only for upgrades section */
|