Skip to content

Commit

Permalink
Store reference pk as text
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-misuk-valor committed May 24, 2024
1 parent ae004c0 commit c8c6e85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/hope_dedup_engine/apps/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-05-22 13:24
# Generated by Django 5.0.6 on 2024-05-24 11:45

import django.db.models.deletion
import uuid
Expand All @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("name", models.CharField(max_length=100)),
("reference_pk", models.IntegerField()),
("reference_pk", models.CharField(max_length=100)),
(
"state",
models.IntegerField(
Expand Down Expand Up @@ -62,9 +62,9 @@ class Migration(migrations.Migration):
name="Duplicate",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("first_reference_pk", models.IntegerField()),
("first_reference_pk", models.CharField(max_length=100)),
("first_filename", models.CharField(max_length=255)),
("second_reference_pk", models.IntegerField()),
("second_reference_pk", models.CharField(max_length=100)),
("second_filename", models.CharField(max_length=255)),
("score", models.FloatField()),
(
Expand Down Expand Up @@ -97,7 +97,7 @@ class Migration(migrations.Migration):
name="Image",
fields=[
("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
("reference_pk", models.IntegerField()),
("reference_pk", models.CharField(max_length=100)),
("filename", models.CharField(max_length=255)),
("created_at", models.DateTimeField(auto_now_add=True)),
(
Expand Down
10 changes: 6 additions & 4 deletions src/hope_dedup_engine/apps/api/models/deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from hope_dedup_engine.apps.security.models import ExternalSystem

REFERENCE_PK_LENGTH = 100


class DeduplicationSet(models.Model):
class State(models.IntegerChoices):
Expand All @@ -15,7 +17,7 @@ class State(models.IntegerChoices):

id = models.UUIDField(primary_key=True, default=uuid4)
name = models.CharField(max_length=100)
reference_pk = models.IntegerField()
reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)
state = models.IntegerField(
choices=State.choices,
default=State.CLEAN,
Expand All @@ -36,7 +38,7 @@ class State(models.IntegerChoices):
class Image(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4)
deduplication_set = models.ForeignKey(DeduplicationSet, on_delete=models.CASCADE)
reference_pk = models.IntegerField()
reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)
filename = models.CharField(max_length=255)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True, related_name="+"
Expand All @@ -46,8 +48,8 @@ class Image(models.Model):

class Duplicate(models.Model):
deduplication_set = models.ForeignKey(DeduplicationSet, on_delete=models.CASCADE)
first_reference_pk = models.IntegerField()
first_reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)
first_filename = models.CharField(max_length=255)
second_reference_pk = models.IntegerField()
second_reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH)
second_filename = models.CharField(max_length=255)
score = models.FloatField()
2 changes: 0 additions & 2 deletions tests/api/test_deduplication_set_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def test_missing_fields_handling(api_client: APIClient, omit: str | tuple[str, .
(
("name", ""),
("name", None),
("reference_pk", "foo"),
("reference_pk", None),
("reference_pk", 3.14),
),
)
def test_invalid_values_handling(api_client: APIClient, field: str, value: Any) -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/extras/testutils/factories/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Meta:

class DeduplicationSetFactory(DjangoModelFactory):
name = fuzzy.FuzzyText()
reference_pk = fuzzy.FuzzyInteger(low=1)
reference_pk = fuzzy.FuzzyText()
external_system = SubFactory(ExternalSystemFactory)
state = DeduplicationSet.State.CLEAN

Expand All @@ -24,7 +24,7 @@ class Meta:
class ImageFactory(DjangoModelFactory):
deduplication_set = SubFactory(DeduplicationSetFactory)
filename = fuzzy.FuzzyText()
reference_pk = fuzzy.FuzzyInteger(low=1)
reference_pk = fuzzy.FuzzyText()

class Meta:
model = Image
Expand All @@ -33,9 +33,9 @@ class Meta:
class DuplicateFactory(DjangoModelFactory):
deduplication_set = SubFactory(DeduplicationSetFactory)
first_filename = fuzzy.FuzzyText()
first_reference_pk = fuzzy.FuzzyInteger(low=1)
first_reference_pk = fuzzy.FuzzyText()
second_filename = fuzzy.FuzzyText()
second_reference_pk = fuzzy.FuzzyInteger(low=1)
second_reference_pk = fuzzy.FuzzyText()
score = fuzzy.FuzzyFloat(low=0, high=1)

class Meta:
Expand Down

0 comments on commit c8c6e85

Please sign in to comment.