diff --git a/users/migrations/0020_populate_cors_allowed_origins.py b/users/migrations/0020_populate_cors_allowed_origins.py index 23535eca..bb5c6cbe 100644 --- a/users/migrations/0020_populate_cors_allowed_origins.py +++ b/users/migrations/0020_populate_cors_allowed_origins.py @@ -1,6 +1,6 @@ # Generated by Django 2.1.11 on 2019-09-02 13:05 -from django.db import migrations +from django.db import migrations, ProgrammingError from users.signals import generate_and_save_allowed_origins_from_client_configurations @@ -12,12 +12,26 @@ def populate_allowed_origin(apps, schema_editor): def _noop(apps, schema_editor): return +from django.db import connection + +def check_migration_applied(app_name, migration_name): + try: + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM django_migrations WHERE app=%s AND name=%s", [app_name, migration_name]) + row = cursor.fetchone() + except ProgrammingError: + return False + return bool(row) + +def get_dependencies(): + if check_migration_applied("users", "0020_populate_cors_allowed_origins"): + return [("users", "0019_allowedorigin")] + return [("users", "0034_application_algorithm_and_more")] + class Migration(migrations.Migration): - dependencies = [ - ('users', '0019_allowedorigin'), - ] + dependencies = get_dependencies() operations = [ migrations.RunPython(populate_allowed_origin, _noop), diff --git a/users/migrations/0034_application_algorithm_and_more.py b/users/migrations/0034_application_algorithm_and_more.py new file mode 100644 index 00000000..b1111d1d --- /dev/null +++ b/users/migrations/0034_application_algorithm_and_more.py @@ -0,0 +1,66 @@ +# Generated by Django 4.2.13 on 2024-07-04 13:39 + +from django.conf import settings +from django.db import migrations, models, ProgrammingError +import django.db.models.deletion +from django.db import connection + +def check_migration_applied(app_name, migration_name): + try: + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM django_migrations WHERE app=%s AND name=%s", [app_name, migration_name]) + row = cursor.fetchone() + except ProgrammingError: + return False + return bool(row) + +def get_dependencies(): + if check_migration_applied("users", "0020_populate_cors_allowed_origins"): + return [("users", "0033_alter_loginmethod_provider_id")] + return [("users", "0019_allowedorigin")] + +class Migration(migrations.Migration): + + dependencies = get_dependencies() + + operations = [ + migrations.AddField( + model_name="application", + name="algorithm", + field=models.CharField( + blank=True, + choices=[ + ("", "No OIDC support"), + ("RS256", "RSA with SHA-2 256"), + ("HS256", "HMAC with SHA-2 256"), + ], + default="", + max_length=5, + ), + ), + migrations.AlterField( + model_name="application", + name="authorization_grant_type", + field=models.CharField( + choices=[ + ("authorization-code", "Authorization code"), + ("implicit", "Implicit"), + ("password", "Resource owner password-based"), + ("client-credentials", "Client credentials"), + ("openid-hybrid", "OpenID connect hybrid"), + ], + max_length=32, + ), + ), + migrations.AlterField( + model_name="application", + name="user", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="%(app_label)s_%(class)s", + to=settings.AUTH_USER_MODEL, + ), + ), + ]