Skip to content

Commit

Permalink
add a forward migration function that computes checksum for existing …
Browse files Browse the repository at this point in the history
…tokens
  • Loading branch information
n2ygk committed Sep 6, 2024
1 parent f220235 commit 08c56f5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion oauth2_provider/migrations/0012_add_token_checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from django.db import migrations, models
from oauth2_provider.settings import oauth2_settings

def forwards_func(apps, schema_editor):
"""
Forward migration touches every "old" accesstoken.token which will cause the checksum to be computed.
"""
AccessToken = apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
accesstokens = AccessToken._default_manager.all()
for accesstoken in accesstokens:
accesstoken.save(update_fields=['token_checksum'])


class Migration(migrations.Migration):
dependencies = [
("oauth2_provider", "0011_refreshtoken_token_family"),
Expand All @@ -15,12 +25,13 @@ class Migration(migrations.Migration):
model_name="accesstoken",
name="token_checksum",
field=oauth2_provider.models.TokenChecksumField(
blank=True, db_index=True, max_length=64, unique=True
blank=True, null=True, db_index=True, max_length=64, unique=True
),
),
migrations.AlterField(
model_name="accesstoken",
name="token",
field=models.TextField(),
),
migrations.RunPython(forwards_func),
]

0 comments on commit 08c56f5

Please sign in to comment.