Skip to content
Snippets Groups Projects
Verified Commit d731800b authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[OAuth] Add migration for moving OAuth applications to custom model

parent 4775332c
No related branches found
No related tags found
1 merge request!724Resolve "OAuth Provider: Allow several/all Grant Flows"
# Generated by Django 3.2.8 on 2021-11-04 09:52
from django.apps import apps as global_apps
from django.conf import settings
from django.db import migrations, models
from django.db import connection, migrations, models
import django.db.models.deletion
import oauth2_provider.generators
def migrate_oauth_applications(apps, schema_editor):
db_alias = schema_editor.connection.alias
try:
OldApp = apps.get_model("oauth2_provider", "Application")
except LookupError:
return
NewApp = apps.get_model("core", "OAuthApplication")
if connection.instrospection.table_names() & set(OldApp._meta.db_table):
NewApp.objects.using(db_alias).bulk_create(
[NewApp(**old_app) for old_app in OldApp.objects.values()]
)
class Migration(migrations.Migration):
......@@ -13,9 +28,7 @@ class Migration(migrations.Migration):
('core', '0022_public_favicon'),
]
run_before = [
('oauth2_provider', '0001_initial'),
]
run_before = []
operations = [
migrations.CreateModel(
......@@ -39,3 +52,11 @@ class Migration(migrations.Migration):
},
),
]
if global_apps.is_installed("oauth2_provider"):
operations += [
migrations.RunPython(migrate_oauth_applications),
migrations.RunSQL("DROP TABLE IF EXISTS oauth2_provider_application;"),
]
else:
run_before.append(('oauth2_provider', '0001_initial'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment