Skip to content

Commit

Permalink
enable search for _table_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Sep 10, 2012
1 parent e986099 commit f5868ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ckanext/datastore/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def datastore_upsert(context, data_dict):
:param upsert: update if record with same key already exists,
otherwise insert
:param insert: insert only, faster because checks are omitted
:param update: update only, exception if duplicates occur
:param update: update only, exception if key does not exist
:type method: string
:returns: the newly created data object.
Expand Down Expand Up @@ -173,7 +173,7 @@ def datastore_search(context, data_dict):
if result:
alias_exists = model.Resource.get(result[0].strip('"'))

if not (res_exists or alias_exists):
if not (res_exists or alias_exists or res_id=='_table_metadata'):
raise p.toolkit.ObjectNotFound(p.toolkit._(
'Resource "{}" was not found.'.format(res_id)
))
Expand Down
19 changes: 10 additions & 9 deletions ckanext/datastore/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import pylons
import sqlalchemy
from sqlalchemy.exc import ProgrammingError
import ckan.plugins as p
import ckanext.datastore.logic.action as action
Expand Down Expand Up @@ -129,18 +128,20 @@ def _check_read_permissions(self):

def _create_alias_table(self):
mapping_sql = '''
SELECT distinct
SELECT DISTINCT ON (r.ev_class, dependent.relname)
r.ev_class AS "_id",
dependee.relname AS name,
-- r.ev_class::regclass AS oid,
-- r.ev_class AS oid,
dependent.relname AS alias_of
-- d.refobjid::regclass AS oid,
-- d.refobjid::regclass AS oid
FROM
pg_attribute as a
JOIN pg_depend as d on d.refobjid = a.attrelid AND d.refobjsubid = a.attnum
JOIN pg_rewrite as r ON d.objid = r.oid
JOIN pg_class as dependee ON r.ev_class = dependee.oid
JOIN pg_class as dependent ON d.refobjid = dependent.oid
pg_attribute AS a
JOIN pg_depend aS d on d.refobjid = a.attrelid AND d.refobjsubid = a.attnum
JOIN pg_rewrite AS r ON d.objid = r.oid
JOIN pg_class AS dependee ON r.ev_class = dependee.oid
JOIN pg_class AS dependent ON d.refobjid = dependent.oid
WHERE dependee.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname='public')
ORDER BY r.ev_class ASC
'''
create_alias_table_sql = u'create or replace view "_table_metadata" as {}'.format(mapping_sql)
connection = db._get_engine(None,
Expand Down

0 comments on commit f5868ac

Please sign in to comment.