Coverage for opt/mealie/lib/python3.12/site-packages/mealie/alembic/versions/2023-04-13-06.47.04_b3dbb554ba53_postgres_fuzzy_search.py: 45%
27 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 15:32 +0000
1"""postgres fuzzy search
3Revision ID: b3dbb554ba53
4Revises: 38514b39a824
5Create Date: 2023-04-13 06:47:04.617131
7"""
9from alembic import op 1a
11# revision identifiers, used by Alembic.
12revision = "b3dbb554ba53" 1a
13down_revision = "38514b39a824" 1a
14branch_labels: str | tuple[str, ...] | None = None 1a
15depends_on: str | tuple[str, ...] | None = None 1a
18def get_db_type(): 1a
19 return op.get_context().dialect.name 1a
22def setup_postgres_trigrams(): 1a
23 op.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm;")
24 op.create_index(
25 "ix_recipes_name_normalized_gin",
26 table_name="recipes",
27 columns=["name_normalized"],
28 unique=False,
29 postgresql_using="gin",
30 postgresql_ops={
31 "name_normalized": "gin_trgm_ops",
32 },
33 )
34 op.create_index(
35 "ix_recipes_description_normalized_gin",
36 table_name="recipes",
37 columns=["description_normalized"],
38 unique=False,
39 postgresql_using="gin",
40 postgresql_ops={
41 "description_normalized": "gin_trgm_ops",
42 },
43 )
44 op.create_index(
45 "ix_recipes_ingredients_note_normalized_gin",
46 table_name="recipes_ingredients",
47 columns=["note_normalized"],
48 unique=False,
49 postgresql_using="gin",
50 postgresql_ops={
51 "note_normalized": "gin_trgm_ops",
52 },
53 )
54 op.create_index(
55 "ix_recipes_ingredients_original_text_normalized_gin",
56 table_name="recipes_ingredients",
57 columns=["original_text_normalized"],
58 unique=False,
59 postgresql_using="gin",
60 postgresql_ops={
61 "original_text_normalized": "gin_trgm_ops",
62 },
63 )
66def remove_postgres_trigrams(): 1a
67 op.execute("DROP EXTENSION IF EXISTS pg_trgm;")
68 op.drop_index("ix_recipes_name_normalized_gin", table_name="recipe")
69 op.drop_index("ix_recipes_description_normalized_gin", table_name="recipe")
70 op.drop_index("ix_recipes_ingredients_note_normalized_gin", table_name="recipes_ingredients")
71 op.drop_index("ix_recipes_ingredients_original_text_normalized_gin", table_name="recipes_ingredients")
74def upgrade(): 1a
75 if get_db_type() == "postgresql": 75 ↛ 76line 75 didn't jump to line 76 because the condition on line 75 was never true1a
76 setup_postgres_trigrams()
77 else:
78 pass 1a
81def downgrade(): 1a
82 if get_db_type() == "postgres":
83 remove_postgres_trigrams()
84 else:
85 pass