-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make migrations applicable on fresh and old env
There is a problem when running migrations users.0022 migraition on fresh env since there is a custom code which touches the models and those fields haven't been yet fully updated until in the 0034 migration. So this tweaks those migrations dependencies based on migration apply info. Refs HP-2441
- Loading branch information
Showing
2 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
), | ||
] |