authentik.policies.event_matcher.migrations.0019_alter_eventmatcherpolicy_app_squashed_0028_alter_eventmatcherpolicy_action
1# Generated by Django 5.2.15 on 2026-07-21 13:24 2 3from django.db import migrations, models 4from django.apps.registry import Apps 5 6from django.db.backends.base.schema import BaseDatabaseSchemaEditor 7 8import authentik.events.models 9 10 11def replace_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 12 db_alias = schema_editor.connection.alias 13 14 eventmatcherpolicy = apps.get_model("authentik_policies_event_matcher", "eventmatcherpolicy") 15 for policy in eventmatcherpolicy.objects.using(db_alias).all(): 16 changed = False 17 if policy.action == "": 18 policy.action = None 19 changed = True 20 if policy.app == "": 21 policy.app = None 22 changed = True 23 if policy.client_ip == "": 24 policy.client_ip = None 25 changed = True 26 if policy.model == "": 27 policy.model = None 28 changed = True 29 if not changed: 30 continue 31 policy.save() 32 33 34class Migration(migrations.Migration): 35 36 replaces = [ 37 ("authentik_policies_event_matcher", "0019_alter_eventmatcherpolicy_app"), 38 ( 39 "authentik_policies_event_matcher", 40 "0020_eventmatcherpolicy_authentik_p_policy__e605cf_idx", 41 ), 42 ("authentik_policies_event_matcher", "0021_alter_eventmatcherpolicy_app"), 43 ("authentik_policies_event_matcher", "0022_eventmatcherpolicy_model"), 44 ("authentik_policies_event_matcher", "0023_alter_eventmatcherpolicy_action_and_more"), 45 ("authentik_policies_event_matcher", "0024_alter_eventmatcherpolicy_action"), 46 ("authentik_policies_event_matcher", "0025_alter_eventmatcherpolicy_action"), 47 ("authentik_policies_event_matcher", "0026_alter_eventmatcherpolicy_action"), 48 ("authentik_policies_event_matcher", "0027_eventmatcherpolicy_query"), 49 ("authentik_policies_event_matcher", "0028_alter_eventmatcherpolicy_action"), 50 ] 51 52 dependencies = [ 53 ("authentik_policies_event_matcher", "0001_squashed_0018_alter_eventmatcherpolicy_action"), 54 ] 55 56 operations = [ 57 migrations.AlterField( 58 model_name="eventmatcherpolicy", 59 name="app", 60 field=models.TextField( 61 blank=True, 62 choices=[ 63 ("authentik.admin", "authentik Admin"), 64 ("authentik.api", "authentik API"), 65 ("authentik.crypto", "authentik Crypto"), 66 ("authentik.events", "authentik Events"), 67 ("authentik.flows", "authentik Flows"), 68 ("authentik.lib", "authentik lib"), 69 ("authentik.outposts", "authentik Outpost"), 70 ("authentik.policies.dummy", "authentik Policies.Dummy"), 71 ("authentik.policies.event_matcher", "authentik Policies.Event Matcher"), 72 ("authentik.policies.expiry", "authentik Policies.Expiry"), 73 ("authentik.policies.expression", "authentik Policies.Expression"), 74 ("authentik.policies.hibp", "authentik Policies.HaveIBeenPwned"), 75 ("authentik.policies.password", "authentik Policies.Password"), 76 ("authentik.policies.reputation", "authentik Policies.Reputation"), 77 ("authentik.policies", "authentik Policies"), 78 ("authentik.providers.ldap", "authentik Providers.LDAP"), 79 ("authentik.providers.oauth2", "authentik Providers.OAuth2"), 80 ("authentik.providers.proxy", "authentik Providers.Proxy"), 81 ("authentik.providers.saml", "authentik Providers.SAML"), 82 ("authentik.recovery", "authentik Recovery"), 83 ("authentik.sources.ldap", "authentik Sources.LDAP"), 84 ("authentik.sources.oauth", "authentik Sources.OAuth"), 85 ("authentik.sources.plex", "authentik Sources.Plex"), 86 ("authentik.sources.saml", "authentik Sources.SAML"), 87 ("authentik.sources.scim", "authentik Sources.SCIM"), 88 ("authentik.stages.authenticator_duo", "authentik Stages.Authenticator.Duo"), 89 ("authentik.stages.authenticator_sms", "authentik Stages.Authenticator.SMS"), 90 ( 91 "authentik.stages.authenticator_static", 92 "authentik Stages.Authenticator.Static", 93 ), 94 ("authentik.stages.authenticator_totp", "authentik Stages.Authenticator.TOTP"), 95 ( 96 "authentik.stages.authenticator_validate", 97 "authentik Stages.Authenticator.Validate", 98 ), 99 ( 100 "authentik.stages.authenticator_webauthn", 101 "authentik Stages.Authenticator.WebAuthn", 102 ), 103 ("authentik.stages.captcha", "authentik Stages.Captcha"), 104 ("authentik.stages.consent", "authentik Stages.Consent"), 105 ("authentik.stages.deny", "authentik Stages.Deny"), 106 ("authentik.stages.dummy", "authentik Stages.Dummy"), 107 ("authentik.stages.email", "authentik Stages.Email"), 108 ("authentik.stages.identification", "authentik Stages.Identification"), 109 ("authentik.stages.invitation", "authentik Stages.User Invitation"), 110 ("authentik.stages.password", "authentik Stages.Password"), 111 ("authentik.stages.prompt", "authentik Stages.Prompt"), 112 ("authentik.stages.user_delete", "authentik Stages.User Delete"), 113 ("authentik.stages.user_login", "authentik Stages.User Login"), 114 ("authentik.stages.user_logout", "authentik Stages.User Logout"), 115 ("authentik.stages.user_write", "authentik Stages.User Write"), 116 ("authentik.brands", "authentik Brands"), 117 ("authentik.blueprints", "authentik Blueprints"), 118 ("authentik.core", "authentik Core"), 119 ], 120 default="", 121 help_text="Match events created by selected application. When left empty, all applications are matched.", 122 ), 123 ), 124 migrations.AddIndex( 125 model_name="eventmatcherpolicy", 126 index=models.Index(fields=["policy_ptr_id"], name="authentik_p_policy__e605cf_idx"), 127 ), 128 migrations.AlterField( 129 model_name="eventmatcherpolicy", 130 name="action", 131 field=models.TextField( 132 choices=[ 133 ("login", "Login"), 134 ("login_failed", "Login Failed"), 135 ("logout", "Logout"), 136 ("user_write", "User Write"), 137 ("suspicious_request", "Suspicious Request"), 138 ("password_set", "Password Set"), 139 ("secret_view", "Secret View"), 140 ("secret_rotate", "Secret Rotate"), 141 ("invitation_used", "Invite Used"), 142 ("authorize_application", "Authorize Application"), 143 ("source_linked", "Source Linked"), 144 ("impersonation_started", "Impersonation Started"), 145 ("impersonation_ended", "Impersonation Ended"), 146 ("flow_execution", "Flow Execution"), 147 ("policy_execution", "Policy Execution"), 148 ("policy_exception", "Policy Exception"), 149 ("property_mapping_exception", "Property Mapping Exception"), 150 ("system_task_execution", "System Task Execution"), 151 ("system_task_exception", "System Task Exception"), 152 ("system_exception", "System Exception"), 153 ("configuration_error", "Configuration Error"), 154 ("model_created", "Model Created"), 155 ("model_updated", "Model Updated"), 156 ("model_deleted", "Model Deleted"), 157 ("email_sent", "Email Sent"), 158 ("update_available", "Update Available"), 159 ("custom_", "Custom Prefix"), 160 ], 161 default=None, 162 help_text="Match created events with this action type. When left empty, all action types will be matched.", 163 null=True, 164 ), 165 ), 166 migrations.AlterField( 167 model_name="eventmatcherpolicy", 168 name="app", 169 field=models.TextField( 170 default=None, 171 help_text="Match events created by selected application. When left empty, all applications are matched.", 172 null=True, 173 ), 174 ), 175 migrations.AlterField( 176 model_name="eventmatcherpolicy", 177 name="client_ip", 178 field=models.TextField( 179 default=None, 180 help_text="Matches Event's Client IP (strict matching, for network matching use an Expression Policy)", 181 null=True, 182 ), 183 ), 184 migrations.AddField( 185 model_name="eventmatcherpolicy", 186 name="model", 187 field=models.TextField( 188 default=None, 189 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.", 190 null=True, 191 ), 192 ), 193 migrations.RunPython( 194 code=replace_defaults, 195 ), 196 migrations.AddField( 197 model_name="eventmatcherpolicy", 198 name="query", 199 field=models.TextField(default=None, null=True), 200 ), 201 migrations.AlterField( 202 model_name="eventmatcherpolicy", 203 name="action", 204 field=models.TextField( 205 choices=authentik.events.models.event_actions, 206 default=None, 207 help_text="Match created events with this action type. When left empty, all action types will be matched.", 208 null=True, 209 ), 210 ), 211 ]
def
replace_defaults( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
12def replace_defaults(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 13 db_alias = schema_editor.connection.alias 14 15 eventmatcherpolicy = apps.get_model("authentik_policies_event_matcher", "eventmatcherpolicy") 16 for policy in eventmatcherpolicy.objects.using(db_alias).all(): 17 changed = False 18 if policy.action == "": 19 policy.action = None 20 changed = True 21 if policy.app == "": 22 policy.app = None 23 changed = True 24 if policy.client_ip == "": 25 policy.client_ip = None 26 changed = True 27 if policy.model == "": 28 policy.model = None 29 changed = True 30 if not changed: 31 continue 32 policy.save()
class
Migration(django.db.migrations.migration.Migration):
35class Migration(migrations.Migration): 36 37 replaces = [ 38 ("authentik_policies_event_matcher", "0019_alter_eventmatcherpolicy_app"), 39 ( 40 "authentik_policies_event_matcher", 41 "0020_eventmatcherpolicy_authentik_p_policy__e605cf_idx", 42 ), 43 ("authentik_policies_event_matcher", "0021_alter_eventmatcherpolicy_app"), 44 ("authentik_policies_event_matcher", "0022_eventmatcherpolicy_model"), 45 ("authentik_policies_event_matcher", "0023_alter_eventmatcherpolicy_action_and_more"), 46 ("authentik_policies_event_matcher", "0024_alter_eventmatcherpolicy_action"), 47 ("authentik_policies_event_matcher", "0025_alter_eventmatcherpolicy_action"), 48 ("authentik_policies_event_matcher", "0026_alter_eventmatcherpolicy_action"), 49 ("authentik_policies_event_matcher", "0027_eventmatcherpolicy_query"), 50 ("authentik_policies_event_matcher", "0028_alter_eventmatcherpolicy_action"), 51 ] 52 53 dependencies = [ 54 ("authentik_policies_event_matcher", "0001_squashed_0018_alter_eventmatcherpolicy_action"), 55 ] 56 57 operations = [ 58 migrations.AlterField( 59 model_name="eventmatcherpolicy", 60 name="app", 61 field=models.TextField( 62 blank=True, 63 choices=[ 64 ("authentik.admin", "authentik Admin"), 65 ("authentik.api", "authentik API"), 66 ("authentik.crypto", "authentik Crypto"), 67 ("authentik.events", "authentik Events"), 68 ("authentik.flows", "authentik Flows"), 69 ("authentik.lib", "authentik lib"), 70 ("authentik.outposts", "authentik Outpost"), 71 ("authentik.policies.dummy", "authentik Policies.Dummy"), 72 ("authentik.policies.event_matcher", "authentik Policies.Event Matcher"), 73 ("authentik.policies.expiry", "authentik Policies.Expiry"), 74 ("authentik.policies.expression", "authentik Policies.Expression"), 75 ("authentik.policies.hibp", "authentik Policies.HaveIBeenPwned"), 76 ("authentik.policies.password", "authentik Policies.Password"), 77 ("authentik.policies.reputation", "authentik Policies.Reputation"), 78 ("authentik.policies", "authentik Policies"), 79 ("authentik.providers.ldap", "authentik Providers.LDAP"), 80 ("authentik.providers.oauth2", "authentik Providers.OAuth2"), 81 ("authentik.providers.proxy", "authentik Providers.Proxy"), 82 ("authentik.providers.saml", "authentik Providers.SAML"), 83 ("authentik.recovery", "authentik Recovery"), 84 ("authentik.sources.ldap", "authentik Sources.LDAP"), 85 ("authentik.sources.oauth", "authentik Sources.OAuth"), 86 ("authentik.sources.plex", "authentik Sources.Plex"), 87 ("authentik.sources.saml", "authentik Sources.SAML"), 88 ("authentik.sources.scim", "authentik Sources.SCIM"), 89 ("authentik.stages.authenticator_duo", "authentik Stages.Authenticator.Duo"), 90 ("authentik.stages.authenticator_sms", "authentik Stages.Authenticator.SMS"), 91 ( 92 "authentik.stages.authenticator_static", 93 "authentik Stages.Authenticator.Static", 94 ), 95 ("authentik.stages.authenticator_totp", "authentik Stages.Authenticator.TOTP"), 96 ( 97 "authentik.stages.authenticator_validate", 98 "authentik Stages.Authenticator.Validate", 99 ), 100 ( 101 "authentik.stages.authenticator_webauthn", 102 "authentik Stages.Authenticator.WebAuthn", 103 ), 104 ("authentik.stages.captcha", "authentik Stages.Captcha"), 105 ("authentik.stages.consent", "authentik Stages.Consent"), 106 ("authentik.stages.deny", "authentik Stages.Deny"), 107 ("authentik.stages.dummy", "authentik Stages.Dummy"), 108 ("authentik.stages.email", "authentik Stages.Email"), 109 ("authentik.stages.identification", "authentik Stages.Identification"), 110 ("authentik.stages.invitation", "authentik Stages.User Invitation"), 111 ("authentik.stages.password", "authentik Stages.Password"), 112 ("authentik.stages.prompt", "authentik Stages.Prompt"), 113 ("authentik.stages.user_delete", "authentik Stages.User Delete"), 114 ("authentik.stages.user_login", "authentik Stages.User Login"), 115 ("authentik.stages.user_logout", "authentik Stages.User Logout"), 116 ("authentik.stages.user_write", "authentik Stages.User Write"), 117 ("authentik.brands", "authentik Brands"), 118 ("authentik.blueprints", "authentik Blueprints"), 119 ("authentik.core", "authentik Core"), 120 ], 121 default="", 122 help_text="Match events created by selected application. When left empty, all applications are matched.", 123 ), 124 ), 125 migrations.AddIndex( 126 model_name="eventmatcherpolicy", 127 index=models.Index(fields=["policy_ptr_id"], name="authentik_p_policy__e605cf_idx"), 128 ), 129 migrations.AlterField( 130 model_name="eventmatcherpolicy", 131 name="action", 132 field=models.TextField( 133 choices=[ 134 ("login", "Login"), 135 ("login_failed", "Login Failed"), 136 ("logout", "Logout"), 137 ("user_write", "User Write"), 138 ("suspicious_request", "Suspicious Request"), 139 ("password_set", "Password Set"), 140 ("secret_view", "Secret View"), 141 ("secret_rotate", "Secret Rotate"), 142 ("invitation_used", "Invite Used"), 143 ("authorize_application", "Authorize Application"), 144 ("source_linked", "Source Linked"), 145 ("impersonation_started", "Impersonation Started"), 146 ("impersonation_ended", "Impersonation Ended"), 147 ("flow_execution", "Flow Execution"), 148 ("policy_execution", "Policy Execution"), 149 ("policy_exception", "Policy Exception"), 150 ("property_mapping_exception", "Property Mapping Exception"), 151 ("system_task_execution", "System Task Execution"), 152 ("system_task_exception", "System Task Exception"), 153 ("system_exception", "System Exception"), 154 ("configuration_error", "Configuration Error"), 155 ("model_created", "Model Created"), 156 ("model_updated", "Model Updated"), 157 ("model_deleted", "Model Deleted"), 158 ("email_sent", "Email Sent"), 159 ("update_available", "Update Available"), 160 ("custom_", "Custom Prefix"), 161 ], 162 default=None, 163 help_text="Match created events with this action type. When left empty, all action types will be matched.", 164 null=True, 165 ), 166 ), 167 migrations.AlterField( 168 model_name="eventmatcherpolicy", 169 name="app", 170 field=models.TextField( 171 default=None, 172 help_text="Match events created by selected application. When left empty, all applications are matched.", 173 null=True, 174 ), 175 ), 176 migrations.AlterField( 177 model_name="eventmatcherpolicy", 178 name="client_ip", 179 field=models.TextField( 180 default=None, 181 help_text="Matches Event's Client IP (strict matching, for network matching use an Expression Policy)", 182 null=True, 183 ), 184 ), 185 migrations.AddField( 186 model_name="eventmatcherpolicy", 187 name="model", 188 field=models.TextField( 189 default=None, 190 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.", 191 null=True, 192 ), 193 ), 194 migrations.RunPython( 195 code=replace_defaults, 196 ), 197 migrations.AddField( 198 model_name="eventmatcherpolicy", 199 name="query", 200 field=models.TextField(default=None, null=True), 201 ), 202 migrations.AlterField( 203 model_name="eventmatcherpolicy", 204 name="action", 205 field=models.TextField( 206 choices=authentik.events.models.event_actions, 207 default=None, 208 help_text="Match created events with this action type. When left empty, all action types will be matched.", 209 null=True, 210 ), 211 ), 212 ]
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.
replaces =
[('authentik_policies_event_matcher', '0019_alter_eventmatcherpolicy_app'), ('authentik_policies_event_matcher', '0020_eventmatcherpolicy_authentik_p_policy__e605cf_idx'), ('authentik_policies_event_matcher', '0021_alter_eventmatcherpolicy_app'), ('authentik_policies_event_matcher', '0022_eventmatcherpolicy_model'), ('authentik_policies_event_matcher', '0023_alter_eventmatcherpolicy_action_and_more'), ('authentik_policies_event_matcher', '0024_alter_eventmatcherpolicy_action'), ('authentik_policies_event_matcher', '0025_alter_eventmatcherpolicy_action'), ('authentik_policies_event_matcher', '0026_alter_eventmatcherpolicy_action'), ('authentik_policies_event_matcher', '0027_eventmatcherpolicy_query'), ('authentik_policies_event_matcher', '0028_alter_eventmatcherpolicy_action')]
dependencies =
[('authentik_policies_event_matcher', '0001_squashed_0018_alter_eventmatcherpolicy_action')]
operations =
[<AlterField model_name='eventmatcherpolicy', name='app', field=<django.db.models.fields.TextField>>, <AddIndex model_name='eventmatcherpolicy', index=<Index: fields=['policy_ptr_id'] name='authentik_p_policy__e605cf_idx'>>, <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>>, <AddField model_name='eventmatcherpolicy', name='model', field=<django.db.models.fields.TextField>>, <RunPython code=<function replace_defaults>>, <AddField model_name='eventmatcherpolicy', name='query', field=<django.db.models.fields.TextField>>, <AlterField model_name='eventmatcherpolicy', name='action', field=<django.db.models.fields.TextField>>]