1 DROP SCHEMA reporter CASCADE;
3 CREATE SCHEMA reporter;
7 CREATE OR REPLACE VIEW reporter.date_series AS
8 SELECT CAST('1900/01/01' AS DATE) + x AS date,
9 CAST('1900/01/01' AS DATE) + x AS date_label
12 CAST( EXTRACT( 'days' FROM CAST( NOW() - CAST( '1900/01/01' AS DATE ) AS INTERVAL ) ) AS INT )
15 CREATE OR REPLACE VIEW reporter.date_hour_series AS
16 SELECT CAST(date + CAST(h || ' hours' AS INTERVAL) AS TIMESTAMP WITH TIME ZONE) AS date_hour,
17 CAST(date + CAST(h || ' hours' AS INTERVAL) AS TIMESTAMP WITH TIME ZONE) AS date_hour_label
18 FROM reporter.date_series,
19 GENERATE_SERIES(0,23) g(h);
23 CREATE TABLE reporter.date_dim AS
25 EXTRACT('year' FROM date_label)::INT AS year,
26 EXTRACT('month' FROM date_label)::INT AS month,
27 EXTRACT('day' FROM date_label)::INT AS day
29 (SELECT '1900-01-01'::date + g.x AS date_label
30 FROM GENERATE_SERIES(0, EXTRACT('days' FROM NOW() + '10 years'::INTERVAL - '1900-01-01'::TIMESTAMP WITH TIME ZONE)::INT) g(x)) as y
34 CREATE TABLE reporter.time_dim AS
40 GENERATE_SERIES(0, 23) as a(x),
41 GENERATE_SERIES(0, 59) as b(x),
42 GENERATE_SERIES(0, 59) as c(x)
46 CREATE TABLE reporter.stage2 (
47 id serial primary key,
53 create_date timestamp with time zone not null
55 edit_date timestamp with time zone not null
59 CREATE OR REPLACE FUNCTION reporter.force_edit_date_update () RETURNS TRIGGER AS $$
61 NEW.edit_date = NOW();
66 CREATE TRIGGER force_edit_date_update_trig
67 BEFORE UPDATE ON reporter.stage2
69 EXECUTE PROCEDURE reporter.force_edit_date_update ();
71 CREATE TABLE reporter.stage3 (
72 id serial primary key,
74 references reporter.stage2 (id)
84 create_date timestamp with time zone not null
86 runtime timestamp with time zone default now(),
90 CREATE TABLE reporter.output (
91 id serial primary key,
93 references reporter.stage3 (id)
97 queue_time timestamp with time zone not null default now(),
98 run_time timestamp with time zone,
102 error_time timestamp with time zone,
103 complete_time timestamp with time zone,
104 state text check (state in ('wait','running','complete','error'))