Commit 127b035b authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 22

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent b5afed71
/* Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of database
*
* database is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/* -------------------------------------------------------------------------- */
/* Enumerations */
comment on type category_enum is 'Enum type for the components category';
comment on type project_enum is 'Enum type for the MEC project which the
machines belong to';
comment on type os_type_enum is 'Enum type for the OS type, which can be "Linux"
or "Windows"';
comment on type class_enum is 'Enum type for the classification of the machines
according to their availability : green if communication occured at most 10 days
ago, yellow if it ocurred between 10 and 30, and red if it has not occured for
more than 30 days)'
/* -------------------------------------------------------------------------- */
/* Staging Areas */
comment on table sa_inventory is 'Transition table with temporary machines
inventory data';
comment on column sa_inventory.inep is 'Longest INEP has 10 characters';
comment on column sa_inventory.hd_model is 'Longest HD model has 47 characters';
comment on column sa_inventory.processor is 'Longest processor model has 46
chars';
comment on column sa_inventory.os_distro is 'Longest OS distro has 35
characters';
comment on column sa_inventory.kernel is 'Longest kernel version has 24 chars';
comment on table sa_net_usage is 'Transition table with temporary network usage
data per machine';
/* -------------------------------------------------------------------------- */
/* Data Warehouse */
comment on table dim_date is 'Dimension table with dates representing each load
done';
comment on table dim_school is 'Dimension table with data about the schools.
Since this table is loaded apart from the rest of the tables, this is the only
one who does not have nor need the load_date field';
comment on column dim_school.city is 'Longest city name has 32 characters';
comment on column dim_school.school is 'MEC database limit for school names is
100 characters';
comment on column dim_school.address is 'Longest address has 70 characters';
comment on column dim_school.ts_school is 'Full text search field for schools';
comment on table dim_components is 'Dimension table of hardware components';
comment on table dim_components.description is 'HD model, OS type, processor
model and memory size';
comment on table dim_components.detail is 'HD size and OS distro';
comment on table dim_machine is 'Dimension table with machines inventory';
comment on table fact_availability is 'Fact table with the history of machines
connections';
comment on table fact_inventory is 'Fact table with all the machines inventory';
comment on table fact_alert is 'Fact table with the history of machines
modifications';
comment on table fact_net_usage is 'Fact table with the history of network usage
per school and 5 minutes sample';
comment on table fact_net_usage_avail is 'Fact table of the list of schools
with network usage data collected (i.e. at least one machine sent the net usage
data)';
comment on table control is 'Control table with the starting and ending times of
each load process';
/* -------------------------------------------------------------------------- */
/* Data Marts */
comment on table dm_avail_state is 'Data mart table of availability per state';
comment on table dm_avail_city is 'Data mart table of availability per city';
comment on table dm_avail_school is 'Data mart table of availability per
school';
comment on table dm_avail_machine is 'Data mart table with availability per
machine';
comment on table dm_avail_state_history is 'Data mart table with the history of
availability per state and month';
comment on table dm_avail_city_history is 'Data mart table with the history of
availability per city and month';
comment on table dm_invent_machine is 'Data mart table with the machines
inventory';
comment on table dm_audit_zm_school is 'Data mart table with schools without any
machine communicating';
comment on table dm_alert_state is 'Data mart table with alerts per state';
comment on table dm_alert_city is 'Data mart table with alerts per city';
comment on table dm_alert_school is 'Data mart table with alerts per school';
comment on table dm_alert_machine is 'Data mart table with machines alerts';
comment on table dm_alert_state_history is 'Data mart table with the history of
alerts per state and month';
comment on table dm_alert_city_history is 'Data mart table with the history of
alerts per city and month';
comment on table dm_net_usage_monthly is 'Data mart table with network usage per
school with 4 hours sample';
comment on table dm_net_usage_weekly is 'Data mart table with network usage per
school with 1 hour sample';
comment on table dm_net_usage_daily is 'Data mart table with network usage per
school with 5 minutes sample';
This diff is collapsed.
......@@ -19,8 +19,8 @@
* USA.
*/
/* Enum type for the catalog elements */
create type category_type as enum (
/* Enum type for the components category */
create type category_enum as enum (
'os',
'kernel',
'processor',
......@@ -31,130 +31,108 @@ create type category_type as enum (
/* -------------------------------------------------------------------------- */
/* Dimension tables */
/* No id in this table because types date and integer have the same size */
/* Dimension table with dates representing each load done */
create table dim_date (
date date primary key
id serial primary key,
load_date date unique not null
);
comment on table dim_date is 'Dimension table with dates representing each load
done';
/* Dimension table with data about the schools. Since this table is loaded apart
* and "manually" from the rest of the tables, this is the only one who does not
* have nor need the load_date field */
create table dim_school (
id integer primary key,
inep text unique not null,
region text not null,
state text not null,
city text not null, /* Longest city name has 32 characters */
school text not null, /* MEC database limit for school names is 100 */
code text,
address text, /* Longest address has 70 characters */
school_s tsquery not null,
net_data boolean default false not null
id integer primary key,
inep text unique not null,
region text not null,
state text not null,
city text not null, /* Longest city name has 32 characters */
school text not null, /* MEC database limit for school names is
* 100 */
code text,
address text, /* Longest address has 70 characters */
ts_school tsvector not null, /* Full text search field for schools */
);
comment on table dim_school is 'Dimension table with data about the schools';
/* Dimension table of hardware components */
create table dim_components (
id serial primary key,
category category_type not null,
description text, /* HD model, OS type, processor model and memory size */
other integer, /* HD size and OS distro */
hd_used integer default 0 not null
load_date integer references dim_date not null,
category category_enum not null,
description text not null, /* HD model, OS type, processor model
* and memory size */
detail text not null /* HD size and OS distro */
);
comment on table dim_catalog is 'Dimension table of hardware components';
create table dim_hd (
id serial primary key,
hd_model text not null, /* Longest HD model has 47 characters *
hd_size integer not null,
hd_used integer not null,
hd2_model text,
hd2_size integer,
hd2_used integer,
extra_hds integer default 0 not null,
unique(hd_model, hd_size)
);
comment on table dim_hd is 'Dimension table with HD data';*/
/* Dimension table with machines inventory */
create table dim_machine (
id serial primary key,
school_id integer references dim_school not null,
os_id integer references dim_os not null,
kernel_id integer references dim_kernel,
processor_id integer references dim_processor,
memory_id integer references dim_memory,
hd_id integer references dim_hd,
machine macaddr not null,
project mec_project default 'proinfo' not null,
id serial primary key,
load_date integer references dim_date not null,
school_id integer references dim_school not null,
machine macaddr not null,
project project_enum default 'proinfo' not null,
unique(school_id, machine)
);
comment on table dim_machine is 'Dimension table with machines inventory';
/* -------------------------------------------------------------------------- */
/* Fact tables */
/* Nowadays, the availability table also represents the inventory received by
* the web service server
* Fact table with the history of machines connections */
/* Fact table with the history of machines connections */
create table fact_availability (
date_id integer references dim_date,
machine_id integer references dim_machine
load_date integer references dim_date not null,
machine_id integer references dim_machine not null,
contact_date date not null
);
comment on table fact_availability is 'Fact table with the history of machines
connections';
/* This is not even a "factless table", so will be kept in dim_machine
* Actual inventory of a machine (that is, the last inventory XML sent by it and
* added to the database) */
/*create table fact_inventory (
machine_id integer references dim_machine,
os_id integer references dim_os,
kernel_id integer references dim_kernel,
processor_id integer references dim_processor,
hd_id integer references dim_hd,
memory_id integer references dim_memory,
-- Replication of data
os_type text not null,
os_distro text not null,
kernel text not null,
processor text not null,
memory_size integer not null,
hd_model text not null,
hd_size integer not null,
hd_used integer not null,
hd2_model text,
hd2_size integer,
/* Fact table with all the machines inventory */
create table fact_inventory (
load_date date references dim_date not null,
machine_id integer references dim_machine not null,
os_id integer references dim_os not null,
kernel_id integer references dim_kernel not null,
processor_id integer references dim_processor not null,
memory_id integer references dim_memory not null,
hd_id integer references dim_hd not null,
hd_used integer not null,
hd2_used integer,
extra_hds integer default 0 not null
extra_hds integer default 0 not null
);
comment on table fact_inventory is 'Fact table with machines inventory';*/
-- Just for alerts or for any change about the machines?
/* Fact table with the history of machines modifications */
create table fact_alert (
old_date_id integer references dim_date,
date_id integer references dim_date,
old_machine_id integer references dim_machine,
machine_id integer references dim_machine,
memory_alert boolean default false not null,
hd_alert boolean default false not null
load_date integer references dim_date not null,
old_machine_id integer references dim_machine not null,
machine_id integer references dim_machine not null,
old_contact_date date not null,
contact_date date not null,
memory_alert boolean default false not null,
hd_alert boolean default false not null
);
comment on table fact_alert is 'Fact table with the history of machines
modifications';
/* Fact table with the history of network usage per school and 5 minutes
* sample */
create table fact_net_usage (
school_id integer references dim_school,
date_id date references dim_date,
time_id integer references dim_time,
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
load_date integer references dim_date not null,
school_id integer references dim_school not null,
collect_date date not null,
collect_time timestamp not null,
down_bytes bigint not null,
down_packages integer not null,
up_bytes bigint not null,
up_packages integer not null
);
/* Fact table of the list of schools with network usage data collected (i.e. at
* least one machine sent the net usage data) */
create table fact_net_usage_avail (
load_date integer references dim_date not null,
school_id integer references dim_school not null,
net_data_avail boolean default false not null
);
comment on table fact_net_usage is 'Fact table with the history of network usage
per school and 5 minutes sample';
/* -------------------------------------------------------------------------- */
/* Control table */
/* Control table with the starting and ending times of each load process */
create table control (
id serial primary key,
name text not null,
......@@ -162,5 +140,3 @@ create table control (
end_time timestamp not null,
total integer not null
);
comment on table control is 'Control table with the starting and ending times of
each load process';
......@@ -32,36 +32,4 @@ psql -d proinfodata -f create_data_warehouse.sql
psql -d proinfodata -f create_data_marts.sql
psql -d proinfodata -f create_indexes.sql
psql -c "grant insert on sa_inventory to ${user};
grant insert on sa_net_usage to ${user};
grant select on dim_date to ${user};
grant select on dim_time to ${user};
grant select on dim_school to ${user};
grant select on dim_os to ${user};
grant select on dim_kernel to ${user};
grant select on dim_processor to ${user};
grant select on dim_memory to ${user};
grant select on dim_hd to ${user};
grant select on dim_machine to ${user};
grant select on fact_availability to ${user};
grant select on fact_alert to ${user};
grant select on fact_net_usage to ${user};
grant select on dm_avail_state to ${user};
grant select on dm_avail_city to ${user};
grant select on dm_avail_school to ${user};
grant select on dm_avail_machine to ${user};
grant select on dm_avail_state_history to ${user};
grant select on dm_avail_city_history to ${user};
grant select on dm_invent_machine to ${user};
grant select on dm_alert_state to ${user};
grant select on dm_alert_city to ${user};
grant select on dm_alert_school to ${user};
grant select on dm_alert_machine to ${user};
grant select on dm_alert_state_history to ${user};
grant select on dm_alert_city_history to ${user};
grant select on dm_net_usage_state to ${user};
grant select on dm_net_usage_city to ${user};
grant select on dm_net_usage_school to ${user};"
bash grant_permissions.sh ${user}
......@@ -29,4 +29,6 @@ create index on dm_audit_zm_school (state, city);
create index on dm_alert_machine (state, city);
create index on dm_alert_state_history (contact_date desc);
create index on dm_alert_city_history (contact_date desc);
create index on dm_net_usage_school (inep, collect_date);
create index on dm_net_usage_monthly (inep, collect_date);
create index on dm_net_usage_weekly (inep, collect_date);
create index on dm_net_usage_daily (inep, collect_date);
......@@ -20,45 +20,49 @@
*/
/* Enum type for the MEC project which the machines belong to */
create type mec_project as enum (
create type project_enum as enum (
'proinfo',
'uca_classmate',
'uca_server',
'projector'
);
/* Enum type for the OS type, which can be "Linux" or "Windows" */
create type os_type_enum as enum (
'Linux',
'Windows'
);
/* -------------------------------------------------------------------------- */
/* Staging area tables */
/* Transition table with temporary machines inventory data */
create table sa_inventory (
project mec_project default 'proinfo' not null
contact_date date not null,
inep text not null, /* Longest INEP has 10 characters */
machine macaddr not null,
hd_model text not null, /* Longest HD model has 47 characters */
hd_size integer not null,
hd_used integer not null,
contact_date date not null,
project project_enum default 'proinfo' not null,
inep text not null, /* Longest INEP has 10 characters */
machine macaddr not null,
os_type text not null,
os_distro text not null, /* Longest OS distro has 35 characters */
kernel text not null, /* Longest kernel version has 24 chars */
processor text not null, /* Longest proc model has 46 chars */
memory_size integer not null,
hd_model text not null, /* Longest HD model has 47 characters */
hd_size integer not null,
hd_used integer not null,
hd2_model text,
hd2_size integer,
hd2_used integer,
extra_hds integer default 0 not null,
memory_size integer not null,
processor text not null, /* Longest proc model has 46 chars */
os_type text not null, /* 'Linux' or 'Windows' */
os_distro text not null, /* Longest OS distro has 35 characters */
kernel text not null, /* Longest kernel version has 24 chars */
);
comment on table sa_inventory is 'Transition table with temporary machines
inventory data';
/* Transition table with temporary network usage data per machine */
create table sa_net_usage (
inep text not null,
machine macaddr not null,
collect_time timestamp not null,
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
down_packages integer not null,
up_bytes bigint not null,
up_packages integer not null
);
comment on table sa_net_usage is 'Transition table with temporary network usage
data per machine';
#!/bin/bash
# Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of database
#
# database is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
if test $# -ne 1; then
printf "Usage: ./grant_permissions.sh <user>"
exit 1
fi
psql -c "grant insert on sa_inventory to ${user};
grant insert on sa_net_usage to ${user};
grant select on dim_date to ${user};
grant select on dim_time to ${user};
grant select on dim_school to ${user};
grant select on dim_os to ${user};
grant select on dim_kernel to ${user};
grant select on dim_processor to ${user};
grant select on dim_memory to ${user};
grant select on dim_hd to ${user};
grant select on dim_machine to ${user};
grant select on fact_availability to ${user};
grant select on fact_alert to ${user};
grant select on fact_net_usage to ${user};
grant select on dm_avail_state to ${user};
grant select on dm_avail_city to ${user};
grant select on dm_avail_school to ${user};
grant select on dm_avail_machine to ${user};
grant select on dm_avail_state_history to ${user};
grant select on dm_avail_city_history to ${user};
grant select on dm_invent_machine to ${user};
grant select on dm_alert_state to ${user};
grant select on dm_alert_city to ${user};
grant select on dm_alert_school to ${user};
grant select on dm_alert_machine to ${user};
grant select on dm_alert_state_history to ${user};
grant select on dm_alert_city_history to ${user};
grant select on dm_net_usage_monthly to ${user};
grant select on dm_net_usage_weekly to ${user};
grant select on dm_net_usage_daily to ${user};"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment