Skip to content

Commit

Permalink
fix: add logo_annotation.server_type field
Browse files Browse the repository at this point in the history
This is the same as ImageModel.server_type, but we store it here to
avoid performing a double join with ImageModel table when we need to
filter logos by server_type
(LogoAnnotation > ImagePrediction > ImageModel)
  • Loading branch information
raphael0202 committed Aug 19, 2024
1 parent 6ba5f7e commit a21859e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
23 changes: 23 additions & 0 deletions migrations/006_add_logo_annotation_server_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import peewee as pw
from peewee_migrate import Migrator


def migrate(migrator: Migrator, database: pw.Database, *, fake=False):
"""Write your migrations here."""

migrator.add_fields(
"logo_annotation",
server_type=pw.CharField(
null=True,
max_length=10,
help_text="project associated with the logo annotation, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=False,
),
)


def rollback(migrator: Migrator, database: pw.Database, *, fake=False):
"""Write your rollback migrations here."""

migrator.remove_fields("logo_annotation", "server_type")
15 changes: 13 additions & 2 deletions robotoff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class Prediction(BaseModel):
server_type = peewee.CharField(
null=False,
max_length=10,
help_text="project associated with the insight, "
"one of 'off', 'obf', 'opff', 'opf'",
help_text="project associated with the prediction, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=True,
default="off",
)
Expand Down Expand Up @@ -343,6 +343,17 @@ class LogoAnnotation(BaseModel):
source_image = peewee.TextField(null=True, index=True)
# The logo text extracted from the image using OCR
text = peewee.TextField(null=True)
# This is the same as ImageModel.server_type, but we store it here to
# avoid performing a double join with ImageModel table when we need to
# filter logos by server_type
# (LogoAnnotation > ImagePrediction > ImageModel)
server_type = peewee.CharField(
null=True,
max_length=10,
help_text="project associated with the logo annotation, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=False,
)

class Meta:
constraints = [peewee.SQL("UNIQUE(image_prediction_id, index)")]
Expand Down

0 comments on commit a21859e

Please sign in to comment.