Subversion Repositories computer_asset_manager_v2

Rev

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

Rev Author Line No. Line
6 rodolico 1
/* 
2
   mySQL Database for Computer Asset Management Program
3
   No records are deleted by default. If record is to be deleted
4
   it is marked as removed (removed_date not null)
18 rodolico 5
   When joining tables (ie client_device) is modified, the old record is
6 rodolico 6
   marked removed and a new record added, to give history of device
7
*/
8
 
9
/* used as a configuration file for the app as a whole */
18 rodolico 10
drop table if exists _system;
11
create table _system (
6 rodolico 12
  _system_id      int unsigned not null auto_increment,
13
  group_name      varchar(64) NOT NULL COMMENT 'used to group keys together',
14
  key_name        varchar(64) NOT NULL COMMENT 'key into this value',
15
  theValue        text null COMMENT 'the actual value of this entry',
22 rodolico 16
  primary key     (_system_id )
6 rodolico 17
)  COMMENT='Basically a configuration file equivilent to a windows INI ';
18
 
19
/* used by the auth class */
18 rodolico 20
drop table if exists _user;
21
create table _user (
22
   _user_id     int unsigned not null auto_increment,
19 rodolico 23
   username     varchar(32) not null comment 'user name for logging in',
6 rodolico 24
   name         varchar(64) comment 'common name of user',
25
   email        varchar(64) comment 'email address of user',
26
   notes        text comment 'any notes about user',
20 rodolico 27
   passwd       varchar(256) comment 'encrypted password of user',
6 rodolico 28
   access       text comment 'sql to determine what records user can view',
18 rodolico 29
   added_date   date not null comment 'Date record added to database',
30
   removed_date date default null comment 'Date record marked as removed',
31
   primary key ( _user_id )
6 rodolico 32
) comment 'user access to program';
33
 
34
/* used by the menu class */
18 rodolico 35
drop table if exists _menu;
36
create table _menu (
37
   _menu_id        int unsigned not null auto_increment,
19 rodolico 38
   parent_id      int unsigned default null  comment 'If this is a submenu the id of the parent' REFERENCES _menu(_menu_id),
6 rodolico 39
   caption        varchar(20) not null comment 'The actual caption displayed',
19 rodolico 40
   url            varchar(120) default null comment 'the url of the page/script to call or null if this contains sub-options',
18 rodolico 41
   primary key    (_menu_id)
6 rodolico 42
) comment 'We keep the entire menu structure here so modules can modify it';
43
 
44
 
18 rodolico 45
/* beginning of the actual tables used by the app, client, site and device */
6 rodolico 46
 
18 rodolico 47
/*
48
   A device is owned by a client (entity). This is a list of available
49
   clients who can own things.
50
*/
51
drop table if exists client;
52
create table client (
6 rodolico 53
   client_id   int unsigned not null auto_increment,
54
   name        varchar(64) comment 'Name of the client',
55
   notes       text comment 'Any notes you want to enter',
22 rodolico 56
   internal_notes text comment 'private notes accessible only to technicians',
18 rodolico 57
   added_date  date not null comment 'Date record added to database',
58
   removed_date date default null comment 'Date record marked as removed',
6 rodolico 59
   primary key (client_id)
60
) comment 'Stores information about a particlar client/owner';
61
 
18 rodolico 62
/*
63
   A device can be on a site. This is a list of sites which can house
64
   devices
65
*/
66
drop table if exists site;
67
create table site (
6 rodolico 68
   site_id     int unsigned not null auto_increment,
69
   name        varchar(64) comment 'Name of the site',
70
   notes       text comment 'Any notes you want to enter',
18 rodolico 71
   added_date  date not null comment 'Date record added to database',
72
   removed_date date default null comment 'Date record marked as removed',
6 rodolico 73
   primary key (site_id)
74
) comment 'Stores information about a particlar physical site';
75
 
18 rodolico 76
/*
77
   The basis for the program. In our context, an asset is a computer or
78
   other device.
79
*/
80
drop table if exists device;
81
create table device (
82
   device_id    int unsigned not null auto_increment,
19 rodolico 83
   name        varchar(64) not null comment 'name of the device or device',
84
   notes       text default null comment 'any notes we want to store',
18 rodolico 85
   device_type_id int unsigned not null references device_type( device_type_id ),
86
   added_date  date not null comment 'Date record added to database',
87
   removed_date date default null comment 'Date record marked as removed',
88
   primary key (device_id)
89
) comment 'stores information about an individual device or other device';
6 rodolico 90
 
