Commit 8224b2ef authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 36

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 35e0eb9f
......@@ -22,7 +22,7 @@
/* Create function that migrates the data from the old database model to the new
* one, removing trailing white spaces from both extremes of the text types and
* discarting some specific duplicate and incorrect data (e.g. HDs with null
* model and duplicate os_distro data)
* model and duplicated os_distro data)
*
* NOTE: Network usage data is going to be discarted, as agreed previously by
* the team */
......@@ -34,9 +34,8 @@ declare
load_date_id integer;
/* -------------------------------------------------------------------------- */
begin
raise log 'Migration start point'
start_time := current_time;
raise log 'Migration start point: %', start_time;
/* ---------------------------------------------------------------------- */
/* Migrate staging area */
......@@ -111,35 +110,104 @@ begin
raise log 'Migrating "mectb05_disponibilidade_fact" data to '
'"fact_availability"...';
insert into fact_availability (load_date, contact_date, machine_id)
select load_date_id, dat_data, dis_maq_id from
mectb05_disponibilidade_fact, mectb03_data_dim where dis_dat_id =
dat_id;
select distinct load_date_id, dat_data, dim_machine.id from
mectb05_disponibilidade_fact, mectb03_data_dim, mectb04_maquina_dim,
dim_machine, mectb01_escola_dim, dim_school where dis_dat_id =
dat_id and dis_maq_id = maq_id and maq_esc_id = esc_id and
maq_mac::macaddr = machine and esc_inep = inep and school_id =
dim_school.id;
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';
/* Temporary tables to get machines components' id */
create temporary table
(select substring(maq_inventario from 65 for 64) as hd from mectb04_maquina_dim),
(select case when char_length(maq_inventario) = 224 then
substring(maq_inventario from 129 for 32)
when char_length(maq_inventario) = 288 then
substring(maq_inventario from 129 for 32) end from mectb04_maquina_dim),
(select from mectb04_maquina_dim),
(select from mectb04_maquina_dim),
(select from mectb04_maquina_dim),
/* Temporary table to get machines ids */
create temporary table tmp_machine (
machine_id integer,
old_id integer
);
/* Temporary tables to get machines components id */
create temporary table tmp_os (
component_id integer,
machine_id integer,
date_id integer
);
create temporary table tmp_kernel like tmp_os;
create temporary table tmp_processor like tmp_os;
create temporary table tmp_memory like tmp_os;
create temporary table tmp_hd (
component_id integer,
machine_id integer,
date_id integer,
used integer
);
create temporary table tmp_hd2 like tmp_hd;
/* Insert data into temporary tables */
insert into tmp_machine (machine_id, old_id)
select distinct dim_machine.id, inv_maq_id from
mectb07_inventario_fact, mectb01_escola_dim, mectb04_maquina_dim,
dim_school, dim_machine where inv_maq_id = maq_id and maq_esc_id =
esc_id and maq_mac::macaddr = machine and esc_inep = inep and
school_id = dim_school.id;
insert into tmp_os (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'SO' and inv_cat_id =
cat_id and trim(both from cat_descricao) = detail;
insert into tmp_kernel (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'KERNEL' and inv_cat_id
= cat_id and trim(both from cat_modelo) = description;
insert into tmp_processor (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'PROC' and inv_cat_id =
cat_id and trim(both from cat_modelo) = description;
insert into tmp_memory (component_id, machine_id, date_id)
select distinct cat_modelo::integer, inv_maq_id, inv_dat_id from
mectb07_inventario_fact, mectb02_catalogo_dim, dim_component where cat_componente
= 'MEM' and inv_cat_id = cat_id and cat_modelo is not null;
insert into tmp_hd (component_id, machine_id, date_id, used)
select distinct id, inv_maq_id, inv_dat_id, inv_disco_usado from
mectb07_inventario_fact, mectb02_catalogo_dim, dim_component where cat_componente
= 'HD' and inv_cat_id = cat_id and trim(both from cat_modelo) =
description and trim(both from cat_descricao) = detail;
/*
insert into tmp_processor (component_id, machine_id, date_id)
select distinct id, dat_data, maq_mac::macaddr from
mectb07_inventario_fact, mectb02_catalogo_dim, mectb03_data_dim,
mectb04_maquina_dim, dim_component where cat_componente = 'PROC' and
inv_cat_id = cat_id and inv_dat_id = dat_id and inv_maq_id = maq_id
and trim(both from cat_modelo) = description;
insert into tmp_memory (component_id, machine_id, date_id)
select distinct cat_modelo::integer, dat_data, maq_mac::macaddr from
mectb07_inventario_fact, mectb02_catalogo_dim, mectb03_data_dim,
mectb04_maquina_dim where cat_componente = 'MEM' and inv_cat_id =
cat_id and inv_dat_id = dat_id and inv_maq_id = maq_id and
cat_modelo is not null;
insert into tmp_hd (component_id, machine_id, date_id)
select distinct id, dat_data, maq_mac::macaddr, inv_disco_usado from
mectb07_inventario_fact, mectb02_catalogo_dim, mectb03_data_dim,
mectb04_maquina_dim, dim_component where cat_componente = 'HD' and
inv_cat_id = cat_id and inv_dat_id = dat_id and inv_maq_id = maq_id
and trim(both from cat_modelo) = description and trim(both from
cat_descricao) = detail;
*/
-- Check old load functions to obtain the data from old hash
raise log 'Migrating "mectb07_inventario_fact" data to '
'"fact_inventory"...';
insert into fact_inventory (load_date, contact_date, machine_id, so_id,
insert into fact_inventory (load_date, contact_date, machine_id, os_id,
kernel_id, processor_id, memory, hd_id, hd_used, hd2_id, hd2_used,
extra_hds)
select load_date_id, dat_data, inv_maq_id,
from mectb07_inventario_fact, mectb03_data_dim where inv_dat_id =
dat_id;
--select load_date_id, dat_data, id from mectb07_inventario_fact,
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';
......@@ -147,8 +215,7 @@ begin
raise log 'Migrating "mectb07_inventario_fact" data to "fact_alert"...';
insert into fact_alert (load_date, old_inventory, inventory, memory_alert,
hd_alert)
select
from ;
--select from ;
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';
......@@ -158,7 +225,7 @@ begin
raise log 'Migrating "mectb99_control" data to "control"...';
insert into control (name, start_time, end_time, total)
select ctr_bd, ctr_inicio::timestamp, ctr_fim:timestamp, ctr_total from
select ctr_bd, ctr_inicio::timestamp, ctr_fim::timestamp, ctr_total from
mectb99_control;
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
......@@ -169,6 +236,6 @@ begin
start_time, current_time, count);
raise log 'Done';
raise log 'Migration end point'
raise log 'Migration end point - %', current_time;
end;
$$ language plpgsql;
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