Subversion Repositories computer_asset_manager_v1

Rev

Rev 106 | Details | Compare with Previous | Last modification | View Log | RSS feed

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