Skip to content

Commit

Permalink
Change safe-app primary key (#128)
Browse files Browse the repository at this point in the history
- Add app_id to SafeApp model
- app_id is the new primary key (previous primary key was the url)
- Remove safe-apps fixture – it does not correspond with the new model and the autogenerated primary key
  • Loading branch information
fmrsabino authored Jun 29, 2021
1 parent e4b431d commit 2ccf0e1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 309 deletions.
307 changes: 0 additions & 307 deletions src/safe_apps/fixtures/initial_default_apps.json

This file was deleted.

25 changes: 25 additions & 0 deletions src/safe_apps/migrations/0004_add_auto_pk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.4 on 2021-06-28 14:45

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("safe_apps", "0003_alter_safeapp_provider"),
]

operations = [
# Remove Primary Key constraint from safeapp.url
migrations.AlterField(
model_name="safeapp",
name="url",
field=models.URLField(),
),
# Add safeapp.app_id as primary key
migrations.AddField(
model_name="safeapp",
name="app_id",
field=models.BigAutoField(primary_key=True, serialize=False),
preserve_default=False,
),
]
3 changes: 2 additions & 1 deletion src/safe_apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def __str__(self):


class SafeApp(models.Model):
url = models.URLField(primary_key=True)
app_id = models.BigAutoField(primary_key=True)
url = models.URLField()
name = models.CharField(max_length=200)
icon_url = models.URLField()
description = models.CharField(max_length=200)
Expand Down
11 changes: 10 additions & 1 deletion src/safe_apps/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ class Meta:


class SafeAppsResponseSerializer(serializers.ModelSerializer):
id = serializers.IntegerField(source="app_id")
provider = ProviderSerializer()

class Meta:
model = SafeApp
fields = ["url", "name", "icon_url", "description", "chain_ids", "provider"]
fields = [
"id",
"url",
"name",
"icon_url",
"description",
"chain_ids",
"provider",
]
1 change: 1 addition & 0 deletions src/safe_apps/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SafeAppFactory(DjangoModelFactory):
class Meta:
model = SafeApp

app_id = factory.Faker("pyint")
url = factory.Faker("url")
name = factory.Faker("company")
icon_url = factory.Faker("image_url")
Expand Down
Loading

0 comments on commit 2ccf0e1

Please sign in to comment.