Skip to content

Commit 71a807d

Browse files
modify index
1 parent 3e0848d commit 71a807d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""add indexes
22
3-
Revision ID: aa2c85e8a66a
3+
Revision ID: cf8f743fd0b7
44
Revises: 48604dfdc5f4
5-
Create Date: 2025-04-03 15:45:02.586547+00:00
5+
Create Date: 2025-04-04 09:46:38.853675+00:00
66
77
"""
88

9+
import sqlalchemy as sa
910
from alembic import op
1011

1112
# revision identifiers, used by Alembic.
12-
revision = "aa2c85e8a66a"
13+
revision = "cf8f743fd0b7"
1314
down_revision = "48604dfdc5f4"
1415
branch_labels = None
1516
depends_on = None
@@ -28,7 +29,13 @@ def upgrade():
2829
postgresql_using="btree",
2930
postgresql_ops={"last_change_date": "DESC"},
3031
)
31-
op.create_index("idx_projects_type", "projects", ["type"], unique=False)
32+
op.create_index(
33+
"ix_projects_partial_type",
34+
"projects",
35+
["type"],
36+
unique=False,
37+
postgresql_where=sa.text("type = 'TEMPLATE'"),
38+
)
3239
op.create_index(
3340
"idx_project_to_folders_project_uuid",
3441
"projects_to_folders",
@@ -68,7 +75,11 @@ def downgrade():
6875
op.drop_index(
6976
"idx_project_to_folders_project_uuid", table_name="projects_to_folders"
7077
)
71-
op.drop_index("idx_projects_type", table_name="projects")
78+
op.drop_index(
79+
"ix_projects_partial_type",
80+
table_name="projects",
81+
postgresql_where=sa.text("type = 'TEMPLATE'"),
82+
)
7283
op.drop_index(
7384
"idx_projects_last_change_date_desc",
7485
table_name="projects",

packages/postgres-database/src/simcore_postgres_database/models/projects.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class ProjectType(enum.Enum):
171171
doc="DEPRECATED: Read/write/delete access rights of each group (gid) on this project",
172172
),
173173
### INDEXES ----------------------------
174-
sa.Index("idx_projects_type", "type"),
175174
sa.Index(
176175
"idx_projects_last_change_date_desc",
177176
"last_change_date",
@@ -180,6 +179,13 @@ class ProjectType(enum.Enum):
180179
),
181180
)
182181

182+
# We define the partial index
183+
sa.Index(
184+
"ix_projects_partial_type",
185+
projects.c.type,
186+
postgresql_where=(projects.c.type == ProjectType.TEMPLATE),
187+
)
188+
183189

184190
# ------------------------ TRIGGERS
185191
new_project_trigger = sa.DDL(

0 commit comments

Comments
 (0)