-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profil_precision): add filter profil_precisions in api
- Loading branch information
Showing
13 changed files
with
245 additions
and
13 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
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
68 changes: 68 additions & 0 deletions
68
api/src/alembic/versions/20241028_172223_c947102bb23f_add_profils_autres_field_in_service.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,68 @@ | ||
"""add profils_precisions field in service | ||
Revision ID: c947102bb23f | ||
Revises: 68fe052dc63c | ||
Create Date: 2024-10-28 17:22:23.374004 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects.postgresql import TSVECTOR | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "c947102bb23f" | ||
down_revision = "68fe052dc63c" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"api__services", | ||
sa.Column( | ||
"profils_precisions", | ||
sa.String(), | ||
nullable=True, | ||
), | ||
) | ||
# can't use ARRAY_TO_STRING mutable function in a generation expression. | ||
# So it must be overiden by an immutable function | ||
op.execute(""" | ||
CREATE OR REPLACE FUNCTION generate_profils_precisions( | ||
profils_precisions TEXT, | ||
profils TEXT[] | ||
) | ||
RETURNS TSVECTOR AS $$ | ||
BEGIN | ||
RETURN to_tsvector( | ||
'french', | ||
COALESCE(profils_precisions, '') || | ||
' '|| | ||
COALESCE(ARRAY_TO_STRING(profils, ' '), '') | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql IMMUTABLE; | ||
""") | ||
op.add_column( | ||
"api__services", | ||
sa.Column( | ||
"searchable_index_profils_precisions", | ||
TSVECTOR(), | ||
sa.Computed( | ||
"generate_profils_precisions(profils_precisions, profils)", | ||
persisted=True, | ||
), | ||
), | ||
) | ||
op.create_index( | ||
"ix_api__services_searchable_index_profils_precisions", | ||
"api__services", | ||
["searchable_index_profils_precisions"], | ||
postgresql_using="gin", | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("api__services", "searchable_index_profils_precisions") | ||
op.drop_column("api__services", "profils_precisions") |
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
Oops, something went wrong.