Subversion Repositories computer_asset_manager_v1

Rev

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

Rev Author Line No. Line
1 rodolico 1
/*
2
   SQL information for the root module of CAMP
3
   Some conventions for these tables:
4
    tablename_id - Primary key for table
5
    added_date   - Date the record was added
6
    removed_date - Date record was removed/superceded
7
    fk id        - links into a separate table (ie, foreign key)
8
*/
9
 
10
DROP TABLE IF EXISTS _system;
11
CREATE TABLE _system (
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
  added_date      datetime not null COMMENT 'date record was added',
17
  removed_date    datetime default NULL COMMENT 'date record was closed',
18
  PRIMARY KEY     (_system_id )
19
)  COMMENT='Basically a configuration file equivilent to a windows INI ';
20
 
21
DROP TABLE IF EXISTS attrib;
22
CREATE TABLE attrib (
23
  attrib_id       int(10) unsigned NOT NULL auto_increment,
24
  name            varchar(64) not null unique COMMENT 'the visible displayed name',
25
  added_date      datetime not null COMMENT 'date record was added',
26
  removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
27
  PRIMARY KEY     (attrib_id)
28
)   COMMENT='These are attributes that can be applied to a device';
29
 
30
 
31
DROP TABLE IF EXISTS client;
32
CREATE TABLE client (
33
  client_id       int(10) unsigned NOT NULL auto_increment,
34
  name            varchar(64) not null COMMENT 'the visible displayed name',
35
  notes           text COMMENT 'world visible notes on the client',
36
  internal_notes  text COMMENT 'These are internal notes visible only to us',
37
  added_date      datetime not null COMMENT 'date record was added',
38
  removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
39
  PRIMARY KEY     (client_id)
40
)   COMMENT='information on a particular client';
41
 
42
DROP TABLE IF EXISTS site;
43
CREATE TABLE site (
44
  site_id         int(10) unsigned NOT NULL auto_increment,
45
  client_id       int(10) unsigned NOT NULL REFERENCES client(client_id),
46
  name            varchar(64) not null COMMENT 'the visible displayed name',
47
  notes           text COMMENT 'Just a place to record some notes',
48
  added_date      datetime not null COMMENT 'date record was added',
49
  removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
50
  PRIMARY KEY     (site_id)
51
)   COMMENT='information on a site which is tied to a client';
52
 
53
DROP TABLE IF EXISTS device;
54
CREATE TABLE device (
55
  device_id       int(10) unsigned NOT NULL auto_increment,
56
  site_id         int(10) unsigned NOT NULL REFERENCES site(site_id),
57
  device_type_id  int(10) unsigned NOT NULL REFERENCES device_type (device_type_id),
58
  name            varchar(255) not NULL COMMENT 'the visible displayed name',
59
  notes           text COMMENT 'Just a place to record some notes',
60
  part_of         int(10) unsigned default NULL  COMMENT 'If this device is a part of a larger device this points to the larger device' REFERENCES device(device_id),
61
  added_date      datetime not null COMMENT 'date record was added',
62
  removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
63
  PRIMARY KEY     (device_id)
64
)   COMMENT='information on an individual device computer router print';
65
 
66
DROP TABLE IF EXISTS device_attrib;
67
CREATE TABLE device_attrib (
68
  device_attrib_id int unsigned not null auto_increment,
69
  device_id       int(10) unsigned NOT NULL REFERENCES device(device_id),
70
  attrib_id       int(10) unsigned NOT NULL REFERENCES attrib(attrib_id),
71
  value           text COMMENT 'The actual value of this attribute.',
72
  added_date      datetime NOT NULL COMMENT 'date record was added',
73
  removed_date    datetime default NULL,
74
  PRIMARY KEY     (device_attrib_id)
75
)  COMMENT='links devices and their attributes together';
76
 
77
 
78
DROP TABLE IF EXISTS device_type;
79
CREATE TABLE device_type (
80
  device_type_id  int(10) unsigned NOT NULL auto_increment,
81
  name            varchar(64) not null COMMENT 'the visible displayed name',
82
  show_as_system  char(1) default 'Y',
83
  added_date      datetime not null COMMENT 'date record was added',
84
  removed_date    datetime default NULL COMMENT 'date record was deleted/supserceded',
85
  PRIMARY KEY     (device_type_id)
86
)   COMMENT='simply a list of device types ie computer printer whatever';
87
 
88
DROP TABLE IF EXISTS login;
89
CREATE TABLE login (
90
  login_id        int(10) unsigned NOT NULL auto_increment,
91
  email           varchar(64) not null COMMENT 'email address used as login id',
92
  pass            char(32) default NULL COMMENT 'the encrypted password of the user',
93
  where_clause    text COMMENT 'clause that limits what a user can see',
94
  added_date      datetime not null COMMENT 'date record was added',
95
  removed_date    datetime default NULL COMMENT 'date record was closed',
96
  PRIMARY KEY     (login_id)
97
)   COMMENT='table for logging into the the maintenance system';
98
 
