activate json_field only if postgres version supports JSONB (fixes #15427)
This commit is contained in:
parent
437f4924d2
commit
b5d9c12fe9
|
@ -85,7 +85,6 @@ class WcsOlapFeeder(object):
|
|||
'name': 'all_formdata',
|
||||
'label': u'Tous les formulaires',
|
||||
'fact_table': 'formdata',
|
||||
'json_field': 'json_data',
|
||||
'key': 'id',
|
||||
'joins': [
|
||||
{
|
||||
|
@ -240,6 +239,13 @@ class WcsOlapFeeder(object):
|
|||
self.base_cube = self.model['cubes'][0]
|
||||
self.agents_mapping = {}
|
||||
self.formdata_json_index = []
|
||||
self.has_jsonb = self.detect_jsonb()
|
||||
if self.has_jsonb:
|
||||
cube['json_field'] = 'json_data'
|
||||
|
||||
def detect_jsonb(self):
|
||||
self.cur.execute("SELECT 1 FROM pg_type WHERE typname = 'jsonb'")
|
||||
return bool(self.cur.rowcount)
|
||||
|
||||
def hash_table_name(self, table_name):
|
||||
table_name = table_name.format(**self.default_ctx)
|
||||
|
@ -390,8 +396,9 @@ CREATE TABLE public.dates AS (SELECT
|
|||
['endpoint_delay', 'interval'],
|
||||
['first_agent_id', 'smallint REFERENCES {agent_table} (id)'],
|
||||
['geolocation_base', 'POINT NULL'],
|
||||
['json_data', 'JSONB NULL'],
|
||||
]
|
||||
if self.has_jsonb:
|
||||
self.columns.append(['json_data', 'JSONB NULL'])
|
||||
self.comments = {
|
||||
'formdef_id': u'formulaire',
|
||||
'receipt_time': u'date de réception',
|
||||
|
@ -577,9 +584,10 @@ class WcsFormdefFeeder(object):
|
|||
self.ex('COMMENT ON COLUMN {formdata_table}.%s IS %%s' % at, vars=(comment,))
|
||||
|
||||
# Creat index for JSON fields
|
||||
for field in fields:
|
||||
if field.varname:
|
||||
self.create_formdata_json_index(field.varname)
|
||||
if self.has_jsonb:
|
||||
for field in fields:
|
||||
if field.varname:
|
||||
self.create_formdata_json_index(field.varname)
|
||||
|
||||
# PostgreSQL does not propagate foreign key constraints to child tables
|
||||
# so we must recreate them manually
|
||||
|
@ -683,7 +691,8 @@ class WcsFormdefFeeder(object):
|
|||
json_data[field.varname] = raw
|
||||
|
||||
row['field_%s' % field.varname] = v
|
||||
row['json_data'] = json.dumps(json_data)
|
||||
if self.has_jsonb:
|
||||
row['json_data'] = json.dumps(json_data)
|
||||
# add geolocation fields value
|
||||
for geolocation, label in self.formdef.schema.geolocations:
|
||||
v = (data.geolocations or {}).get(geolocation)
|
||||
|
|
Loading…
Reference in New Issue