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)
|
|
|
5 |
When joining tables (ie client_asset) is modified, the old record is
|
|
|
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 */
|
|
|
10 |
create or replace table _system (
|
|
|
11 |
_system_id int unsigned not null auto_increment,
|
|
|
12 |
group_name varchar(64) NOT NULL COMMENT 'used to group keys together',
|
|
|
13 |
key_name varchar(64) NOT NULL COMMENT 'key into this value',
|
|
|
14 |
theValue text null COMMENT 'the actual value of this entry',
|
|
|
15 |
added_date datetime not null COMMENT 'date record was added',
|
|
|
16 |
removed_date datetime default NULL COMMENT 'date record was closed',
|
|
|
17 |
PRIMARY KEY (_system_id )
|
|
|
18 |
) COMMENT='Basically a configuration file equivilent to a windows INI ';
|
|
|
19 |
|
|
|
20 |
/* used by the auth class */
|
|
|
21 |
create or replace table user (
|
|
|
22 |
user_id int unsigned not null auto_increment,
|
|
|
23 |
name varchar(64) comment 'common name of user',
|
|
|
24 |
email varchar(64) comment 'email address of user',
|
|
|
25 |
notes text comment 'any notes about user',
|
|
|
26 |
pass varchar(64) comment 'encrypted password of user',
|
|
|
27 |
access text comment 'sql to determine what records user can view',
|
|
|
28 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
29 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
30 |
primary key (user_id)
|
|
|
31 |
) comment 'user access to program';
|
|
|
32 |
|
|
|
33 |
/* used by the menu class */
|
|
|
34 |
create or replace table menu (
|
|
|
35 |
menu_id int unsigned not null auto_increment,
|
|
|
36 |
parent_id int unsigned null comment 'If this is a submenu the id of the parent' REFERENCES menu(menu_id),
|
|
|
37 |
caption varchar(20) not null comment 'The actual caption displayed',
|
|
|
38 |
url varchar(120) null comment 'the url of the page/script to call or null if this contains sub-options',
|
|
|
39 |
primary key (menu_id)
|
|
|
40 |
) comment 'We keep the entire menu structure here so modules can modify it';
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
/* used by report class */
|
|
|
44 |
create or replace table report (
|
|
|
45 |
report_id int unsigned not null auto_increment,
|
|
|
46 |
name varchar(64) not null comment 'Display Name of Report',
|
|
|
47 |
query text not null comment 'Query to be executed',
|
|
|
48 |
parameters text comment 'All parameters used in above',
|
|
|
49 |
screen_report int unsigned default null comment 'Each screen can be assigned a bit and this will show up on a screen',
|
|
|
50 |
primary key (report_id)
|
|
|
51 |
) comment 'holds definition for report';
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
/* beginning of the actual tables used by the app, client, site and asset */
|
|
|
55 |
|
|
|
56 |
create or replace table client (
|
|
|
57 |
client_id int unsigned not null auto_increment,
|
|
|
58 |
name varchar(64) comment 'Name of the client',
|
|
|
59 |
notes text comment 'Any notes you want to enter',
|
|
|
60 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
61 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
62 |
primary key (client_id)
|
|
|
63 |
) comment 'Stores information about a particlar client/owner';
|
|
|
64 |
|
|
|
65 |
create or replace table site (
|
|
|
66 |
site_id int unsigned not null auto_increment,
|
|
|
67 |
name varchar(64) comment 'Name of the site',
|
|
|
68 |
notes text comment 'Any notes you want to enter',
|
|
|
69 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
70 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
71 |
primary key (site_id)
|
|
|
72 |
) comment 'Stores information about a particlar physical site';
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
create or replace table asset (
|
|
|
77 |
asset_id int unsigned not null auto_increment,
|
|
|
78 |
name varchar(64) comment 'name of the device or asset',
|
|
|
79 |
notes text comment 'any notes we want to store',
|
|
|
80 |
part_of int unsigned null references asset( asset_id),
|
|
|
81 |
asset_type_id int unsigned not null references asset_type( asset_type_id ),
|
|
|
82 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
83 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
84 |
primary key (asset_id)
|
|
|
85 |
) comment 'stores information about an individual device or other asset';
|
|
|
86 |
|
|
|
87 |
create or replace table asset_relationship (
|
|
|
88 |
asset_relationship_id int unsigned not null auto_increment,
|
|
|
89 |
source int unsigned not null references asset( asset_id ),
|
|
|
90 |
target int unsigned not null references asset( asset_id ),
|
|
|
91 |
primary key (asset_relationship_id)
|
|
|
92 |
) comment 'joins asset to another asset';
|
|
|
93 |
|
|
|
94 |
/*
|
|
|
95 |
asset_type is a child table of asset, determining what type of asset it is]
|
|
|
96 |
such as computer, printer, router, whatever.
|
|
|
97 |
flags currently used as 0 is non system and 1 is system, though this could
|
|
|
98 |
be expanded in the future
|
|
|
99 |
*/
|
|
|
100 |
|
|
|
101 |
create or replace table asset_type (
|
|
|
102 |
asset_type_id int(10) unsigned NOT NULL auto_increment,
|
|
|
103 |
name varchar(64) not null COMMENT 'the visible displayed name',
|
|
|
104 |
flags int unsigned default 1 comment 'flags for this asset type',
|
|
|
105 |
added_date date not null COMMENT 'date record was added',
|
|
|
106 |
removed_date date default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
107 |
primary key (asset_type_id)
|
|
|
108 |
) comment='simply a list of device types ie computer printer whatever';
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
/*
|
|
|
112 |
this is actually a join with multiple tables, depending on what the
|
|
|
113 |
name is associated with, client, site or asset
|
|
|
114 |
for example, if 'id' is client_id from the client table, then 'source'
|
|
|
115 |
would be 'client' (name of the table);
|
|
|
116 |
*/
|
|
|
117 |
create or replace table alias (
|
|
|
118 |
alias_id int unsigned not null auto_increment,
|
|
|
119 |
source varchar(64) comment 'the table this alias comes from',
|
|
|
120 |
id int unsigned not null comment 'the client, site or asset id',
|
|
|
121 |
name varchar(64) comment 'the alias for the asset',
|
|
|
122 |
primary key (asset_alias_id)
|
|
|
123 |
) comment 'Allows client, site and asset to have multiple names';
|
|
|
124 |
|
|
|
125 |
create or replace table client_site (
|
|
|
126 |
client_site_id int unsigned not null auto_increment,
|
|
|
127 |
client_id int unsigned not null references client( client_id ),
|
|
|
128 |
site_id int unsigned not null references site( site_id ),
|
|
|
129 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
130 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
131 |
primary key (client_id,asset_id)
|
|
|
132 |
) comment 'A client owns a site';
|
|
|
133 |
|
|
|
134 |
create or replace table client_asset (
|
|
|
135 |
client_asset_id int unsigned not null auto_increment,
|
|
|
136 |
client_id int unsigned not null references client( client_id ),
|
|
|
137 |
asset_id int unsigned not null references asset( asset_id ),
|
|
|
138 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
139 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
140 |
primary key (client_asset_id)
|
|
|
141 |
) comment 'Links client and asset tables';
|
|
|
142 |
|
|
|
143 |
create or replace table site_asset (
|
|
|
144 |
site_asset_id int unsigned not null auto_increment,
|
|
|
145 |
site_id int unsigned not null references site( site_id ),
|
|
|
146 |
asset_id int unsigned not null references asset( asset_id ),
|
|
|
147 |
added_date date not null default now() comment 'Date record added to database',
|
|
|
148 |
removed_date date null default null comment 'Date record marked as removed',
|
|
|
149 |
primary key ( site_asset_id )
|
|
|
150 |
) comment 'Links site and asset tables';
|
|
|
151 |
|
|
|
152 |
/* add some indexes */
|
|
|
153 |
alter table asset add index (added_date,removed_date);
|
|
|
154 |
alter table asset add index (part_of);
|
|
|
155 |
alter table asset add index (removed_date);
|
|
|
156 |
alter table asset add index (site_id);
|
|
|
157 |
alter table asset add index (name);
|
|
|
158 |
alter table asset add index (asset_type_id);
|
|
|
159 |
|
|
|
160 |
alter table site add index (removed_date);
|
|
|
161 |
|
|
|
162 |
alter table client add index (removed_date);
|
|
|
163 |
|
|
|
164 |
/* some convenience views */
|
|
|
165 |
|
|
|
166 |
/* this will combine asset, client and site */
|
|
|
167 |
create or replace view view_current_asset_full as
|
|
|
168 |
select
|
|
|
169 |
asset.name 'asset',
|
|
|
170 |
client.name 'client',
|
|
|
171 |
site.name 'site'
|
|
|
172 |
from
|
|
|
173 |
asset
|
|
|
174 |
join client using( client_id )
|
|
|
175 |
join site using ( site_id )
|
|
|
176 |
where
|
|
|
177 |
client.removed_date is null
|
|
|
178 |
and site.removed_date is null
|
|
|
179 |
and asset.removed_date is null;
|
|
|
180 |
|
|
|
181 |
create or replace view view_asset_name as
|
|
|
182 |
select
|
|
|
183 |
asset_id 'asset_id',
|
|
|
184 |
null 'alias_id',
|
|
|
185 |
name 'name'
|
|
|
186 |
from asset
|
|
|
187 |
union
|
|
|
188 |
select
|
|
|
189 |
asset_id 'asset_id',
|
|
|
190 |
alias_id 'alias_id',
|
|
|
191 |
name 'name'
|
|
|
192 |
from
|
|
|
193 |
asset_alias
|
|
|
194 |
where
|
|
|
195 |
source = 'asset';
|
|
|
196 |
|
|
|
197 |
create or replace view view_client_name as
|
|
|
198 |
select
|
|
|
199 |
client_id 'client_id',
|
|
|
200 |
null 'alias_id',
|
|
|
201 |
name 'name'
|
|
|
202 |
from client
|
|
|
203 |
union
|
|
|
204 |
select
|
|
|
205 |
id 'client_id',
|
|
|
206 |
alias_id 'alias_id',
|
|
|
207 |
name 'name'
|
|
|
208 |
from
|
|
|
209 |
alias
|
|
|
210 |
where
|
|
|
211 |
source = 'client';
|
|
|
212 |
|
|
|
213 |
create or replace view view_site_name as
|
|
|
214 |
select
|
|
|
215 |
site_id 'site_id',
|
|
|
216 |
null 'alias_id',
|
|
|
217 |
name 'name'
|
|
|
218 |
from site
|
|
|
219 |
union
|
|
|
220 |
select
|
|
|
221 |
id 'site_id',
|
|
|
222 |
alias_id 'alias_id',
|
|
|
223 |
name 'name'
|
|
|
224 |
from
|
|
|
225 |
alias
|
|
|
226 |
where
|
|
|
227 |
source = 'site';
|
|
|
228 |
|