| 1 | rodolico | 1 |    /* sql table creator for computer_asset_mananagement_program */
 | 
        
           |  |  | 2 |    /* Author: R. W. Rodolico, http://www.dailydata.net */
 | 
        
           |  |  | 3 |    /* Software License: GPL */
 | 
        
           |  |  | 4 |    /* version 0.10 */
 | 
        
           |  |  | 5 |    /*         20071103 - Modified to break software packages and names into lookup tables */
 | 
        
           |  |  | 6 |    /* version 0.20 */
 | 
        
           |  |  | 7 |    /* Major modification to handle a lot more information such as additional device types, additional attributes */
 | 
        
           |  |  | 8 |    /* and network interconnects */
 | 
        
           |  |  | 9 |    /* version 2.0 */
 | 
        
           |  |  | 10 |    /* previously, this was an "all in one" structure. Now, reduced to minimal with each module creating its own */
 | 
        
           |  |  | 11 |    /* modifications. This is the very basic set of tables needed */
 | 
        
           |  |  | 12 |   | 
        
           |  |  | 13 |   | 
        
           |  |  | 14 |    drop table if exists _system;
 | 
        
           |  |  | 15 |    create table _system (
 | 
        
           |  |  | 16 |       group_name              varchar(64) not null comment 'used to group keys together',
 | 
        
           |  |  | 17 |       key_name                varchar(64) not null comment 'key into this value',
 | 
        
           |  |  | 18 |       theValue                text comment 'the actual value of this entry',
 | 
        
           |  |  | 19 |       primary key             (group_name,key_name)
 | 
        
           |  |  | 20 |    ) comment 'Basically a configuration file, equivilent to a windows INI file';
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 |    drop table if exists client;
 | 
        
           |  |  | 23 |    create table client (
 | 
        
           |  |  | 24 |       client_id               int unsigned not null auto_increment,
 | 
        
           |  |  | 25 |       name                    varchar(64) comment 'the visible, displayed name',
 | 
        
           |  |  | 26 |       notes                   text comment 'world visible notes on the client',
 | 
        
           |  |  | 27 |       internal_notes          text comment 'These are internal notes, visible only to us',
 | 
        
           |  |  | 28 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 29 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 30 |       primary key             (client_id)
 | 
        
           |  |  | 31 |    ) comment 'information on a particular client';
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 |    drop table if exists site;
 | 
        
           |  |  | 34 |    create table site (
 | 
        
           |  |  | 35 |       site_id                 int unsigned not null auto_increment,
 | 
        
           |  |  | 36 |       client_id               int unsigned not null comment 'a link to the client table',
 | 
        
           |  |  | 37 |       name                    varchar(64) comment 'the visible, displayed name',
 | 
        
           |  |  | 38 |       notes                   text comment 'Just a place to record some notes',
 | 
        
           |  |  | 39 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 40 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 41 |       primary key             (site_id)
 | 
        
           |  |  | 42 |    ) comment 'information on a site, which is tied to a client';
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 |    drop table if exists device;
 | 
        
           |  |  | 45 |    create table device (
 | 
        
           |  |  | 46 |       device_id               int unsigned not null auto_increment,
 | 
        
           |  |  | 47 |       site_id                 int unsigned not null comment 'a link to the site table',
 | 
        
           |  |  | 48 |       device_type_id          int unsigned not null comment 'a link to the device_type table',
 | 
        
           |  |  | 49 |       name                    varchar(255) comment 'the visible, displayed name',
 | 
        
           |  |  | 50 |       notes                   text comment 'Just a place to record some notes',
 | 
        
           |  |  | 51 |       part_of                 int unsigned null comment 'If this device is a part of a larger device, this points to the larger device',
 | 
        
           |  |  | 52 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 53 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 54 |       primary key             (device_id)
 | 
        
           |  |  | 55 |    )  comment 'information on an indivicual device (computer, router, printer, etc)';
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 |    drop table if exists attrib;
 | 
        
           |  |  | 58 |    create table attrib (
 | 
        
           |  |  | 59 |       attrib_id               int unsigned not null auto_increment,
 | 
        
           |  |  | 60 |       name                    varchar(64) comment 'the visible, displayed name',
 | 
        
           |  |  | 61 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 62 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 63 |       primary key             (attrib_id)
 | 
        
           |  |  | 64 |    )  comment 'These are attributes that can be applied to a device';
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 |    drop table if exists device_attrib;
 | 
        
           |  |  | 67 |    create table device_attrib (
 | 
        
           |  |  | 68 |       device_id               int unsigned not null comment 'a link to the device table',
 | 
        
           |  |  | 69 |       attrib_id               int unsigned not null comment 'a link to the attrib table',
 | 
        
           |  |  | 70 |       value                   text comment 'The actual value of this attribute.',
 | 
        
           |  |  | 71 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 72 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 73 |       primary key             (device_id,attrib_id,removed_date)
 | 
        
           |  |  | 74 |    ) comment'links devices and their attributes together';
 | 
        
           |  |  | 75 |   | 
        
           |  |  | 76 |    drop table if exists device_type;
 | 
        
           |  |  | 77 |    create table device_type (
 | 
        
           |  |  | 78 |       device_type_id          int unsigned not null auto_increment,
 | 
        
           |  |  | 79 |       name                    varchar(64) comment 'the visible, displayed name',
 | 
        
           |  |  | 80 |       added_date              date comment 'date record was added',
 | 
        
           |  |  | 81 |       removed_date            date comment 'date record was deleted/supserceded',
 | 
        
           |  |  | 82 |       primary key             (device_type_id)
 | 
        
           |  |  | 83 |    ) comment 'simply a list of device types, ie computer, printer, whatever';
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 |    drop table if exists login;
 | 
        
           |  |  | 86 |    create table login (
 | 
        
           |  |  | 87 |       login_id                int unsigned not null auto_increment,
 | 
        
           |  |  | 88 |       email                   varchar(64) comment 'email address, used as login id',
 | 
        
           |  |  | 89 |       pass                    char(32) comment 'the encrypted password of the user',
 | 
        
           |  |  | 90 |       primary key             (login_id)
 | 
        
           |  |  | 91 |    ) comment 'table for logging into the the maintenance system';
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |    drop table if exists permissions;
 | 
        
           |  |  | 94 |    create table permissions (
 | 
        
           |  |  | 95 |       permissions_id         int unsigned not null auto_increment,
 | 
        
           |  |  | 96 |       description             varchar(64) comment 'Description of this permission',
 | 
        
           |  |  | 97 |       php_function            text comment 'Holds PHP code that, when evaluated, determines whether user has access to a record',
 | 
        
           |  |  | 98 |       primary key             (permissions_id)
 | 
        
           |  |  | 99 |    ) comment 'Holds the definition of permissions available on the system';
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 |    drop table if exists login_permissions;
 | 
        
           |  |  | 102 |    create table login_permissions (
 | 
        
           |  |  | 103 |       login_permissions_id    int unsigned not null auto_increment,
 | 
        
           |  |  | 104 |       login_id                int unsigned not null comment 'the login this record is associated with',
 | 
        
           |  |  | 105 |       permissions_id          int unsigned not null comment 'the permission this record is associated with',
 | 
        
           |  |  | 106 |       parameter_list          text comment 'Any additional parameters needed by this permission to validate',
 | 
        
           |  |  | 107 |       primary key             (login_permissions_id)
 | 
        
           |  |  | 108 |    ) comment 'Hold a list of permissions available to the login id';
 | 
        
           |  |  | 109 |   | 
        
           |  |  | 110 |    /* get some child tables out of the way */
 | 
        
           |  |  | 111 |    insert into attrib(name,added_date) values ('Operating System', now());
 | 
        
           |  |  | 112 |    insert into attrib(name,added_date) values ('Memory', now());
 | 
        
           |  |  | 113 |    insert into attrib(name,added_date) values ('CPU Count', now());
 | 
        
           |  |  | 114 |    insert into attrib(name,added_date) values ('CPU Speed', now());
 | 
        
           |  |  | 115 |    insert into attrib(name,added_date) values ('CPU Type', now());
 | 
        
           |  |  | 116 |    insert into attrib(name,added_date) values ('CPU Subtype', now());
 | 
        
           |  |  | 117 |    insert into attrib(name,added_date) values ('Brand',now());
 | 
        
           |  |  | 118 |    insert into attrib(name,added_date) values ('Model Number',now());
 | 
        
           |  |  | 119 |    insert into attrib(name,added_date) values ('Serial Number',now());
 | 
        
           |  |  | 120 |   | 
        
           |  |  | 121 |    insert into attrib(name,added_date) values ('Printer Cartridge', now());
 | 
        
           |  |  | 122 |   | 
        
           |  |  | 123 |   | 
        
           |  |  | 124 |    insert into device_type (name,added_date) values ('Computer',now());
 | 
        
           |  |  | 125 |    insert into device_type (name,added_date) values ('Router',now());
 | 
        
           |  |  | 126 |    insert into device_type (name,added_date) values ('Switch',now());
 | 
        
           |  |  | 127 |    insert into device_type (name,added_date) values ('Printer',now());
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 |    insert into _system( group_name,key_name,theValue) values ( 'default','ALL','Brand,Model Number,Serial Number');
 | 
        
           |  |  | 130 |    insert into _system( group_name,key_name,theValue) values ( 'default','Computer','Operating System,Memory,CPU Count,CPU Speed,CPU Type,CPU Subtype');
 | 
        
           |  |  | 131 |    insert into _system( group_name,key_name,theValue) values ( 'default','Printer','Printer Cartridge' );
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 |    insert into default_attrib(device_type_id,attrib_id,added_date)
 | 
        
           |  |  | 134 |       select device_type_id,attrib_id,now()
 | 
        
           |  |  | 135 |       from device_type,attrib
 | 
        
           |  |  | 136 |       where attrib.name in ('Brand','Model Number','Serial Number');
 | 
        
           |  |  | 137 |   | 
        
           |  |  | 138 |    insert into default_attrib(device_type_id,attrib_id,added_date)
 | 
        
           |  |  | 139 |       select device_type_id,attrib_id,now()
 | 
        
           |  |  | 140 |       from device_type,attrib
 | 
        
           |  |  | 141 |       where device_type.name = 'Computer' and attrib.name in ('Operating System','Memory','CPU Count','CPU Speed','CPU Type','CPU Subtype');
 | 
        
           |  |  | 142 |   | 
        
           |  |  | 143 |    insert into default_attrib(device_type_id,attrib_id,added_date)
 | 
        
           |  |  | 144 |       select device_type_id,attrib_id,now()
 | 
        
           |  |  | 145 |       from device_type,attrib
 | 
        
           |  |  | 146 |       where device_type.name = 'Printer' and attrib.name in ('Printer Cartridge');
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 |   /* Now, create a client site */
 | 
        
           |  |  | 149 |    insert into client( name,added_date) values ( 'Daily Data', now() );
 | 
        
           |  |  | 150 |    insert into site ( client_id, name,added_date) select client_id,'Main Office',now() from client where name = 'Daily Data';
 | 
        
           |  |  | 151 |    insert into device ( site_id, device_type_id,name,added_date) select site_id,device_type_id, 'PIX 501',now() from site,device_type where site.name = 'Main Office' and device_type.name = 'Router';
 |