Skip to content

Commit

Permalink
add migration for AccessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox committed Sep 12, 2024
1 parent bf1f05b commit 0c0baaf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 5.0.8 on 2024-09-12 20:15

import oauth2_provider.models
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.
Taken from https://github.com/jazzband/django-oauth-toolkit/pull/1491/
"""
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 = [
("api", "0004_application_allowed_origins_and_more"),
]

operations = [
migrations.AddField(
model_name="accesstoken",
name="token_checksum",
field=oauth2_provider.models.TokenChecksumField(
db_index=True, default="", max_length=64, blank=True, null=True
),
preserve_default=False,
),
migrations.AddField(
model_name="refreshtoken",
name="token_family",
field=models.UUIDField(blank=True, editable=False, null=True),
),
migrations.AlterField(
model_name="accesstoken",
name="token",
field=models.TextField(),
),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
migrations.AlterField(
model_name="accesstoken",
name="token_checksum",
field=oauth2_provider.models.TokenChecksumField(
blank=False, max_length=64, db_index=True, unique=True
),
),
]
4 changes: 1 addition & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ django-filter = "^24.0"
djangorestframework-guardian = "^0.3.0"
uritemplate = "^4.1.1"
django-recurrence = "^1.11.1"
django-oauth-toolkit = ">=2.4,<3.1" # pinned because minor versions sometimes require migrations in our models
django-oauth-toolkit = "~3.0.1" # pinned because minor versions sometimes require migrations in our models
urllib3 = "^1.26.0,<2.0.0" # pinned because of uberspace issues with urllib3 2.0.0
pyyaml = "^6.0.1"
lxml = ">=4.9.3,<6.0.0"
Expand Down

0 comments on commit 0c0baaf

Please sign in to comment.