Commit 80215fd6 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 16

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 09b90ef1
......@@ -19,16 +19,16 @@
* USA.
*/
-- Enum type for the classification of the machines according to their
-- availability
/* Enum type for the classification of the machines according to their
* availability */
create type classification as enum (
'green', -- Communication ocurred at most 10 days ago
'yellow', -- Communication ocurred between 10 and 30 days
'red' -- Communication doesn't occure for more than 30 days
);
--------------------------------------------------------------------------------
-- Last load availability tables
/* -------------------------------------------------------------------------- */
/* Last load availability tables */
create table dm_avail_state (
project mec_project default 'proinfo' not null,
......@@ -82,8 +82,8 @@ create table dm_avail_machine (
comment on table dm_avail_machine is 'Data mart table with availability per
machine';
--------------------------------------------------------------------------------
-- History availability tables
/* -------------------------------------------------------------------------- */
/* History availability tables */
create table dm_avail_state_history (
project mec_project default 'proinfo' not null,
......@@ -111,8 +111,8 @@ create table dm_avail_city_history (
comment on table dm_avail_city_history is 'Data mart table with the history of
availability per city and month';
--------------------------------------------------------------------------------
-- Last load inventory table
/* -------------------------------------------------------------------------- */
/* Last load inventory table */
create table dm_invent_machine (
project mec_project default 'proinfo' not null,
......@@ -130,10 +130,10 @@ create table dm_invent_machine (
comment on table dm_invent_machine is 'Data mart table with the machines
inventory';
--------------------------------------------------------------------------------
-- Last load audit table
/* -------------------------------------------------------------------------- */
/* Last load audit table */
-- Table of schools with the contact of zero machines
/* Table of schools with the contact of zero machines */
create table dm_audit_zm_school (
project mec_project default 'proinfo' not null,
state varchar(2) not null,
......@@ -144,8 +144,8 @@ create table dm_audit_zm_school (
comment on table dm_audit_zm_school is 'Data mart table with schools without any
machine communicating';
--------------------------------------------------------------------------------
-- Last load alert tables
/* -------------------------------------------------------------------------- */
/* Last load alert tables */
create table dm_alert_state (
project mec_project default 'proinfo' not null,
......@@ -196,8 +196,8 @@ create table dm_alert_machine (
);
comment on table dm_alert_machine is 'Data mart table with machines alerts';
--------------------------------------------------------------------------------
-- History alert tables
/* -------------------------------------------------------------------------- */
/* History alert tables */
create table dm_alert_state_history (
project mec_project default 'proinfo' not null,
......@@ -221,10 +221,10 @@ create table dm_alert_city_history (
comment on table dm_alert_city_history is 'Data mart table with the history of
alerts per city and month';
--------------------------------------------------------------------------------
-- Network usage tables
-- Brazil, regions, states, cities and schools levels?
-- Yearly usage, monthly usage, weekly usage, daily usage?
/* -------------------------------------------------------------------------- */
/* Network usage tables
* Brazil, regions, states, cities and schools levels?
* Yearly usage, monthly usage, weekly usage, daily usage? */
create table dm_net_usage_state (
region varchar(12) not null,
......
......@@ -39,18 +39,20 @@ comment on table dim_date is 'Dimension table of dates';
-- Is this needed? Check fact_net_usage table
create table dim_time (
collect_time timestamp primary key
id serial primary key,
collect_time timestamp unique not null
);
comment on table dim_time is 'Dimension table with collect times during a day';
create table dim_school (
inep varchar(12) primary key,
region varchar(12) not null,
state varchar(2) not null,
city varchar(50), not null, -- Longest city name has 32 characters
school varchar(100) not null, -- MEC web service limit for school names
id integer primary key,
inep varchar(12) unique not null,
region varchar(12) not null,
state varchar(2) not null,
city varchar(50) not null, -- Longest city name has 32 characters
school varchar(100) not null, -- MEC web service limit for school names
code varchar(8),
address varchar(100) -- Longest address has 70 characters
address varchar(100) -- Longest address has 70 characters
);
comment on table dim_school is 'Dimension table with data about the schools';
......@@ -111,7 +113,7 @@ comment on table dim_hd is 'Dimension table with HD data';
create table dim_machine (
id serial primary key,
inep varchar(12) references dim_school,
school_id integer references dim_school,
os_id integer references dim_os,
kernel_id integer references dim_kernel,
processor_id integer references dim_processor,
......@@ -119,7 +121,7 @@ create table dim_machine (
hd_id integer references dim_hd,
machine macaddr not null,
project mec_project default 'proinfo' not null,
unique(inep, machine)
unique(school_id, machine)
);
comment on table dim_machine is 'Dimension table with machines inventory';
......@@ -129,10 +131,10 @@ comment on table dim_machine is 'Dimension table with machines inventory';
-- 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 (
contact_date date references dim_date,
machine_id integer references dim_machine
date_id integer references dim_date,
machine_id integer references dim_machine
);
comment on table fact_availability is 'Fact table with the history of machines
connections';
......@@ -166,37 +168,37 @@ comment on table fact_inventory is 'Fact table with machines inventory';*/
-- Just for alerts or for any change about the machines?
create table fact_alert (
old_date date references dim_date,
contact_date date references dim_date,
old_machine_id integer references dim_machine,
new_machine_id integer references dim_machine,
memory_alert boolean default false not null,
hd_alert boolean default false not null
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
);
comment on table fact_alert is 'Fact table with the history of machines
modifications';
create table fact_net_usage (
id serial primary key,
collect_date date references dim_date,
collect_time timestamp references dim_time,
machine_id integer references dim_machine
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
--id serial primary key,
date_id integer references dim_date,
time_id integer references dim_time,
machine_id integer references dim_machine
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
);
comment on table fact_net_usage is 'Fact table with machines network usage';
/* Is this table needed, or the data mart is enough?
create table fact_net_usage_school (
collect_date date references dim_date,
collect_time timestamp references dim_time,
inep varchar(12) references dim_school,
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
collect_date date references dim_date,
time_id integer references dim_time,
school_id integer references dim_school,
down_packages integer not null,
down_bytes bigint not null,
up_packages integer not null,
up_bytes bigint not null
);
/*comment on table fact_net_usage_school is 'Fact table with the history of
network usage per school';*/
......@@ -33,15 +33,19 @@ begin
-- Insert new hardware and software components into their respective
-- dimension tables
insert into dim_os select distinct os_type, os_distro from sa_inventory;
insert into dim_kernel select distinct kernel from sa_inventory;
insert into dim_processor select distinct processor from sa_inventory;
insert into dim_memory select distinct memory_size from sa_inventory;
insert into dim_hd select distinct hd_model, hd_size, hd_used, hd2_model,
hd2_size, hd2_used, extra_hds from sa_inventory;
insert into dim_os (os_type, os_distro) select distinct os_type, os_distro
from sa_inventory;
insert into dim_kernel (kernel) select distinct kernel from sa_inventory;
insert into dim_processor (processor) select distinct processor
from sa_inventory;
insert into dim_memory (memory_size) select distinct memory_size
from sa_inventory;
insert into dim_hd (hd_model, hd_size, hd_used, hd2_model, hd2_size,
hd2_used, extra_hds) select distinct hd_model, hd_size, hd_used,
hd2_model, hd2_size, hd2_used, extra_hds from sa_inventory;
-- Insert the new machines into dim_machine table
insert into dim_machine /*(
insert into dim_machine (
inep,
os_id,
kernel_id,
......@@ -50,40 +54,48 @@ begin
hd_id,
machine,
project
)*/ select
) select
inep,
(select id from dim_os t where os_type = t.os_type and os_distro =
(select id from dim_os where os_type = t.os_type and os_distro =
t.os_distro) as os_id,
(select id from dim_kernel t where kernel = t.kernel) as kernel_id,
(select id from dim_processor t where processor = t.processor) as processor_id,
(select id from dim_memory t where memory_size = t.memory_size) as memory_id,
(select id from dim_hd t where
(select id from dim_kernel where kernel = t.kernel) as kernel_id,
(select id from dim_processor where processor = t.processor) as
processor_id,
(select id from dim_memory where memory_size = t.memory_size) as
memory_id,
(select id from dim_hd where
hd_model = t.hd_model, hd_size = t.hd_size, hd_used = t.hd_used,
hd2_model = t.hd2_model, hd2_size = t.hd2_size,
hd2_used = t.hd2_used, extra_hds = t.extra_hds) as hd_id,
machine,
project
from
sa_inventory;
sa_inventory t;
-- Update old machines whose components have changed, creating the alerts
/*update dim_machine set ...*/
/*insert into fact_alert select ...*/
-- Update availability table
insert into fact_availability
select contact_date, machine_id
from sa_inventory
-- Walk through every row in the staging area and update the data warehouse
-- tables accordingly
for sa_rows in select * from sa_inventory order by contact_date loop
/*for sa_rows in select * from sa_inventory order by contact_date loop
/*insert into dim_date values (contact_date);
exception when unique_violation then
-- Do nothing - the date already exists
end;*/
end;/
/*update where;
if not found then
insert;
end if;*/
end if;/
end loop;
end loop;*/
return;
end;
......
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