-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create materialized view using alembic-utils (is this actually helpful?)
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
alembic/versions/0d3732aa62be_add_scoreset_search_materialized_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters