Skip to content

Commit

Permalink
[#907] Always create the type nested with a write connection
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed May 27, 2013
1 parent 82f45de commit 4d95bbc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ckanext/datastore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ def _cache_types(context):
if 'nested' not in _type_names:
native_json = _pg_version_is_at_least(connection, '9.2')

connection.execute('CREATE TYPE "nested" AS (json {0}, extra text)'
.format('json' if native_json else 'text'))
log.info("Create nested type. Native JSON: {0}".format(native_json))

import pylons
data_dict = {'connection_url': pylons.config['ckan.datastore.write_url']}
engine = _get_engine(None, data_dict)
with engine.begin() as connection:
connection.execute('CREATE TYPE "nested" AS (json {0}, extra text)'
.format('json' if native_json else 'text'))
_pg_types.clear()

log.info("Created nested type. Native JSON: {0}".format(native_json))

## redo cache types with json now available.
return _cache_types(context)

Expand Down

0 comments on commit 4d95bbc

Please sign in to comment.