Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 rodolico 1
/*
2
   The base install of CAMP2.
3
 
4
   Just track devices. A device can be any arbitrary item.
5
   A device has one owner, and is located at one site (location)
6
   A site also has an owner. Devices can be located on locations
7
   owned by a different client, ie when a device is lent to a client
8
   or colocated at a third party NOC.
9
 
10
   This is very basic. It only tracks device ownership and locations,
11
   and movement between them (via the created and removed fields).
12
   When a device is moved to a different location, or sold to a different
13
   client, the old record in the linking field has its removed field 
14
   updated and a new record created with a created date. With this, we
15
   can track the lifespan of a device.
16
 
17
   It is assumed various modules will be created to extend the capabilities
18
   of this basic structure. However, modules should not modify the basic
19
   database structure, instead creating new tables that link into
20
   these tables.
21
*/
22
 
23
/*
24
   configuration of application. DB representation of old Windows INI file format
25
   containing groups, and under groups key/value pairs
26
*/
27
drop table if exists _system;
28
create table _system (
29
  _system_id      int unsigned not null auto_increment,
30
  group_name      varchar(45) not null comment 'Group name for matching',
31
  key_name        varchar(45) not null comment 'key name for matching',
32
  key_value       varchar(45) not null comment 'value for key_name',
33
  primary key     (_system_id)
34
)
35
comment = 'Stores internal system information like ini file';
36
 
37
/*
38
   holds menu, which may be modified programmatically.
39
   This is a hierarchial menu so an entry may have a parent entry
40
*/
41
drop table if exists _menu;
42
create table _menu (
43
   _menu_id       int unsigned not null auto_increment,
37 rodolico 44
   parent_id      int unsigned default null references _menu (_menu_id),
33 rodolico 45
   caption        varchar(20) not null comment 'Caption displayed for menu',
46
   url            varchar(64) default null comment 'optional URL when they click here',
47
   primary key    (_menu_id)
48
) comment = 'Menus for the application';
49
 
37 rodolico 50
insert into camp2._menu values (null,null,'Home', '/index.php');
33 rodolico 51
 
52
/*
53
   simple table to hold ownership information
54
*/
55
drop table if exists client;
56
create table client (
57
   client_id      int unsigned not null auto_increment,
58
   name           varchar(64) comment 'name of client',
59
   created        date comment 'date record was created',
60
   removed        date comment 'date record was removed',
61
   primary key    (client_id)
62
) comment 'hold client information';
63
 
64
/*
65
   simple table to hold site where a device is located
66
*/
67
drop table if exists site;
68
create table site (
69
   site_id        int unsigned not null auto_increment,
70
   name           varchar(64) comment 'name of site',
71
   created        date comment 'date record was created',
72
   removed        date comment 'date record was removed',
73
   primary key    (site_id)
74
) comment 'hold site information';
75
 
76
/*
77
   table which holds a device type, such as server, workstation
78
   printer, virtual, etc...
79
*/
80
drop table if exists device_type;
81
create table device_type (
82
   device_type_id int unsigned not null auto_increment,
83
   name           varchar(64) comment 'name of device type',
84
   show_as_system boolean comment 'if true, this is a system, ie a computer or virtual',
85
   created        date comment 'date record was created',
86
   removed        date comment 'date record was removed',
87
   primary key    (device_type_id)
88
) comment 'simple child table to determine the type of device we have';
89
 
90
/*
91
   holds very basic information on a device such as its type, location,
92
   and owner. This is the main table for the database, and each device
93
   should be uniquely identified. We will allow name to be modified
94
   randomly, however.
95
 
96
   Internally, we find this device based on device_id, but for remote
97
   systems, we use the combined uuid and serial to uniquely identify
98
   some manufacturers use one uuid for all systems, but the uuid and serial
99
   number combination should be unique. serial can be any arbitrary string
100
   and it is suggested to use manufacturer:serial or something like that
101
*/
102
drop table if exists device;
103
create table device (
104
   device_id      int unsigned not null auto_increment,
105
   uuid           varchar(32) comment 'unique id of this device, normally uuid',
106
   serial         varchar(32) comment 'serial number of this device, if we have it',
107
   name           varchar(64) comment 'name of device',
108
   device_type_id int unsigned not null references device_type( device_type_id ),
109
   created        date comment 'date record was created',
110
   removed        date comment 'date record was removed',
111
/*   unique key     unique_uuid( uuid, serial ), */
112
   primary key    (device_id)
113
) comment 'holds individual devices';
114
 