18 rodolico 91
/* 
92
   allows devices to be related to each other, ie a "part of" scheme, where 
93
   for example, a virtualized server may be 'part of' a physical machine.
94
   By using a child table, we can track movement across this relationship
95
*/
96
drop table if exists device_device;
97
create table device_device (
98
   device_device_id int unsigned not null auto_increment,
22 rodolico 99
   device_id    int unsigned not null references device( device_id ),
100
   parent_id    int unsigned not null references device( device_id ),
18 rodolico 101
   added_date  date not null comment 'Date record added to database',
102
   removed_date date default null comment 'Date record marked as removed',
103
   primary key (device_device_id)
104
) comment 'joins device to another device';
6 rodolico 105
 
106
/*
18 rodolico 107
   device_type is a child table of device, determining what type of device it is]
6 rodolico 108
   such as computer, printer, router, whatever.
109
   flags currently used as 0 is non system and 1 is system, though this could
110
   be expanded in the future
111
*/
18 rodolico 112
drop table if exists device_type;
113
create table device_type (
114
  device_type_id   int(10) unsigned NOT NULL auto_increment,
6 rodolico 115
  name            varchar(64) not null COMMENT 'the visible displayed name',
18 rodolico 116
  flags           int unsigned default 1 comment 'flags for this device type',
6 rodolico 117
  added_date      date not null COMMENT 'date record was added',
118
  removed_date    date default NULL COMMENT 'date record was deleted/supserceded',
18 rodolico 119
  primary key     (device_type_id)
6 rodolico 120
) comment='simply a list of device types ie computer printer whatever';
121
 
122
 
123
/* 
124
   this is actually a join with multiple tables, depending on what the
18 rodolico 125
   name is associated with, client, site or device
6 rodolico 126
   for example, if 'id' is client_id from the client table, then 'source'
127
   would be 'client' (name of the table);
128
*/
18 rodolico 129
drop table if exists alias;
130
create table alias (
6 rodolico 131
   alias_id int unsigned not null auto_increment,
132
   source   varchar(64) comment 'the table this alias comes from',
18 rodolico 133
   id       int unsigned not null comment 'the client, site or device id',
134
   name         varchar(64) comment 'the alias for the device',
135
   primary key (alias_id)
136
) comment 'Allows client, site and device to have multiple names';
6 rodolico 137
 
18 rodolico 138
/*
139
   links a site to a client. A site is "owned" by a client
140
*/
141
drop table if exists client_site;
142
create table client_site (
6 rodolico 143
   client_site_id int unsigned not null auto_increment,
144
   client_id   int unsigned not null references client( client_id ),
145
   site_id     int unsigned not null references site( site_id ),
18 rodolico 146
   added_date  date not null comment 'Date record added to database',
147
   removed_date date default null comment 'Date record marked as removed',
148
   primary key (client_site_id)
6 rodolico 149
) comment 'A client owns a site';
150
 
18 rodolico 151
/*
152
  A device is owned by a client. Ownership can be tracked by removing
153
  a device from one client and adding it to another.
154
*/
155
drop table if exists client_device;
156
create table client_device (
157
   client_device_id int unsigned not null auto_increment,
6 rodolico 158
   client_id   int unsigned not null references client( client_id ),
18 rodolico 159
   device_id    int unsigned not null references device( device_id ),
160
   added_date  date not null comment 'Date record added to database',
161
   removed_date date default null comment 'Date record marked as removed',
162
   primary key (client_device_id)
163
) comment 'Links client and device tables';
6 rodolico 164
 
18 rodolico 165
/*
166
   A device is at a location. Location history can be tracked by removing
167
   and adding a device to a new location
168
*/
169
drop table if exists site_device;
170
create table site_device (
171
   site_device_id int unsigned not null auto_increment,
6 rodolico 172
   site_id     int unsigned not null references site( site_id ),
18 rodolico 173
   device_id    int unsigned not null references device( device_id ),
174
   added_date  date not null comment 'Date record added to database',
175
   removed_date date default null comment 'Date record marked as removed',
176
   primary key ( site_device_id )
177
) comment 'Links site and device tables';
6 rodolico 178
 
179
/* add some indexes */
18 rodolico 180
alter table device add index (added_date,removed_date);
181
alter table device add index (removed_date);
182
alter table device add index (name);
183
alter table device add index (device_type_id);
6 rodolico 184
 
18 rodolico 185
alter table client_site add index ( client_id,site_id );
186
 
6 rodolico 187
alter table site add index (removed_date);
188
 
189
alter table client add index (removed_date);
190
 
18 rodolico 191
/* preload some data */
6 rodolico 192
 
18 rodolico 193
/* basic menu; home and logout */
194
insert into _menu values ( null, null, 'Home Page', 'index.html' );
195
insert into _menu values ( null, null, 'Log Out', 'logout.html' );
6 rodolico 196
 
18 rodolico 197
/* one user, admin, with no password for initial access */
198
insert into _user( username,added_date) values ( 'admin', now() );
6 rodolico 199
 
22 rodolico 200
/* insert into device_type (name,flags, added_date ) values ( 'Computer',1,now() ); */