authentik.policies.expression.migrations.0003_auto_20201203_1223

 1# Generated by Django 3.1.3 on 2020-12-03 12:23
 2
 3from django.apps.registry import Apps
 4from django.db import migrations
 5from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 6
 7
 8def replace_pb_prefix(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
 9    ExpressionPolicy = apps.get_model("authentik_policies_expression", "ExpressionPolicy")
10
11    db_alias = schema_editor.connection.alias
12
13    for policy in ExpressionPolicy.objects.using(db_alias).all():
14        # Because the previous migration had a broken replace, we have to replace here again
15        policy.expression = policy.expression.replace("pb_flow_plan.", "context.")
16        policy.expression = policy.expression.replace("pb_is_sso_flow", "ak_is_sso_flow")
17        policy.save()
18
19
20class Migration(migrations.Migration):
21    dependencies = [
22        ("authentik_policies_expression", "0002_auto_20200926_1156"),
23    ]
24
25    operations = [
26        migrations.RunPython(replace_pb_prefix),
27    ]
def replace_pb_prefix( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
 9def replace_pb_prefix(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    ExpressionPolicy = apps.get_model("authentik_policies_expression", "ExpressionPolicy")
11
12    db_alias = schema_editor.connection.alias
13
14    for policy in ExpressionPolicy.objects.using(db_alias).all():
15        # Because the previous migration had a broken replace, we have to replace here again
16        policy.expression = policy.expression.replace("pb_flow_plan.", "context.")
17        policy.expression = policy.expression.replace("pb_is_sso_flow", "ak_is_sso_flow")
18        policy.save()
class Migration(django.db.migrations.migration.Migration):
21class Migration(migrations.Migration):
22    dependencies = [
23        ("authentik_policies_expression", "0002_auto_20200926_1156"),
24    ]
25
26    operations = [
27        migrations.RunPython(replace_pb_prefix),
28    ]

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_policies_expression', '0002_auto_20200926_1156')]
operations = [<RunPython <function replace_pb_prefix>>]