Skip to content

Commit

Permalink
create materialized view using alembic-utils (is this actually helpful?)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Oct 15, 2024
1 parent 9f8ac82 commit ea2b605
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""add scoreset_search materialized view
Revision ID: 0d3732aa62be
Revises: ec5d2787bec9
Create Date: 2024-10-15 14:59:16.297975
"""
from alembic import op
import sqlalchemy as sa

from alembic_utils.pg_materialized_view import PGMaterializedView

scoreset_search_query = """
select S.id, to_tsvector(S.title || ' ' || S.short_description || ' ' || S.abstract_text || ' ' || string_agg(G.name, ' ')) as text
from scoresets S join target_genes G on G.scoreset_id = S.id
group by S.id
"""

# revision identifiers, used by Alembic.
revision = '0d3732aa62be'
down_revision = '1d4933b4b6f7'
branch_labels = None
depends_on = None

scoreset_search = PGMaterializedView(
schema="public",
signature="scoreset_search",
definition=scoreset_search_query,
with_data=True
)


def upgrade():
op.create_entity(scoreset_search)
op.execute("create index scoreset_search_idx on scoreset_search using gin (text)")


def downgrade():
op.execute("drop index scoreset_search_idx")
op.drop_entity(scoreset_search)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ starlette-context = "^0.3.6"

# Optional dependencies for running this application as a server
alembic = { version = "~1.7.6", optional = true }
alembic-utils = { version = "~0.8.1", optional = true }
arq = { version = "~0.25.0", optional = true }
authlib = { version = "~0.15.5", optional = true }
boto3 = { version = "~1.34.97", optional = true }
Expand Down Expand Up @@ -84,7 +85,7 @@ SQLAlchemy = { extras = ["mypy"], version = "~2.0.0" }


[tool.poetry.extras]
server = ["alembic", "arq", "authlib", "boto3", "cryptography", "fastapi", "email-validator", "orcid", "psycopg2", "python-jose", "python-multipart", "requests", "slack-sdk", "uvicorn", "watchtower"]
server = ["alembic", "alembic-utils", "arq", "authlib", "boto3", "cryptography", "fastapi", "email-validator", "orcid", "psycopg2", "python-jose", "python-multipart", "requests", "slack-sdk", "uvicorn", "watchtower"]


[tool.black]
Expand Down

0 comments on commit ea2b605

Please sign in to comment.