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',
|
|
|
16 |
PRIMARY KEY (_system_id )
|
|
|
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',
|
11 |
rodolico |
27 |
pass 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',
|
18 |
rodolico |
56 |
added_date date not null comment 'Date record added to database',
|
|
|
57 |
removed_date date default null comment 'Date record marked as removed',
|
6 |
rodolico |
58 |
primary key (client_id)
|
|
|
59 |
) comment 'Stores information about a particlar client/owner';
|
|
|
60 |
|
18 |
rodolico |
61 |
/*
|
|
|
62 |
A device can be on a site. This is a list of sites which can house
|
|
|
63 |
devices
|
|
|
64 |
*/
|
|
|
65 |
drop table if exists site;
|
|
|
66 |
create table site (
|
6 |
rodolico |
67 |
site_id int unsigned not null auto_increment,
|
|
|
68 |
name varchar(64) comment 'Name of the site',
|
|
|
69 |
notes text comment 'Any notes you want to enter',
|
18 |
rodolico |
70 |
added_date date not null comment 'Date record added to database',
|
|
|
71 |
removed_date date default null comment 'Date record marked as removed',
|
6 |
rodolico |
72 |
primary key (site_id)
|
|
|
73 |
) comment 'Stores information about a particlar physical site';
|
|
|
74 |
|
18 |
rodolico |
75 |
/*
|
|
|
76 |
The basis for the program. In our context, an asset is a computer or
|
|
|
77 |
other device.
|
|
|
78 |
*/
|
|
|
79 |
drop table if exists device;
|
|
|
80 |
create table device (
|
|
|
81 |
device_id int unsigned not null auto_increment,
|
19 |
rodolico |
82 |
name varchar(64) not null comment 'name of the device or device',
|
|
|
83 |
notes text default null comment 'any notes we want to store',
|
18 |
rodolico |
84 |
device_type_id int unsigned not null references device_type( device_type_id ),
|
|
|
85 |
added_date date not null comment 'Date record added to database',
|
|
|
86 |
removed_date date default null comment 'Date record marked as removed',
|
|
|
87 |
primary key (device_id)
|
|
|
88 |
) comment 'stores information about an individual device or other device';
|
6 |
rodolico |
89 |
|
18 |
rodolico |
90 |
/*
|
|
|
91 |
allows devices to be related to each other, ie a "part of" scheme, where
|
|
|
92 |
for example, a virtualized server may be 'part of' a physical machine.
|
|
|
93 |
By using a child table, we can track movement across this relationship
|
|
|
94 |
*/
|
|
|
95 |
drop table if exists device_device;
|
|
|
96 |
create table device_device (
|
|
|
97 |
device_device_id int unsigned not null auto_increment,
|
|
|
98 |
source int unsigned not null references device( device_id ),
|
|
|
99 |
target int unsigned not null references device( device_id ),
|
|
|
100 |
added_date date not null comment 'Date record added to database',
|
|
|
101 |
removed_date date default null comment 'Date record marked as removed',
|
|
|
102 |
primary key (device_device_id)
|
|
|
103 |
) comment 'joins device to another device';
|
6 |
rodolico |
104 |
|
|
|
105 |
/*
|
18 |
rodolico |
106 |
device_type is a child table of device, determining what type of device it is]
|
6 |
rodolico |
107 |
such as computer, printer, router, whatever.
|
|
|
108 |
flags currently used as 0 is non system and 1 is system, though this could
|
|
|
109 |
be expanded in the future
|
|
|
110 |
*/
|
18 |
rodolico |
111 |
drop table if exists device_type;
|
|
|
112 |
create table device_type (
|
|
|
113 |
device_type_id int(10) unsigned NOT NULL auto_increment,
|
6 |
rodolico |
114 |
name varchar(64) not null COMMENT 'the visible displayed name',
|
18 |
rodolico |
115 |
flags int unsigned default 1 comment 'flags for this device type',
|
6 |
rodolico |
116 |
added_date date not null COMMENT 'date record was added',
|
|
|
117 |
removed_date date default NULL COMMENT 'date record was deleted/supserceded',
|
18 |
rodolico |
118 |
primary key (device_type_id)
|
6 |
rodolico |
119 |
) comment='simply a list of device types ie computer printer whatever';
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
/*
|
|
|
123 |
this is actually a join with multiple tables, depending on what the
|
18 |
rodolico |
124 |
name is associated with, client, site or device
|
6 |
rodolico |
125 |
for example, if 'id' is client_id from the client table, then 'source'
|
|
|
126 |
would be 'client' (name of the table);
|
|
|
127 |
*/
|
18 |
rodolico |
128 |
drop table if exists alias;
|
|
|
129 |
create table alias (
|
6 |
rodolico |
130 |
alias_id int unsigned not null auto_increment,
|
|
|
131 |
source varchar(64) comment 'the table this alias comes from',
|
18 |
rodolico |
132 |
id int unsigned not null comment 'the client, site or device id',
|
|
|
133 |
name varchar(64) comment 'the alias for the device',
|
|
|
134 |
primary key (alias_id)
|
|
|
135 |
) comment 'Allows client, site and device to have multiple names';
|
6 |
rodolico |
136 |
|
18 |
rodolico |
137 |
/*
|
|
|
138 |
links a site to a client. A site is "owned" by a client
|
|
|
139 |
*/
|
|
|
140 |
drop table if exists client_site;
|
|
|
141 |
create table client_site (
|
6 |
rodolico |
142 |
client_site_id int unsigned not null auto_increment,
|
|
|
143 |
client_id int unsigned not null references client( client_id ),
|
|
|
144 |
site_id int unsigned not null references site( site_id ),
|
18 |
rodolico |
145 |
added_date date not null comment 'Date record added to database',
|
|
|
146 |
removed_date date default null comment 'Date record marked as removed',
|
|
|
147 |
primary key (client_site_id)
|
6 |
rodolico |
148 |
) comment 'A client owns a site';
|
|
|
149 |
|
18 |
rodolico |
150 |
/*
|
|
|
151 |
A device is owned by a client. Ownership can be tracked by removing
|
|
|
152 |
a device from one client and adding it to another.
|
|
|
153 |
*/
|
|
|
154 |
drop table if exists client_device;
|
|
|
155 |
create table client_device (
|
|
|
156 |
client_device_id int unsigned not null auto_increment,
|
6 |
rodolico |
157 |
client_id int unsigned not null references client( client_id ),
|
18 |
rodolico |
158 |
device_id int unsigned not null references device( device_id ),
|
|
|
159 |
added_date date not null comment 'Date record added to database',
|
|
|
160 |
removed_date date default null comment 'Date record marked as removed',
|
|
|
161 |
primary key (client_device_id)
|
|
|
162 |
) comment 'Links client and device tables';
|
6 |
rodolico |
163 |
|
18 |
rodolico |
164 |
/*
|
|
|
165 |
A device is at a location. Location history can be tracked by removing
|
|
|
166 |
and adding a device to a new location
|
|
|
167 |
*/
|
|
|
168 |
drop table if exists site_device;
|
|
|
169 |
create table site_device (
|
|
|
170 |
site_device_id int unsigned not null auto_increment,
|
6 |
rodolico |
171 |
site_id int unsigned not null references site( site_id ),
|
18 |
rodolico |
172 |
device_id int unsigned not null references device( device_id ),
|
|
|
173 |
added_date date not null comment 'Date record added to database',
|
|
|
174 |
removed_date date default null comment 'Date record marked as removed',
|
|
|
175 |
primary key ( site_device_id )
|
|
|
176 |
) comment 'Links site and device tables';
|
6 |
rodolico |
177 |
|
|
|
178 |
/* add some indexes */
|
18 |
rodolico |
179 |
alter table device add index (added_date,removed_date);
|
|
|
180 |
alter table device add index (removed_date);
|
|
|
181 |
alter table device add index (name);
|
|
|
182 |
alter table device add index (device_type_id);
|
6 |
rodolico |
183 |
|
18 |
rodolico |
184 |
alter table client_site add index ( client_id,site_id );
|
|
|
185 |
|
6 |
rodolico |
186 |
alter table site add index (removed_date);
|
|
|
187 |
|
|
|
188 |
alter table client add index (removed_date);
|
|
|
189 |
|
18 |
rodolico |
190 |
/* preload some data */
|
6 |
rodolico |
191 |
|
18 |
rodolico |
192 |
/* basic menu; home and logout */
|
|
|
193 |
insert into _menu values ( null, null, 'Home Page', 'index.html' );
|
|
|
194 |
insert into _menu values ( null, null, 'Log Out', 'logout.html' );
|
6 |
rodolico |
195 |
|
18 |
rodolico |
196 |
/* one user, admin, with no password for initial access */
|
|
|
197 |
insert into _user( username,added_date) values ( 'admin', now() );
|
6 |
rodolico |
198 |
|
18 |
rodolico |
199 |
insert into device_type (name,flags, added_date ) values ( 'Computer',1,now() );
|