authentik.stages.password.migrations.0008_replace_inbuilt

 1# Generated by Django 3.2.6 on 2021-08-23 14:34
 2from django.apps.registry import Apps
 3from django.db import migrations
 4from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 5
 6from authentik.stages.password import BACKEND_INBUILT
 7
 8
 9def replace_inbuilt(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    PasswordStage = apps.get_model("authentik_stages_password", "passwordstage")
11    db_alias = schema_editor.connection.alias
12
13    for stage in PasswordStage.objects.using(db_alias).all():
14        if "django.contrib.auth.backends.ModelBackend" not in stage.backends:
15            continue
16        stage.backends.remove("django.contrib.auth.backends.ModelBackend")
17        stage.backends.append(BACKEND_INBUILT)
18        stage.backends.sort()
19        stage.save()
20
21
22class Migration(migrations.Migration):
23    dependencies = [
24        ("authentik_stages_password", "0007_app_password"),
25    ]
26
27    operations = [
28        migrations.RunPython(replace_inbuilt),
29    ]
def replace_inbuilt( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
10def replace_inbuilt(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
11    PasswordStage = apps.get_model("authentik_stages_password", "passwordstage")
12    db_alias = schema_editor.connection.alias
13
14    for stage in PasswordStage.objects.using(db_alias).all():
15        if "django.contrib.auth.backends.ModelBackend" not in stage.backends:
16            continue
17        stage.backends.remove("django.contrib.auth.backends.ModelBackend")
18        stage.backends.append(BACKEND_INBUILT)
19        stage.backends.sort()
20        stage.save()
class Migration(django.db.migrations.migration.Migration):
23class Migration(migrations.Migration):
24    dependencies = [
25        ("authentik_stages_password", "0007_app_password"),
26    ]
27
28    operations = [
29        migrations.RunPython(replace_inbuilt),
30    ]

The base class for all migrations.

Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:

  • operations: A list of Operation instances, probably from django.db.migrations.operations
  • dependencies: A list of tuples of (app_path, migration_name)
  • run_before: A list of tuples of (app_path, migration_name)
  • replaces: A list of migration_names

Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.

dependencies = [('authentik_stages_password', '0007_app_password')]
operations = [<RunPython <function replace_inbuilt>>]