-
Notifications
You must be signed in to change notification settings - Fork 0
/
7366df17e57c_resource_uid_included_in_fts.py
67 lines (58 loc) · 2.02 KB
/
7366df17e57c_resource_uid_included_in_fts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""resource_uid included in FTS.
Revision ID: 7366df17e57c
Revises: 81993949dc59
Create Date: 2024-04-11 14:11:50.174472
"""
import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op
# revision identifiers, used by Alembic.
revision = "7366df17e57c"
down_revision = "81993949dc59"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.drop_column("resources", "search_field")
op.add_column(
"resources",
sa.Column(
"search_field",
sqlalchemy_utils.types.ts_vector.TSVectorType(regconfig="english"),
sa.Computed(
"setweight(to_tsvector('english', resource_uid || ' ' || coalesce(title, '')), 'A') "
" || ' ' || "
"setweight(to_tsvector('english', coalesce(abstract, '')), 'B') || ' ' || "
"setweight(to_tsvector('english', coalesce(fulltext, '')), 'C') || ' ' || "
"setweight(to_tsvector('english', coalesce(high_priority_terms, '')), 'D')",
persisted=True,
),
),
)
op.create_index(
"idx_resources_search_field",
"resources",
["search_field"],
postgresql_using="gin",
)
def downgrade() -> None:
op.drop_column("resources", "search_field")
op.add_column(
"resources",
sa.Column(
"search_field",
sqlalchemy_utils.types.ts_vector.TSVectorType(regconfig="english"),
sa.Computed(
"setweight(to_tsvector('english', coalesce(title, '')), 'A') || ' ' || "
"setweight(to_tsvector('english', coalesce(abstract, '')), 'B') || ' ' || "
"setweight(to_tsvector('english', coalesce(fulltext, '')), 'C') || ' ' || "
"setweight(to_tsvector('english', coalesce(high_priority_terms, '')), 'D')",
persisted=True,
),
),
)
op.create_index(
"idx_resources_search_field",
"resources",
["search_field"],
postgresql_using="gin",
)