115
 
116
/*
117
   Set ownership of a site. These records are not deleted, but by
118
   setting field removed to non-null value, then creating a new record,
119
   we can track ownership of sites.
120
*/
121
drop table if exists client_site;
122
create table client_site (
123
   client_site_id int unsigned not null auto_increment,
124
   client_id      int unsigned not null references client( client_id ),
125
   site_id        int unsigned not null references site( site_id ),
126
   created        date comment 'date record was created',
127
   removed        date comment 'date record was removed',
128
   index          site_device ( client_id,site_id ),
129
   primary key    (client_site_id)
130
) comment 'links ownership of a site to a client';   
131
 
132
/*
133
   Set location of a device. These records are not deleted, but by
134
   setting field removed to non-null value, then creating a new record,
135
   we can track movement of devices.
136
*/
137
drop table if exists site_device;
138
create table site_device (
139
   site_device_id int unsigned not null auto_increment,
140
   site_id        int unsigned not null references site( site_id ),
141
   device_id      int unsigned not null references device( device_id ),
142
   created        date comment 'date record was created',
143
   removed        date comment 'date record was removed',
144
   index          site_device ( site_id,device_id ),
145
   primary key    (site_device_id)
146
) comment 'links a device to its location';
147
 
148
/*
149
   Set ownership of a device. These records are not deleted, but by
150
   setting field removed to non-null value, then creating a new record,
151
   we can track ownership of devices.
152
*/
153
drop table if exists client_device;
154
create table client_device (
155
   client_device_id  int unsigned not null auto_increment,
156
   client_id      int unsigned not null references client( client_id ),
157
   device_id      int unsigned not null references device( device_id ),
158
   created        date comment 'date record was created',
159
   removed        date comment 'date record was removed',
160
   index          client_device( client_id, device_id ),
161
   primary key    ( client_device_id )
162
) comment 'links a device to its owner';
163
 
164
/*
165
   There can be a parent/child relationship with devices. For example, a virtual
166
   resides on a DOM0, so the parent_id of a DOMU is the device_id of the DOM0.
167
   or, a printer can be attached to a computer, so the printers parent is the
168
   device_id of the computer it is attached to.
169
*/
170
drop table if exists device_device;
171
create table device_device (
172
   device_device_id int unsigned not null auto_increment,
173
   device_id      int unsigned not null references device( device_id ),
174
   parent_id      int unsigned not null references device( device_id ),
175
   created        date comment 'date record was created',
176
   removed        date comment 'date record was removed',
177
   index          device_device( device_id, parent_id ),
178
   primary key    ( device_device_id )
179
) comment 'links a device to another device';
180
 
181
 
182
drop view if exists view_device_site_client;
183
create view view_device_site_client as
184
   select
185
      device.device_id,
186
      device.name device,
187
      device.created device_created,
188
      device.removed device_removed,
189
      device_type.device_type_id,
190
      device_type.name device_type,
191
      site.site_id,
192
      site.name site,
193
      site.created site_created,
194
      site.removed site_removed,
195
      client.client_id,
196
      client.name client,
197
      client.created client_created,
198
      client.removed client_removed
199
   from
200
      device
201
      join site_device using (device_id)
202
      join site using (site_id)
203
      join client_device using (device_id)
204
      join client using (client_id)
205
      join device_type using (device_type_id);
206
 
36 rodolico 207
 
208
insert into _system ( key_value, group_name, key_name ) values ( '0.1','database','version' );