Commit 7e69cdad authored by sim's avatar sim

Add api.documents view

parent d15558f8
"""Add api.documents view
Revision ID: cceddcb46e27
Revises: 4e5952eb6d61
Create Date: 2018-01-24 16:11:57.032715
"""
from alembic import op
import sqlalchemy as sa
from gargantext.util.alembic import ReplaceableObject
# revision identifiers, used by Alembic.
revision = 'cceddcb46e27'
down_revision = '4e5952eb6d61'
branch_labels = None
depends_on = None
api_documents_view = ReplaceableObject(
"api.documents",
"""SELECT n.id, n.typename AS type, n.user_id, n.parent_id, n.name, n.date AS created, n.hyperdata AS data, n.title_abstract, COUNT(nng) AS ngram_count
FROM nodes n
LEFT JOIN nodes_ngrams nng ON (n.id=nng.node_id)
LEFT JOIN nodes lst ON (lst.parent_id=n.parent_id)
LEFT JOIN nodes_ngrams nng2 ON (lst.id=nng2.node_id AND nng2.ngram_id=nng.ngram_id)
WHERE n.typename=4 AND lst.typename=8
GROUP BY n.id""")
def upgrade():
op.create_view(api_documents_view)
op.execute("ALTER VIEW api.documents OWNER TO gargantext")
op.execute("GRANT SELECT ON nodes_ngrams TO gargantext")
def downgrade():
op.execute("REVOKE SELECT ON nodes_ngrams FROM gargantext")
op.drop_view(api_documents_view)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment