Subversion Repositories computer_asset_manager_v2

Rev

Rev 26 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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