Commit ff465bc0 authored by Rafael De Lima Prado's avatar Rafael De Lima Prado
Browse files

database: Add timestamp column


Signed-off-by: Rafael De Lima Prado's avatarRafael de Lima Prado <rlp09@inf.ufpr.br>
parent 0f3f72ef
......@@ -15,7 +15,8 @@ CREATE TABLE proinfo_inventory (
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT DEFAULT 0 NOT NULL
extra_hds SMALLINT DEFAULT 0 NOT NULL,
ts TIMESTAMP
);
CREATE TABLE proinfo_net_usage (
......@@ -48,7 +49,8 @@ CREATE TABLE rejected_inventory (
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT
extra_hds SMALLINT,
ts TIMESTAMP
);
CREATE TABLE rejected_net_usage (
......
......@@ -16,7 +16,7 @@ CREATE TABLE dim_school (
inep CHARACTER VARYING(12) NOT NULL,
name CHARACTER VARYING(150) NOT NULL,
address CHARACTER VARYING(100),
cep CHARACTER VARYING(10)
cep CHARACTER VARYING(10),
CHECK (inep <> ''),
CHECK (name <> '')
);
......
......@@ -6,6 +6,7 @@ CREATE TABLE fact_contact (
dat_id DATE NOT NULL REFERENCES dim_date,
macaddr MACADDR NOT NULL,
project project_enum DEFAULT 'proinfo' NOT NULL,
ts TIMESTAMP,
UNIQUE (sch_id, cit_id, dat_id, macaddr)
);
......
......@@ -49,6 +49,7 @@ BEGIN
i.disk2_size,
i.disk2_used,
i.extra_hds,
i.ts,
'0'::boolean as valid
FROM
proinfo_inventory i
......@@ -189,11 +190,11 @@ BEGIN
INSERT INTO rejected_inventory
(sch_id, cit_id, contact_date, project, inep, macaddr,
os_type, os_distro, os_kernel, processor, memory, disk1_model,
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used)
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used, ts)
(SELECT
sch_id, cit_id, contact_date, project, inep, macaddr,
os_type, os_distro, os_kernel, processor, memory, disk1_model,
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used, ts
FROM
sa_inventory
WHERE
......
......@@ -15,10 +15,10 @@ BEGIN
INTO result from sa_inventory;
--
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project)
(SELECT sch_id, cit_id, contact_date, macaddr::macaddr, to_project_enum(project) FROM sa_inventory WHERE valid = '1')
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project, ts)
(SELECT sch_id, cit_id, contact_date, macaddr::macaddr, to_project_enum(project), ts FROM sa_inventory WHERE valid = '1')
EXCEPT
(SELECT sch_id, cit_id, dat_id, macaddr, project FROM fact_contact WHERE dat_id >= result.min_date AND dat_id <= result.max_date);
(SELECT sch_id, cit_id, dat_id, macaddr, project, ts FROM fact_contact WHERE dat_id >= result.min_date AND dat_id <= result.max_date);
-- how many rows were inserted?
GET DIAGNOSTICS total_rows = ROW_COUNT;
......
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