authentik.policies.event_matcher.migrations.0023_alter_eventmatcherpolicy_action_and_more

  1# Generated by Django 4.1.7 on 2023-06-21 12:45
  2
  3from django.apps.registry import Apps
  4from django.db import migrations, models
  5from django.db.backends.base.schema import BaseDatabaseSchemaEditor
  6
  7
  8def replace_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
  9    db_alias = schema_editor.connection.alias
 10
 11    eventmatcherpolicy = apps.get_model("authentik_policies_event_matcher", "eventmatcherpolicy")
 12    for policy in eventmatcherpolicy.objects.using(db_alias).all():
 13        changed = False
 14        if policy.action == "":
 15            policy.action = None
 16            changed = True
 17        if policy.app == "":
 18            policy.app = None
 19            changed = True
 20        if policy.client_ip == "":
 21            policy.client_ip = None
 22            changed = True
 23        if policy.model == "":
 24            policy.model = None
 25            changed = True
 26        if not changed:
 27            continue
 28        policy.save()
 29
 30
 31class Migration(migrations.Migration):
 32    dependencies = [
 33        ("authentik_policies_event_matcher", "0022_eventmatcherpolicy_model"),
 34    ]
 35
 36    operations = [
 37        migrations.AlterField(
 38            model_name="eventmatcherpolicy",
 39            name="action",
 40            field=models.TextField(
 41                choices=[
 42                    ("login", "Login"),
 43                    ("login_failed", "Login Failed"),
 44                    ("logout", "Logout"),
 45                    ("user_write", "User Write"),
 46                    ("suspicious_request", "Suspicious Request"),
 47                    ("password_set", "Password Set"),
 48                    ("secret_view", "Secret View"),
 49                    ("secret_rotate", "Secret Rotate"),
 50                    ("invitation_used", "Invite Used"),
 51                    ("authorize_application", "Authorize Application"),
 52                    ("source_linked", "Source Linked"),
 53                    ("impersonation_started", "Impersonation Started"),
 54                    ("impersonation_ended", "Impersonation Ended"),
 55                    ("flow_execution", "Flow Execution"),
 56                    ("policy_execution", "Policy Execution"),
 57                    ("policy_exception", "Policy Exception"),
 58                    ("property_mapping_exception", "Property Mapping Exception"),
 59                    ("system_task_execution", "System Task Execution"),
 60                    ("system_task_exception", "System Task Exception"),
 61                    ("system_exception", "System Exception"),
 62                    ("configuration_error", "Configuration Error"),
 63                    ("model_created", "Model Created"),
 64                    ("model_updated", "Model Updated"),
 65                    ("model_deleted", "Model Deleted"),
 66                    ("email_sent", "Email Sent"),
 67                    ("update_available", "Update Available"),
 68                    ("custom_", "Custom Prefix"),
 69                ],
 70                default=None,
 71                help_text="Match created events with this action type. When left empty, all action types will be matched.",
 72                null=True,
 73            ),
 74        ),
 75        migrations.AlterField(
 76            model_name="eventmatcherpolicy",
 77            name="app",
 78            field=models.TextField(
 79                default=None,
 80                help_text="Match events created by selected application. When left empty, all applications are matched.",
 81                null=True,
 82            ),
 83        ),
 84        migrations.AlterField(
 85            model_name="eventmatcherpolicy",
 86            name="client_ip",
 87            field=models.TextField(
 88                default=None,
 89                help_text="Matches Event's Client IP (strict matching, for network matching use an Expression Policy)",
 90                null=True,
 91            ),
 92        ),
 93        migrations.AlterField(
 94            model_name="eventmatcherpolicy",
 95            name="model",
 96            field=models.TextField(
 97                default=None,
 98                help_text="Match events created by selected model. When left empty, all models are matched. When an app is selected, all the application's models are matched.",
 99                null=True,
100            ),
101        ),
102        migrations.RunPython(replace_defaults),
103    ]
def replace_defaults( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
 9def replace_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    db_alias = schema_editor.connection.alias
11
12    eventmatcherpolicy = apps.get_model("authentik_policies_event_matcher", "eventmatcherpolicy")
13    for policy in eventmatcherpolicy.objects.using(db_alias).all():
14        changed = False
15        if policy.action == "":
16            policy.action = None
17            changed = True
18        if policy.app == "":
19            policy.app = None
20            changed = True
21        if policy.client_ip == "":
22            policy.client_ip = None
23            changed = True
24        if policy.model == "":
25            policy.model = None
26            changed = True
27        if not changed:
28            continue
29        policy.save()
class Migration(django.db.migrations.migration.Migration):
 32class Migration(migrations.Migration):
 33    dependencies = [
 34        ("authentik_policies_event_matcher", "0022_eventmatcherpolicy_model"),
 35    ]
 36
 37    operations = [
 38        migrations.AlterField(
 39            model_name="eventmatcherpolicy",
 40            name="action",
 41            field=models.TextField(
 42                choices=[
 43                    ("login", "Login"),
 44                    ("login_failed", "Login Failed"),
 45                    ("logout", "Logout"),
 46                    ("user_write", "User Write"),
 47                    ("suspicious_request", "Suspicious Request"),
 48                    ("password_set", "Password Set"),
 49                    ("secret_view", "Secret View"),
 50                    ("secret_rotate", "Secret Rotate"),
 51                    ("invitation_used", "Invite Used"),
 52                    ("authorize_application", "Authorize Application"),
 53                    ("source_linked", "Source Linked"),
 54                    ("impersonation_started", "Impersonation Started"),
 55                    ("impersonation_ended", "Impersonation Ended"),
 56                    ("flow_execution", "Flow Execution"),
 57                    ("policy_execution", "Policy Execution"),
 58                    ("policy_exception", "Policy Exception"),
 59                    ("property_mapping_exception", "Property Mapping Exception"),
 60                    ("system_task_execution", "System Task Execution"),
 61                    ("system_task_exception", "System Task Exception"),
 62                    ("system_exception", "System Exception"),
 63                    ("configuration_error", "Configuration Error"),
 64                    ("model_created", "Model Created"),
 65                    ("model_updated", "Model Updated"),
 66                    ("model_deleted", "Model Deleted"),
 67                    ("email_sent", "Email Sent"),
 68                    ("update_available", "Update Available"),
 69                    ("custom_", "Custom Prefix"),
 70                ],
 71                default=None,
 72                help_text="Match created events with this action type. When left empty, all action types will be matched.",
 73                null=True,
 74            ),
 75        ),
 76        migrations.AlterField(
 77            model_name="eventmatcherpolicy",
 78            name="app",
 79            field=models.TextField(
 80                default=None,
 81                help_text="Match events created by selected application. When left empty, all applications are matched.",
 82                null=True,
 83            ),
 84        ),
 85        migrations.AlterField(
 86            model_name="eventmatcherpolicy",
 87            name="client_ip",
 88            field=models.TextField(
 89                default=None,
 90                help_text="Matches Event's Client IP (strict matching, for network matching use an Expression Policy)",
 91                null=True,
 92            ),
 93        ),
 94        migrations.AlterField(
 95            model_name="eventmatcherpolicy",
 96            name="model",
 97            field=models.TextField(
 98                default=None,
 99                help_text="Match events created by selected model. When left empty, all models are matched. When an app is selected, all the application's models are matched.",
100                null=True,
101            ),
102        ),
103        migrations.RunPython(replace_defaults),
104    ]

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_event_matcher', '0022_eventmatcherpolicy_model')]
operations = [<AlterField model_name='eventmatcherpolicy', name='action', field=<django.db.models.fields.TextField>>, <AlterField model_name='eventmatcherpolicy', name='app', field=<django.db.models.fields.TextField>>, <AlterField model_name='eventmatcherpolicy', name='client_ip', field=<django.db.models.fields.TextField>>, <AlterField model_name='eventmatcherpolicy', name='model', field=<django.db.models.fields.TextField>>, <RunPython <function replace_defaults>>]