99
DROP TABLE IF EXISTS menu;
100
CREATE TABLE menu (
101
   menu_id        int unsigned not null auto_increment,
102
   parent_id      int unsigned null  comment 'If this is a submenu the id of the parent' REFERENCES menu(menu_id),
103
   caption        varchar(20) not null comment 'The actual caption displayed',
104
   url            varchar(120) null comment 'the url of the page/script to call or null if this contains sub-options',
105
   primary key    (menu_id)
106
) comment 'We keep the entire menu structure here so modules can modify it';
107
 
108
drop table if exists report;
109
create table report (
110
   report_id      int unsigned not null auto_increment,
111
   name           varchar(64) not null comment 'Display Name of Report',
112
   query          text not null comment 'Query to be executed',
113
   parameters     text comment 'All parameters used in above',
114
   screen_report  int unsigned default null comment 'Each screen can be assigned a bit and this will show up on a screen',
115
   primary key    (report_id)
116
) comment 'holds definition for report';
117
 
118
/* create some keys */
119
alter table attrib add index (name);
120
alter table attrib add index (added_date,removed_date);
121
 
122
alter table device add index (added_date,removed_date);
123
alter table device add index (part_of);
124
alter table device add index (removed_date);
125
alter table device add index (site_id);
126
alter table device add index (name);
127
alter table device add index (device_type_id);
128
 
129
alter table device_attrib add index (device_id);
130
alter table device_attrib add index (added_date,removed_date);
131
 
132
alter table site add index (client_id);
133
alter table site add index (removed_date);
134
 
135
alter table client add index (removed_date);
136
 
137
alter table login add index (email);
138
alter table login add index (removed_date);
139
 
140
 
141
 
142
/* a couple of baby reports */
143
insert into report( name, query, parameters ) values ('Current Clients','select name Client, notes Notes, internal_notes "Internal Notes", date(added_date) Added from current_client', null );
144
insert into report( name, query, parameters ) values ('Current Sites', 'select client.name Client, site.name Site, site.added_date "Site Added" from current_client client join current_site site using (client_id) order by client.name,site.name', null );
145
insert into report( name, query, parameters ) values ('Client Devices','select client.name,site.name,device.name
146
from current_client client join current_site site using (client_id) 
147
join current_device device using (site_id)
148
where client.client_id = <client_id>','client_id++Client++select client_id,name from current_client order by name++select name from current_client where client_id = <value>');
149
 
150
insert into report( name, query, parameters, screen_report ) values ('Device Attributes','select attrib.name "Attribute",device_attrib.value "Value" 
151
         from device_attrib join attrib using (attrib_id) 
152
         where device_id = <device_id> and device_attrib.removed_date is null',
153
         'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>', 1);
154
 
155
 
156
/* base menu */
157
insert into menu( url,caption,parent_id) values ('/index.html','Home Page',null);
158
insert into menu( url,caption,parent_id) values ('/reports.html','Reports',null);
159
insert into menu( url,caption,parent_id) values ('/backup.html', 'Backup', null);
160
 
161
/* insert into menu( url,caption,parent_id) select 'reports.html','Generic Report Writer', menu_id from menu where caption = 'Reports'; */
162
 
163
/* Some convenience views that return only current entries (ie, removed_date is null) */
164
 
165
create or replace view current_client as select * from client where removed_date is null;
166
create or replace view current_site as select * from site where removed_date is null;
167
create or replace view current_device as select * from device where removed_date is null;
168
 
169
/* A couple of additional convenience views */
170
create or replace view current_systems as select * from device where removed_date is null and device.device_type_id in (select device_type_id from device_type where show_as_system = 'Y');
171
create or replace view client_site as select concat( client.name, ' - ', ifnull(site.name,'None' )) name, client.client_id,site.site_id from client left outer join site using (client_id);
172
create or replace view client_systems as select device.device_id,concat(device.name, ' (', client_site.name, ')') 'Device' from device join client_site using (site_id) join device_type using (device_type_id) where device_type.show_as_system = 'Y';
173
 
174
/* just a way of making sure we can log in */
175
insert into login (email, pass, where_clause, added_date ) values ('admin', md5('pass') , 'ADMINISTRATOR', now() );
176
 
177
/* create some defaults for device_type */
178
insert into device_type ( name, show_as_system, added_date ) values ( 'Computer', 'Y', now() );
179
insert into device_type ( name, show_as_system, added_date ) values ( 'Virtual', 'Y', now() );
180
insert into device_type ( name, show_as_system, added_date ) values ( 'Router', 'Y', now() );
181
insert into device_type ( name, show_as_system, added_date ) values ( 'Switch', 'Y', now() );
182
insert into device_type ( name, show_as_system, added_date ) values ( 'Network Printer', 'Y', now() );
183
insert into device_type ( name, show_as_system, added_date ) values ( 'PCI Card', 'N', now() );
184
insert into device_type ( name, show_as_system, added_date ) values ( 'Periphial', 'N', now() );
185
 
186
/* create some defaults for attrib */
187
insert into attrib (name,added_date) values ( 'Manufacturer', now() );
188
insert into attrib (name,added_date) values ( 'Model', now() );
189
insert into attrib (name,added_date) values ( 'Serial Number', now() );
190