From eb545bdf49032b32b680839c14bc1fb046e72b97 Mon Sep 17 00:00:00 2001 From: Afonso Albrecht Date: Thu, 8 Feb 2024 20:06:35 +0100 Subject: [PATCH 1/2] Merge token_blacklist migrations into one ([#615](https://github.com/jazzband/djangorestframework-simplejwt/issues/615)) - Initial migrations defined id as AutoField, later migrations changed the type to BigAutoField. This conversion is not allowed in MSSQL --- .../migrations/0001_initial.py | 60 ++++++------------- .../0002_outstandingtoken_jti_hex.py | 15 ----- .../migrations/0003_auto_20171017_2007.py | 31 ---------- .../migrations/0004_auto_20171017_2013.py | 15 ----- .../0005_remove_outstandingtoken_jti.py | 14 ----- .../migrations/0006_auto_20171017_2113.py | 15 ----- .../migrations/0007_auto_20171017_2214.py | 27 --------- .../0008_migrate_to_bigautofield.py | 24 -------- .../0010_fix_migrate_to_bigautofield.py | 26 -------- .../migrations/0011_linearizes_history.py | 18 ------ .../0012_alter_outstandingtoken_user.py | 25 -------- 11 files changed, 19 insertions(+), 251 deletions(-) delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0002_outstandingtoken_jti_hex.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0004_auto_20171017_2013.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0005_remove_outstandingtoken_jti.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0006_auto_20171017_2113.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0007_auto_20171017_2214.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0008_migrate_to_bigautofield.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0010_fix_migrate_to_bigautofield.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0011_linearizes_history.py delete mode 100644 rest_framework_simplejwt/token_blacklist/migrations/0012_alter_outstandingtoken_user.py diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py b/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py index 88baa7d93..686365758 100644 --- a/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py +++ b/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py @@ -1,9 +1,12 @@ +# Generated by Django 5.0.2 on 2024-02-08 19:04 + import django.db.models.deletion from django.conf import settings from django.db import migrations, models class Migration(migrations.Migration): + initial = True dependencies = [ @@ -12,54 +15,29 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="BlacklistedToken", + name='OutstandingToken', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("blacklisted_at", models.DateTimeField(auto_now_add=True)), + ('id', models.BigAutoField(primary_key=True, serialize=False)), + ('jti', models.CharField(max_length=255, unique=True)), + ('token', models.TextField()), + ('created_at', models.DateTimeField(blank=True, null=True)), + ('expires_at', models.DateTimeField()), + ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), ], + options={ + 'ordering': ('user',), + 'abstract': False, + }, ), migrations.CreateModel( - name="OutstandingToken", + name='BlacklistedToken', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("jti", models.UUIDField(unique=True)), - ("token", models.TextField()), - ("created_at", models.DateTimeField()), - ("expires_at", models.DateTimeField()), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), + ('id', models.BigAutoField(primary_key=True, serialize=False)), + ('blacklisted_at', models.DateTimeField(auto_now_add=True)), + ('token', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='token_blacklist.outstandingtoken')), ], options={ - "ordering": ("user",), + 'abstract': False, }, ), - migrations.AddField( - model_name="blacklistedtoken", - name="token", - field=models.OneToOneField( - on_delete=django.db.models.deletion.CASCADE, - to="token_blacklist.OutstandingToken", - ), - ), ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0002_outstandingtoken_jti_hex.py b/rest_framework_simplejwt/token_blacklist/migrations/0002_outstandingtoken_jti_hex.py deleted file mode 100644 index 59af197e6..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0002_outstandingtoken_jti_hex.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="outstandingtoken", - name="jti_hex", - field=models.CharField(blank=True, null=True, max_length=255), - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py b/rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py deleted file mode 100644 index 1b753499a..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py +++ /dev/null @@ -1,31 +0,0 @@ -from uuid import UUID - -from django.db import migrations - - -def populate_jti_hex(apps, schema_editor): - OutstandingToken = apps.get_model("token_blacklist", "OutstandingToken") - - db_alias = schema_editor.connection.alias - for token in OutstandingToken.objects.using(db_alias).all(): - token.jti_hex = token.jti.hex - token.save() - - -def reverse_populate_jti_hex(apps, schema_editor): # pragma: no cover - OutstandingToken = apps.get_model("token_blacklist", "OutstandingToken") - - db_alias = schema_editor.connection.alias - for token in OutstandingToken.objects.using(db_alias).all(): - token.jti = UUID(hex=token.jti_hex) - token.save() - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0002_outstandingtoken_jti_hex"), - ] - - operations = [ - migrations.RunPython(populate_jti_hex, reverse_populate_jti_hex), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0004_auto_20171017_2013.py b/rest_framework_simplejwt/token_blacklist/migrations/0004_auto_20171017_2013.py deleted file mode 100644 index f5ba7e9ff..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0004_auto_20171017_2013.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0003_auto_20171017_2007"), - ] - - operations = [ - migrations.AlterField( - model_name="outstandingtoken", - name="jti_hex", - field=models.CharField(unique=True, max_length=255), - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0005_remove_outstandingtoken_jti.py b/rest_framework_simplejwt/token_blacklist/migrations/0005_remove_outstandingtoken_jti.py deleted file mode 100644 index 2b140ed9f..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0005_remove_outstandingtoken_jti.py +++ /dev/null @@ -1,14 +0,0 @@ -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0004_auto_20171017_2013"), - ] - - operations = [ - migrations.RemoveField( - model_name="outstandingtoken", - name="jti", - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0006_auto_20171017_2113.py b/rest_framework_simplejwt/token_blacklist/migrations/0006_auto_20171017_2113.py deleted file mode 100644 index 10f9f1e2a..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0006_auto_20171017_2113.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0005_remove_outstandingtoken_jti"), - ] - - operations = [ - migrations.RenameField( - model_name="outstandingtoken", - old_name="jti_hex", - new_name="jti", - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0007_auto_20171017_2214.py b/rest_framework_simplejwt/token_blacklist/migrations/0007_auto_20171017_2214.py deleted file mode 100644 index 5fa602fd1..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0007_auto_20171017_2214.py +++ /dev/null @@ -1,27 +0,0 @@ -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0006_auto_20171017_2113"), - ] - - operations = [ - migrations.AlterField( - model_name="outstandingtoken", - name="created_at", - field=models.DateTimeField(blank=True, null=True), - ), - migrations.AlterField( - model_name="outstandingtoken", - name="user", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to=settings.AUTH_USER_MODEL, - ), - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0008_migrate_to_bigautofield.py b/rest_framework_simplejwt/token_blacklist/migrations/0008_migrate_to_bigautofield.py deleted file mode 100644 index 9a7735729..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0008_migrate_to_bigautofield.py +++ /dev/null @@ -1,24 +0,0 @@ -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0007_auto_20171017_2214"), - ] - - operations = [ - migrations.AlterField( - model_name="blacklistedtoken", - name="id", - field=models.BigAutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - migrations.AlterField( - model_name="outstandingtoken", - name="id", - field=models.BigAutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0010_fix_migrate_to_bigautofield.py b/rest_framework_simplejwt/token_blacklist/migrations/0010_fix_migrate_to_bigautofield.py deleted file mode 100644 index b6d595df9..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0010_fix_migrate_to_bigautofield.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.2.3 on 2021-05-27 17:46 - -from pathlib import Path - -from django.db import migrations, models - -parent_dir = Path(__file__).resolve(strict=True).parent - - -class Migration(migrations.Migration): - dependencies = [ - ("token_blacklist", "0008_migrate_to_bigautofield"), - ] - - operations = [ - migrations.AlterField( - model_name="blacklistedtoken", - name="id", - field=models.BigAutoField(primary_key=True, serialize=False), - ), - migrations.AlterField( - model_name="outstandingtoken", - name="id", - field=models.BigAutoField(primary_key=True, serialize=False), - ), - ] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0011_linearizes_history.py b/rest_framework_simplejwt/token_blacklist/migrations/0011_linearizes_history.py deleted file mode 100644 index cd102e0c2..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0011_linearizes_history.py +++ /dev/null @@ -1,18 +0,0 @@ -import fnmatch -import os -from pathlib import Path - -from django.db import migrations, models # noqa F401 - -parent_dir = Path(__file__).resolve(strict=True).parent - - -class Migration(migrations.Migration): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.dependencies = [("token_blacklist", "0010_fix_migrate_to_bigautofield")] - _m = sorted(fnmatch.filter(os.listdir(parent_dir), "000*.py")) - if len(_m) == 9: - self.dependencies.insert(0, ("token_blacklist", os.path.splitext(_m[8])[0])) - - operations = [] diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0012_alter_outstandingtoken_user.py b/rest_framework_simplejwt/token_blacklist/migrations/0012_alter_outstandingtoken_user.py deleted file mode 100644 index 91d5e0645..000000000 --- a/rest_framework_simplejwt/token_blacklist/migrations/0012_alter_outstandingtoken_user.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 3.2.10 on 2022-01-24 06:42 - -import django.db.models.deletion -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("token_blacklist", "0011_linearizes_history"), - ] - - operations = [ - migrations.AlterField( - model_name="outstandingtoken", - name="user", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to=settings.AUTH_USER_MODEL, - ), - ), - ] From f4a9be9e5ee3b71748724b7e41163102ddde7562 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 19:21:29 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../migrations/0001_initial.py | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py b/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py index 686365758..1d48c2e83 100644 --- a/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py +++ b/rest_framework_simplejwt/token_blacklist/migrations/0001_initial.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ @@ -15,29 +14,43 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='OutstandingToken', + name="OutstandingToken", fields=[ - ('id', models.BigAutoField(primary_key=True, serialize=False)), - ('jti', models.CharField(max_length=255, unique=True)), - ('token', models.TextField()), - ('created_at', models.DateTimeField(blank=True, null=True)), - ('expires_at', models.DateTimeField()), - ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("jti", models.CharField(max_length=255, unique=True)), + ("token", models.TextField()), + ("created_at", models.DateTimeField(blank=True, null=True)), + ("expires_at", models.DateTimeField()), + ( + "user", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to=settings.AUTH_USER_MODEL, + ), + ), ], options={ - 'ordering': ('user',), - 'abstract': False, + "ordering": ("user",), + "abstract": False, }, ), migrations.CreateModel( - name='BlacklistedToken', + name="BlacklistedToken", fields=[ - ('id', models.BigAutoField(primary_key=True, serialize=False)), - ('blacklisted_at', models.DateTimeField(auto_now_add=True)), - ('token', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='token_blacklist.outstandingtoken')), + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("blacklisted_at", models.DateTimeField(auto_now_add=True)), + ( + "token", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="token_blacklist.outstandingtoken", + ), + ), ], options={ - 'abstract': False, + "abstract": False, }, ), ]