authentik.core.migrations.0040_provider_invalidation_flow
1# Generated by Django 5.0.9 on 2024-10-02 11:35 2 3import django.db.models.deletion 4from django.db import migrations, models 5 6from django.apps.registry import Apps 7from django.db import migrations, models 8from django.db.backends.base.schema import BaseDatabaseSchemaEditor 9 10 11def migrate_invalidation_flow_default(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 12 from authentik.flows.models import FlowDesignation, FlowAuthenticationRequirement 13 14 db_alias = schema_editor.connection.alias 15 16 Flow = apps.get_model("authentik_flows", "Flow") 17 Provider = apps.get_model("authentik_core", "Provider") 18 19 # So this flow is managed via a blueprint, bue we're in a migration so we don't want to rely on that 20 # since the blueprint is just an empty flow we can just create it here 21 # and let it be managed by the blueprint later 22 flow, _ = Flow.objects.using(db_alias).update_or_create( 23 slug="default-provider-invalidation-flow", 24 defaults={ 25 "name": "Logged out of application", 26 "title": "You've logged out of %(app)s.", 27 "authentication": FlowAuthenticationRequirement.NONE, 28 "designation": FlowDesignation.INVALIDATION, 29 }, 30 ) 31 Provider.objects.using(db_alias).filter(invalidation_flow=None).update(invalidation_flow=flow) 32 33 34class Migration(migrations.Migration): 35 36 dependencies = [ 37 ("authentik_core", "0039_source_group_matching_mode_alter_group_name_and_more"), 38 ("authentik_flows", "0027_auto_20231028_1424"), 39 ] 40 41 operations = [ 42 migrations.AddField( 43 model_name="provider", 44 name="invalidation_flow", 45 field=models.ForeignKey( 46 default=None, 47 help_text="Flow used ending the session from a provider.", 48 null=True, 49 on_delete=django.db.models.deletion.SET_DEFAULT, 50 related_name="provider_invalidation", 51 to="authentik_flows.flow", 52 ), 53 ), 54 migrations.RunPython(migrate_invalidation_flow_default), 55 ]
def
migrate_invalidation_flow_default( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
12def migrate_invalidation_flow_default(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 13 from authentik.flows.models import FlowDesignation, FlowAuthenticationRequirement 14 15 db_alias = schema_editor.connection.alias 16 17 Flow = apps.get_model("authentik_flows", "Flow") 18 Provider = apps.get_model("authentik_core", "Provider") 19 20 # So this flow is managed via a blueprint, bue we're in a migration so we don't want to rely on that 21 # since the blueprint is just an empty flow we can just create it here 22 # and let it be managed by the blueprint later 23 flow, _ = Flow.objects.using(db_alias).update_or_create( 24 slug="default-provider-invalidation-flow", 25 defaults={ 26 "name": "Logged out of application", 27 "title": "You've logged out of %(app)s.", 28 "authentication": FlowAuthenticationRequirement.NONE, 29 "designation": FlowDesignation.INVALIDATION, 30 }, 31 ) 32 Provider.objects.using(db_alias).filter(invalidation_flow=None).update(invalidation_flow=flow)
class
Migration(django.db.migrations.migration.Migration):
35class Migration(migrations.Migration): 36 37 dependencies = [ 38 ("authentik_core", "0039_source_group_matching_mode_alter_group_name_and_more"), 39 ("authentik_flows", "0027_auto_20231028_1424"), 40 ] 41 42 operations = [ 43 migrations.AddField( 44 model_name="provider", 45 name="invalidation_flow", 46 field=models.ForeignKey( 47 default=None, 48 help_text="Flow used ending the session from a provider.", 49 null=True, 50 on_delete=django.db.models.deletion.SET_DEFAULT, 51 related_name="provider_invalidation", 52 to="authentik_flows.flow", 53 ), 54 ), 55 migrations.RunPython(migrate_invalidation_flow_default), 56 ]
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.