Skip to content

Commit d45b9b1

Browse files
committed
adds priority column
1 parent 94b6e5f commit d45b9b1

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,42 @@
22

33
from .base import metadata
44

5-
#
6-
# tags: a way to mark any entity (e.g. a project, ...)
7-
# this can be used to perform operations as filter, select, compare, etc
8-
#
95
tags = sa.Table(
6+
#
7+
# A way to mark any entity (e.g. a project, ...)
8+
# this can be used to perform operations as filter, select, compare, etc
9+
#
1010
"tags",
1111
metadata,
1212
sa.Column(
1313
"id",
1414
sa.BigInteger(),
1515
nullable=False,
1616
primary_key=True,
17+
doc="Unique identifier for each tag.",
1718
),
18-
sa.Column(
19-
"name",
20-
sa.String(),
21-
nullable=False,
22-
doc="display name",
23-
),
19+
sa.Column("name", sa.String(), nullable=False, doc="The display name of the tag."),
2420
sa.Column(
2521
"description",
2622
sa.String(),
2723
nullable=True,
28-
doc="description displayed",
24+
doc="A brief description displayed for the tag.",
2925
),
3026
sa.Column(
3127
"color",
3228
sa.String(),
3329
nullable=False,
34-
doc="Hex color (see https://www.color-hex.com/)",
30+
doc="Hexadecimal color code representing the tag (e.g., #FF5733).",
31+
),
32+
sa.Column(
33+
"priority",
34+
sa.Integer(),
35+
nullable=True,
36+
doc=(
37+
"Explicit ordering priority when displaying tags. "
38+
"Tags with a lower value are displayed first. "
39+
"If NULL, tags are considered to have the lowest priority and "
40+
"are displayed after non-NULL values, ordered by their ID (reflecting creation order)."
41+
),
3542
),
3643
)

packages/postgres-database/src/simcore_postgres_database/utils_tags.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ async def create(
8888
read: bool = True,
8989
write: bool = True,
9090
delete: bool = True,
91+
priority: int | None = None,
9192
) -> TagDict:
9293
"""Creates tag and defaults to full access rights to `user_id`"""
93-
values = {
94+
values: dict[str, str | int] = {
9495
"name": name,
9596
"color": color,
9697
}
9798
if description:
9899
values["description"] = description
100+
if priority is not None:
101+
values["priority"] = priority
99102

100103
async with transaction_context(self.engine, connection) as conn:
101104
# insert new tag
@@ -184,7 +187,7 @@ async def update(
184187
updates = {
185188
name: value
186189
for name, value in fields.items()
187-
if name in {"name", "color", "description"}
190+
if name in {"name", "color", "description", "priority"}
188191
}
189192

190193
if not updates:

packages/postgres-database/src/simcore_postgres_database/utils_tags_sql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def list_tags_stmt(*, user_id: int):
8989
)
9090
)
9191
.group_by(tags.c.id) # makes it tag.id uniqueness
92+
.order_by(tags.c.priority.nulls_last())
9293
.order_by(tags.c.id)
9394
)
9495

0 commit comments

Comments
 (0)