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 client;
|
|
|
22 |
CREATE TABLE client (
|
|
|
23 |
client_id int(10) unsigned NOT NULL auto_increment,
|
|
|
24 |
name varchar(64) not null COMMENT 'the visible displayed name',
|
|
|
25 |
notes text COMMENT 'world visible notes on the client',
|
|
|
26 |
internal_notes text COMMENT 'These are internal notes visible only to us',
|
|
|
27 |
added_date datetime not null COMMENT 'date record was added',
|
|
|
28 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
29 |
PRIMARY KEY (client_id)
|
|
|
30 |
) COMMENT='information on a particular client';
|
|
|
31 |
|
|
|
32 |
DROP TABLE IF EXISTS site;
|
|
|
33 |
CREATE TABLE site (
|
|
|
34 |
site_id int(10) unsigned NOT NULL auto_increment,
|
|
|
35 |
client_id int(10) unsigned NOT NULL REFERENCES client(client_id),
|
|
|
36 |
name varchar(64) not null COMMENT 'the visible displayed name',
|
|
|
37 |
notes text COMMENT 'Just a place to record some notes',
|
|
|
38 |
added_date datetime not null COMMENT 'date record was added',
|
|
|
39 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
40 |
PRIMARY KEY (site_id)
|
|
|
41 |
) COMMENT='information on a site which is tied to a client';
|
|
|
42 |
|
|
|
43 |
DROP TABLE IF EXISTS device;
|
|
|
44 |
CREATE TABLE device (
|
|
|
45 |
device_id int(10) unsigned NOT NULL auto_increment,
|
|
|
46 |
site_id int(10) unsigned NOT NULL REFERENCES site(site_id),
|
|
|
47 |
device_type_id int(10) unsigned NOT NULL REFERENCES device_type (device_type_id),
|
|
|
48 |
name varchar(255) not NULL COMMENT 'the visible displayed name',
|
|
|
49 |
notes text COMMENT 'Just a place to record some notes',
|
|
|
50 |
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),
|
|
|
51 |
added_date datetime not null COMMENT 'date record was added',
|
|
|
52 |
removed_date datetime default NULL COMMENT 'date record was deleted/supserceded',
|
|
|
53 |
PRIMARY KEY (device_id)
|
|
|
54 |
) COMMENT='information on an individual device computer router print';
|
|
|
55 |
|
|
|
56 |
DROP TABLE IF EXISTS device_type;
|
|
|
57 |
CREATE TABLE device_type (
|
|
|
58 |
device_type_id int(10) unsigned NOT NULL auto_increment,
|
|
|
59 |
name varchar(64) not null COMMENT 'the visible displayed name',
|
|
|
60 |
show_as_system char(1) default 'Y',
|
|
|
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_type_id)
|
|
|
64 |
) COMMENT='simply a list of device types ie computer printer whatever';
|
|
|
65 |
|
|
|
66 |
DROP TABLE IF EXISTS login;
|
|
|
67 |
CREATE TABLE login (
|
|
|
68 |
login_id int(10) unsigned NOT NULL auto_increment,
|
|
|
69 |
email varchar(64) not null COMMENT 'email address used as login id',
|
|
|
70 |
pass char(32) default NULL COMMENT 'the encrypted password of the user',
|
|
|
71 |
where_clause text COMMENT 'clause that limits what a user can see',
|
|
|
72 |
added_date datetime not null COMMENT 'date record was added',
|
|
|
73 |
removed_date datetime default NULL COMMENT 'date record was closed',
|
|
|
74 |
PRIMARY KEY (login_id)
|
|
|
75 |
) COMMENT='table for logging into the the maintenance system';
|
|
|
76 |
|
|
|
77 |
DROP TABLE IF EXISTS menu;
|
|
|
78 |
CREATE TABLE menu (
|
|
|
79 |
menu_id int unsigned not null auto_increment,
|
|
|
80 |
parent_id int unsigned null comment 'If this is a submenu the id of the parent' REFERENCES menu(menu_id),
|
|
|
81 |
caption varchar(20) not null comment 'The actual caption displayed',
|
|
|
82 |
url varchar(120) null comment 'the url of the page/script to call or null if this contains sub-options',
|
|
|
83 |
primary key (menu_id)
|
|
|
84 |
) comment 'We keep the entire menu structure here so modules can modify it';
|
|
|
85 |
|
|
|
86 |
drop table if exists report;
|
|
|
87 |
create table report (
|
|
|
88 |
report_id int unsigned not null auto_increment,
|
|
|
89 |
name varchar(64) not null comment 'Display Name of Report',
|
|
|
90 |
query text not null comment 'Query to be executed',
|
|
|
91 |
parameters text comment 'All parameters used in above',
|
|
|
92 |
screen_report int unsigned default null comment 'Each screen can be assigned a bit and this will show up on a screen',
|
|
|
93 |
primary key (report_id)
|
|
|
94 |
) comment 'holds definition for report';
|
|
|
95 |
|
|
|
96 |
/* create some keys */
|
|
|
97 |
|
|
|
98 |
alter table device add index (added_date,removed_date);
|
|
|
99 |
alter table device add index (part_of);
|
|
|
100 |
alter table device add index (removed_date);
|
|
|
101 |
alter table device add index (site_id);
|
|
|
102 |
alter table device add index (name);
|
|
|
103 |
alter table device add index (device_type_id);
|
|
|
104 |
|
|
|
105 |
alter table site add index (client_id);
|
|
|
106 |
alter table site add index (removed_date);
|
|
|
107 |
|
|
|
108 |
alter table client add index (removed_date);
|
|
|
109 |
|
|
|
110 |
alter table login add index (email);
|
|
|
111 |
alter table login add index (removed_date);
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
/* a couple of baby reports */
|
|
|
116 |
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 );
|
|
|
117 |
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 );
|
|
|
118 |
insert into report( name, query, parameters ) values ('Client Devices','select client.name,site.name,device.name
|
|
|
119 |
from current_client client join current_site site using (client_id)
|
|
|
120 |
join current_device device using (site_id)
|
|
|
121 |
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>');
|
|
|
122 |
|
106 |
rodolico |
123 |
insert into report values (
|
|
|
124 |
null,
|
|
|
125 |
'Virtuals on Hypervisor',
|
|
|
126 |
'select device_id id,name Name from device where removed_date is null and device_id in (select device_id from device join device_type using (device_type_id) where part_of = <device_id> and device_type.show_as_system = \'Y\') order by name',
|
|
|
127 |
'device_id++Device++select device_id,name from device where removed_date is null++select name from device where device_id = <value>',
|
|
|
128 |
1
|
|
|
129 |
);
|
1 |
rodolico |
130 |
|
|
|
131 |
|
106 |
rodolico |
132 |
|
1 |
rodolico |
133 |
/* base menu */
|
|
|
134 |
insert into menu( url,caption,parent_id) values ('/index.html','Home Page',null);
|
|
|
135 |
insert into menu( url,caption,parent_id) values ('/reports.html','Reports',null);
|
|
|
136 |
insert into menu( url,caption,parent_id) values ('/backup.html', 'Backup', null);
|
|
|
137 |
|
|
|
138 |
/* insert into menu( url,caption,parent_id) select 'reports.html','Generic Report Writer', menu_id from menu where caption = 'Reports'; */
|
|
|
139 |
|
|
|
140 |
/* Some convenience views that return only current entries (ie, removed_date is null) */
|
|
|
141 |
|
|
|
142 |
create or replace view current_client as select * from client where removed_date is null;
|
|
|
143 |
create or replace view current_site as select * from site where removed_date is null;
|
|
|
144 |
create or replace view current_device as select * from device where removed_date is null;
|
49 |
rodolico |
145 |
create or replace view view_device_systems as select * from device where device_type_id in (select device_type_id from device_type where show_as_system = 'Y');
|
1 |
rodolico |
146 |
|
49 |
rodolico |
147 |
|
1 |
rodolico |
148 |
/* A couple of additional convenience views */
|
|
|
149 |
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');
|
|
|
150 |
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);
|
|
|
151 |
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';
|
|
|
152 |
|
|
|
153 |
/* just a way of making sure we can log in */
|
|
|
154 |
insert into login (email, pass, where_clause, added_date ) values ('admin', md5('pass') , 'ADMINISTRATOR', now() );
|
|
|
155 |
|
|
|
156 |
/* create some defaults for device_type */
|
|
|
157 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Computer', 'Y', now() );
|
|
|
158 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Virtual', 'Y', now() );
|
|
|
159 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Router', 'Y', now() );
|
|
|
160 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Switch', 'Y', now() );
|
|
|
161 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Network Printer', 'Y', now() );
|
|
|
162 |
insert into device_type ( name, show_as_system, added_date ) values ( 'PCI Card', 'N', now() );
|
|
|
163 |
insert into device_type ( name, show_as_system, added_date ) values ( 'Periphial', 'N', now() );
|