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,
44
   parent_id      int unsigned not null references _menu (_menu_id),
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
 
50
 
51
/*
52
   simple table to hold ownership information
53
*/
54
drop table if exists client;
55
create table client (
56
   client_id      int unsigned not null auto_increment,
57
   name           varchar(64) comment 'name of client',
58
   created        date comment 'date record was created',
59
   removed        date comment 'date record was removed',
60
   primary key    (client_id)
61
) comment 'hold client information';
62
 
63
/*
64
   simple table to hold site where a device is located
65
*/
66
drop table if exists site;
67
create table site (
68
   site_id        int unsigned not null auto_increment,
69
   name           varchar(64) comment 'name of site',
70
   created        date comment 'date record was created',
71
   removed        date comment 'date record was removed',
72
   primary key    (site_id)
73
) comment 'hold site information';
74
 
75
/*
76
   table which holds a device type, such as server, workstation
77
   printer, virtual, etc...
78
*/
79
drop table if exists device_type;
80
create table device_type (
81
   device_type_id int unsigned not null auto_increment,
82
   name           varchar(64) comment 'name of device type',
83
   show_as_system boolean comment 'if true, this is a system, ie a computer or virtual',
84
   created        date comment 'date record was created',
85
   removed        date comment 'date record was removed',
86
   primary key    (device_type_id)
87
) comment 'simple child table to determine the type of device we have';
88
 
89
/*
90
   holds very basic information on a device such as its type, location,
91
   and owner. This is the main table for the database, and each device
92
   should be uniquely identified. We will allow name to be modified
93
   randomly, however.
94
 
95
   Internally, we find this device based on device_id, but for remote
96
   systems, we use the combined uuid and serial to uniquely identify
97
   some manufacturers use one uuid for all systems, but the uuid and serial
98
   number combination should be unique. serial can be any arbitrary string
99
   and it is suggested to use manufacturer:serial or something like that
100
*/
101
drop table if exists device;
102
create table device (
103
   device_id      int unsigned not null auto_increment,
104
   uuid           varchar(32) comment 'unique id of this device, normally uuid',
105
   serial         varchar(32) comment 'serial number of this device, if we have it',
106
   name           varchar(64) comment 'name of device',
107
   device_type_id int unsigned not null references device_type( device_type_id ),
108
   created        date comment 'date record was created',
109
   removed        date comment 'date record was removed',
110
/*   unique key     unique_uuid( uuid, serial ), */
111
   primary key    (device_id)
112
) comment 'holds individual devices';
113
 
114
 
115
/*
116
   Set ownership of a site. These records are not deleted, but by
117
   setting field removed to non-null value, then creating a new record,
118
   we can track ownership of sites.
119
*/
120
drop table if exists client_site;
121
create table client_site (
122
   client_site_id int unsigned not null auto_increment,
123
   client_id      int unsigned not null references client( client_id ),
124
   site_id        int unsigned not null references site( site_id ),
125
   created        date comment 'date record was created',
126
   removed        date comment 'date record was removed',
127
   index          site_device ( client_id,site_id ),
128
   primary key    (client_site_id)
129
) comment 'links ownership of a site to a client';   
130
 
131
/*
132
   Set location of a device. These records are not deleted, but by
133
   setting field removed to non-null value, then creating a new record,
134
   we can track movement of devices.
135
*/
136
drop table if exists site_device;
137
create table site_device (
138
   site_device_id int unsigned not null auto_increment,
139
   site_id        int unsigned not null references site( site_id ),
140
   device_id      int unsigned not null references device( device_id ),
141
   created        date comment 'date record was created',
142
   removed        date comment 'date record was removed',
143
   index          site_device ( site_id,device_id ),
144
   primary key    (site_device_id)
145
) comment 'links a device to its location';
146
 
147
/*
148
   Set ownership of a device. These records are not deleted, but by
149
   setting field removed to non-null value, then creating a new record,
150
   we can track ownership of devices.
151
*/
152
drop table if exists client_device;
153
create table client_device (
154
   client_device_id  int unsigned not null auto_increment,
155
   client_id      int unsigned not null references client( client_id ),
156
   device_id      int unsigned not null references device( device_id ),
157
   created        date comment 'date record was created',
158
   removed        date comment 'date record was removed',
159
   index          client_device( client_id, device_id ),
160
   primary key    ( client_device_id )
161
) comment 'links a device to its owner';
162
 
163
/*
164
   There can be a parent/child relationship with devices. For example, a virtual
165
   resides on a DOM0, so the parent_id of a DOMU is the device_id of the DOM0.
166
   or, a printer can be attached to a computer, so the printers parent is the
167
   device_id of the computer it is attached to.
168
*/
169
drop table if exists device_device;
170
create table device_device (
171
   device_device_id int unsigned not null auto_increment,
172
   device_id      int unsigned not null references device( device_id ),
173
   parent_id      int unsigned not null references device( device_id ),
174
   created        date comment 'date record was created',
175
   removed        date comment 'date record was removed',
176
   index          device_device( device_id, parent_id ),
177
   primary key    ( device_device_id )
178
) comment 'links a device to another device';
179
 
180
 
181
drop view if exists view_device_site_client;
182
create view view_device_site_client as
183
   select
184
      device.device_id,
185
      device.name device,
186
      device.created device_created,
187
      device.removed device_removed,
188
      device_type.device_type_id,
189
      device_type.name device_type,
190
      site.site_id,
191
      site.name site,
192
      site.created site_created,
193
      site.removed site_removed,
194
      client.client_id,
195
      client.name client,
196
      client.created client_created,
197
      client.removed client_removed
198
   from
199
      device
200
      join site_device using (device_id)
201
      join site using (site_id)
202
      join client_device using (device_id)
203
      join client using (client_id)
204
      join device_type using (device_type_id);
205
 
36 rodolico 206
 
207
insert into _system ( key_value, group_name, key_name ) values ( '0.1','database','version' );