Skip to content

Commit 3c59dc2

Browse files
adding SINGLE/LIST values to new tag_type column
1 parent ae3f3ce commit 3c59dc2

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""tag_type_column
2+
3+
Revision ID: 2a04911f3c9f
4+
Revises: 3fc5d75723b3
5+
Create Date: 2025-08-01 15:32:06.453072
6+
7+
"""
8+
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "2a04911f3c9f"
15+
down_revision = "3fc5d75723b3"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade() -> None:
21+
op.add_column(
22+
"tag",
23+
sa.Column(
24+
"tag_type",
25+
sa.Enum("single", "list", name="tagtype", native_enum=False),
26+
nullable=True,
27+
),
28+
)
29+
30+
31+
def downgrade() -> None:
32+
op.drop_column("tag", "tag_type")

backend/onyx/configs/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ class DocumentSource(str, Enum):
195195
MOCK_CONNECTOR = "mock_connector"
196196

197197

198+
class TagType(str, Enum):
199+
SINGLE = "single"
200+
LIST = "list"
201+
202+
198203
class FederatedConnectorSource(str, Enum):
199204
FEDERATED_SLACK = "federated_slack"
200205

backend/onyx/db/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
MilestoneRecordType,
5151
)
5252
from onyx.configs.constants import DocumentSource
53+
from onyx.configs.constants import TagType
5354
from onyx.configs.constants import FileOrigin
5455
from onyx.configs.constants import MessageType
5556
from onyx.db.enums import (
@@ -1293,6 +1294,9 @@ class Tag(Base):
12931294
source: Mapped[DocumentSource] = mapped_column(
12941295
Enum(DocumentSource, native_enum=False)
12951296
)
1297+
tag_type: Mapped[TagType] = mapped_column(
1298+
Enum(TagType, native_enum=False), nullable=True
1299+
)
12961300

12971301
documents = relationship(
12981302
"Document",

backend/onyx/db/tag.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlalchemy.orm import Session
88

99
from onyx.configs.constants import DocumentSource
10+
from onyx.configs.constants import TagType
1011
from onyx.db.models import Document
1112
from onyx.db.models import Document__Tag
1213
from onyx.db.models import Tag
@@ -58,9 +59,17 @@ def create_or_add_document_tag(
5859
tag = db_session.execute(tag_stmt).scalar_one_or_none()
5960

6061
if not tag:
61-
tag = Tag(tag_key=tag_key, tag_value=tag_value, source=source)
62+
tag = Tag(
63+
tag_key=tag_key,
64+
tag_value=tag_value,
65+
source=source,
66+
tag_type=TagType.SINGLE,
67+
)
6268
db_session.add(tag)
6369

70+
elif tag.tag_type is None:
71+
tag.tag_type = TagType.SINGLE
72+
6473
if tag not in document.tags:
6574
document.tags.append(tag)
6675

@@ -107,10 +116,23 @@ def create_or_add_document_tag_list(
107116
new_tags = []
108117
for tag_value in valid_tag_values:
109118
if tag_value not in existing_tag_values:
110-
new_tag = Tag(tag_key=tag_key, tag_value=tag_value, source=source)
119+
new_tag = Tag(
120+
tag_key=tag_key,
121+
tag_value=tag_value,
122+
source=source,
123+
tag_type=TagType.LIST,
124+
)
111125
db_session.add(new_tag)
112126
new_tags.append(new_tag)
113127
existing_tag_values.add(tag_value)
128+
else:
129+
# Find the existing tag and update its type if needed
130+
for existing_tag in existing_tags:
131+
if (
132+
existing_tag.tag_value == tag_value
133+
and existing_tag.tag_type is None
134+
):
135+
existing_tag.tag_type = TagType.LIST
114136

115137
if new_tags:
116138
logger.debug(

0 commit comments

Comments
 (0)