-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOP-19784] - add search_vector to Transfer model
- Loading branch information
1 parent
2967c7f
commit 9372298
Showing
7 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
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 @@ | ||
Add full-text search for **transfers** |
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
55 changes: 55 additions & 0 deletions
55
syncmaster/db/migrations/versions/2024-09-30_b9f5c4315bb2_.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,55 @@ | ||
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
"""add search_vector with GIN indexed to Transfer table | ||
Revision ID: b9f5c4315bb2 | ||
Revises: 478240cdad4b | ||
Create Date: 2024-09-30 14:25:37.264273 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b9f5c4315bb2" | ||
down_revision = "478240cdad4b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
sql_expression = ( | ||
"to_tsvector('english'::regconfig, " | ||
"name || ' ' || " | ||
"translate(name, './', ' ') || ' ' || " | ||
"COALESCE(json_extract_path_text(source_params, 'table_name'), '') || ' ' || " | ||
"COALESCE(json_extract_path_text(target_params, 'table_name'), '') || ' ' || " | ||
"COALESCE(json_extract_path_text(source_params, 'directory_path'), '') || ' ' || " | ||
"COALESCE(json_extract_path_text(target_params, 'directory_path'), '') || ' ' || " | ||
"COALESCE(translate(json_extract_path_text(source_params, 'table_name'), './', ' '), '') || ' ' || " | ||
"COALESCE(translate(json_extract_path_text(target_params, 'table_name'), './', ' '), '') || ' ' || " | ||
"COALESCE(translate(json_extract_path_text(source_params, 'directory_path'), './', ' '), '') || ' ' || " | ||
"COALESCE(translate(json_extract_path_text(target_params, 'directory_path'), './', ' '), '')" | ||
")" | ||
) | ||
|
||
op.add_column( | ||
"transfer", | ||
sa.Column( | ||
"search_vector", | ||
postgresql.TSVECTOR(), | ||
sa.Computed(sql_expression, persisted=True), | ||
nullable=False, | ||
), | ||
) | ||
op.create_index("idx_transfer_search_vector", "transfer", ["search_vector"], unique=False, postgresql_using="gin") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index("idx_transfer_search_vector", table_name="transfer", postgresql_using="gin") | ||
op.drop_column("transfer", "search_vector") | ||
# ### end Alembic commands ### |
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
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
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
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