-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#20] Add an identifier field to the Subscription model
- Loading branch information
1 parent
1629259
commit f75e79c
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
notifications_api_common/migrations/0009_add_subscription_identifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated by Django 5.1.4 on 2024-12-09 08:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def generate_missing_identifiers(apps, schema_editor): | ||
Subscription = apps.get_model("notifications_api_common", "Subscription") | ||
|
||
count = 1 | ||
for subscription in Subscription.objects.all(): | ||
subscription.identifier = f"subscription-{count:02d}" | ||
subscription.save(update_fields=["identifier"]) | ||
count += 1 | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"notifications_api_common", | ||
"0008_merge_0006_auto_20221213_0214_0007_auto_20221206_0414", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="subscription", | ||
name="identifier", | ||
field=models.SlugField( | ||
help_text="A human-friendly identifier to refer to this subscription.", | ||
max_length=64, | ||
null=True, | ||
unique=True, | ||
), | ||
), | ||
migrations.RunPython( | ||
generate_missing_identifiers, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
migrations.AlterField( | ||
model_name="subscription", | ||
name="identifier", | ||
field=models.SlugField( | ||
help_text="A human-friendly identifier to refer to this subscription.", | ||
max_length=64, | ||
unique=True, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters