create dates table as part of feeding (fixes #14961)

This commit is contained in:
Benjamin Dauvergne 2017-02-21 23:56:50 +01:00
parent 0bf1faed1f
commit af01f30313
3 changed files with 15 additions and 19 deletions

View File

@ -24,13 +24,3 @@ cube.
--key KEY HMAC key for signatures
--pg-dsn PG_DSN Psycopg2 DB DSN
--schema SCHEMA schema name
Dates measure
=============
All date field are joined with a main date table in order to have measure on
date with no facts. You must create this table in the public schema of your
database so that it is shared with all the w.c.s. instance's schemas. For this
use the script create_dates.sql.::
psql -f create_dates.sql wcs-olap

View File

@ -1,9 +0,0 @@
-- Crée une table de dates entre 2010 et 2020
DROP TABLE IF EXISTS dates;
CREATE TABLE dates AS (SELECT
the_date.the_date::date AS date,
to_char(the_date.the_date, 'TMday') AS day,
to_char(the_date.the_date, 'TMmonth') AS month
FROM
generate_series('2010-01-01'::date, '2020-01-01'::date, '1 day'::interval)
AS the_date(the_date));

View File

@ -268,6 +268,20 @@ class WcsOlapFeeder(object):
self.ex('CREATE SCHEMA {schema_temp}')
self.ex('SET search_path = {schema_temp},public')
def do_dates_table(self):
# test if public.dates exists
self.ex("SELECT * FROM information_schema.tables WHERE table_name = 'dates' AND"
" table_schema = 'public'")
if len(list(self.cur.fetchall())) < 1:
self.ex('''
CREATE TABLE public.dates AS (SELECT
the_date.the_date::date AS date,
to_char(the_date.the_date, 'TMday') AS day,
to_char(the_date.the_date, 'TMmonth') AS month
FROM
generate_series('2010-01-01'::date, '2020-01-01'::date, '1 day'::interval)
AS the_date(the_date));''')
channels = [
[1, 'web', u'web'],
[2, 'mail', u'courrier'],
@ -397,6 +411,7 @@ class WcsOlapFeeder(object):
try:
if self.do_feed:
self.do_schema()
self.do_dates_table()
self.do_base_table()
for formdef in self.formdefs:
self.api.cache = {}