Migrations fail when using mssql
I'm currently using this package and noticed that one of the migrations fail when using MSSQL. I've got a temporary workaround by faking the migration, but I wanted to point out what the issue is so that it can hopefully get fixed. The issue occurs in the migration file oauth2_authcodeflow\migrations\0003_auto_20210528_1432.py because the max_length is set to 15000 on the token field for the blacklistedtoken model. The problem is that the max length for a CharField in MSSQL is only 4000. I saw in the git history that this was changed from a TextField to solve a problem with MySQL in Innodb, and I'm not sure if lowering the max_length to 4000 would break thing in other database management systems.
An easy solution would be to add a new environment variable with a default of 15000 that could be overwritten by users to control the field size. Something like:
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('oauth2_authcodeflow', '0002_auto_20210528_1422'),
]
operations = [
migrations.AlterField(
model_name='blacklistedtoken',
name='token',
field=models.CharField(editable=False, max_length=settings.BLACK_LISTED_TOKEN_MAX_LENGTH),
),
]
And in the model:
class BlacklistedToken(models.Model):
username = models.CharField(max_length=255, editable=False, db_index=True)
# no max length in RFC6749 but:
# - https://docs.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens
# - https://stackoverflow.com/questions/24892496/max-size-for-oauth-token
# postgres, sqlite, mysql >= 5.0.3 or oracle >= 12c required
token = models.CharField(max_length=settings.BLACK_LISTED_TOKEN_MAX_LENGTH, editable=False)
expires_at = models.DateTimeField(db_index=True)
blacklisted_at = models.DateTimeField(editable=False, db_index=True)
The other alternative would be to add an option to leave the field as a text field.