Commit e5609a51 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 49

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent f5b4fd46
This diff is collapsed.
......@@ -31,7 +31,11 @@ PREFIX="$(dirname $(readlink -f $0))"
old_database=$1
new_database=$2
date +"Dump-restore process started at %F %T"
pg_dump -Fc -b -t mectb* ${old_database} | pg_restore -d ${new_database}
date +"Dump-restore process completed at %F %T"
date +"Migration process started at %F %T"
psql -d ${new_database} -f ${PREFIX}/migrate_data.sql
psql -d ${new_database} -c 'select migrate_data()'
date +"Migration process completed at %F %T"
......@@ -31,11 +31,11 @@ declare
count_total integer := 5; /* 1 load_date and 4 fake components */
tmp integer;
load_date_id integer;
no_data_os integer;
no_data_kernel integer;
no_data_processor integer;
no_data_hd integer;
no_data_hash text;
unknown_os integer;
unknown_kernel integer;
unknown_processor integer;
unknown_hd integer;
unknown_hash text;
/* -------------------------------------------------------------------------- */
begin
raise log 'Migration start point: %', current_timestamp;
......@@ -79,28 +79,28 @@ begin
count_total := count_total + tmp;
raise log 'Done - % rows inserted', tmp;
/* Forge "no data" components and add them to dim_component, so they can be
/* Forge "unknown" components and add them to dim_component, so they can be
* used to insert missing availability data from
* mectb05_disponibilidade_fact into fact_inventory */
raise log 'Forge a "no data" component for each type and add them to '
'"dim_component"';
raise log 'Forging an "unknown" component for each type and adding them to '
'"dim_component"...';
insert into dim_component (load_date, category, description, detail) values
(load_date_id, 'os'::category_enum, 'no data', 'no data') returning id
into no_data_os;
(load_date_id, 'os'::category_enum, 'unknown', 'unknown') returning id
into unknown_os;
insert into dim_component (load_date, category, description, detail) values
(load_date_id, 'kernel'::category_enum, 'no data', null) returning id
into no_data_kernel;
(load_date_id, 'kernel'::category_enum, 'unknown', null) returning id
into unknown_kernel;
insert into dim_component (load_date, category, description, detail) values
(load_date_id, 'processor'::category_enum, 'no data', null) returning id
into no_data_processor;
(load_date_id, 'processor'::category_enum, 'unknown', null) returning id
into unknown_processor;
insert into dim_component (load_date, category, description, detail) values
(load_date_id, 'hd'::category_enum, 'no data', '0') returning id into
no_data_hd;
(load_date_id, 'hd'::category_enum, 'unknown', '0') returning id into
unknown_hd;
raise log 'Done - 4 rows inserted';
/* Calculate the md5 of the "no data" components combination */
no_data_hash = md5(no_data_os::text || no_data_kernel::text ||
no_data_processor::text || '0' || no_data_hd::text || '0' || '0');
/* Calculate the md5 of the "unknown" components combination */
unknown_hash = md5(unknown_os::text || unknown_kernel::text ||
unknown_processor::text || '0' || unknown_hd::text || '0' || '0');
raise log 'Migrating "mectb02_catalogo_dim" data to "dim_component"...';
insert into dim_component (load_date, category, description, detail)
......@@ -220,8 +220,8 @@ begin
/* Get quantity of extra HDs for each combination of data and machine */
insert into tmp_extra_hds (component_id, date_id, old_id)
select count(*), inv_dat_id, inv_maq_id from (select
distinct inv_dat_id, inv_maq_id, cat_modelo, cat_descricao from
select count(*) - 2, inv_dat_id, inv_maq_id from (select distinct
inv_dat_id, inv_maq_id, cat_modelo, cat_descricao from
mectb07_inventario_fact, mectb02_catalogo_dim where inv_cat_id =
cat_id and cat_componente = 'HD') s group by inv_dat_id, inv_maq_id
having count(*) > 2;
......@@ -257,18 +257,18 @@ begin
raise log 'Done - % rows inserted', tmp;
raise log 'Inserting contact data from "mectb05_disponibilidade_fact" '
'data to "fact_inventory", using "no data" flag for the components...';
'data to "fact_inventory", using "unknown" flag for the components...';
insert into fact_inventory (load_date, contact_date, machine_id, os_id,
kernel_id, processor_id, memory_size, hd_id, hd_used, hd2_id,
hd2_used, extra_hds, hash)
select load_date_id, *, no_data_os, no_data_kernel, no_data_processor,
0, no_data_hd, 0, null, null, 0, no_data_hash from (select dat_data,
select load_date_id, *, unknown_os, unknown_kernel, unknown_processor,
0, unknown_hd, 0, null, null, 0, unknown_hash from (select dat_data,
dim_machine.id from mectb05_disponibilidade_fact,
mectb01_escola_dim, mectb03_data_dim, mectb04_maquina_dim,
dim_school, dim_machine 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 except select
contact_date, machine_id from fact_inventory) s;
esc_inep = inep and school_id = dim_school.id
except select contact_date, machine_id from fact_inventory) s;
get diagnostics tmp = ROW_COUNT;
count_total := count_total + tmp;
raise log 'Done - % rows inserted', tmp;
......@@ -306,10 +306,10 @@ begin
raise log 'Updating "control" table with current migration process...';
insert into control (name, start_time, end_time, total) values ('migration',
current_timestamp, clock_timestamp, count_total);
current_timestamp, clock_timestamp(), count_total);
raise log 'Done - 1 row inserted';
raise log 'Migration end point - % (started at %) - total of % rows',
clock_timestamp, current_timestamp, count_total;
raise log 'Migration end point: % (started at %) - total of % rows',
clock_timestamp(), current_timestamp, count_total;
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