authentik.core.migrations.0029_provider_backchannel_applications_and_more
1# Generated by Django 4.1.7 on 2023-04-30 17:56 2 3import django.db.models.deletion 4from django.apps.registry import Apps 5from django.db import DatabaseError, InternalError, ProgrammingError, migrations, models 6from django.db.backends.base.schema import BaseDatabaseSchemaEditor 7 8 9def backport_is_backchannel(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 10 db_alias = schema_editor.connection.alias 11 from authentik.providers.ldap.models import LDAPProvider 12 from authentik.providers.scim.models import SCIMProvider 13 14 for model in [LDAPProvider, SCIMProvider]: 15 try: 16 for obj in model.objects.using(db_alias).only("is_backchannel"): 17 obj.is_backchannel = True 18 obj.save() 19 except DatabaseError, InternalError, ProgrammingError: 20 # The model might not have been migrated yet/doesn't exist yet 21 # so we don't need to worry about backporting the data 22 pass 23 24 25class Migration(migrations.Migration): 26 dependencies = [ 27 ("authentik_core", "0028_provider_authentication_flow"), 28 ("authentik_providers_ldap", "0002_ldapprovider_bind_mode"), 29 ("authentik_providers_scim", "0006_rename_parent_group_scimprovider_filter_group"), 30 ] 31 32 operations = [ 33 migrations.AddField( 34 model_name="provider", 35 name="backchannel_application", 36 field=models.ForeignKey( 37 default=None, 38 help_text="Accessed from applications; optional backchannel providers for protocols like LDAP and SCIM.", 39 null=True, 40 on_delete=django.db.models.deletion.CASCADE, 41 related_name="backchannel_providers", 42 to="authentik_core.application", 43 ), 44 ), 45 migrations.AddField( 46 model_name="provider", 47 name="is_backchannel", 48 field=models.BooleanField(default=False), 49 ), 50 migrations.RunPython(backport_is_backchannel), 51 migrations.AlterField( 52 model_name="propertymapping", 53 name="managed", 54 field=models.TextField( 55 default=None, 56 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 57 null=True, 58 unique=True, 59 verbose_name="Managed by authentik", 60 ), 61 ), 62 migrations.AlterField( 63 model_name="source", 64 name="managed", 65 field=models.TextField( 66 default=None, 67 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 68 null=True, 69 unique=True, 70 verbose_name="Managed by authentik", 71 ), 72 ), 73 migrations.AlterField( 74 model_name="token", 75 name="managed", 76 field=models.TextField( 77 default=None, 78 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 79 null=True, 80 unique=True, 81 verbose_name="Managed by authentik", 82 ), 83 ), 84 ]
def
backport_is_backchannel( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
10def backport_is_backchannel(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 11 db_alias = schema_editor.connection.alias 12 from authentik.providers.ldap.models import LDAPProvider 13 from authentik.providers.scim.models import SCIMProvider 14 15 for model in [LDAPProvider, SCIMProvider]: 16 try: 17 for obj in model.objects.using(db_alias).only("is_backchannel"): 18 obj.is_backchannel = True 19 obj.save() 20 except DatabaseError, InternalError, ProgrammingError: 21 # The model might not have been migrated yet/doesn't exist yet 22 # so we don't need to worry about backporting the data 23 pass
class
Migration(django.db.migrations.migration.Migration):
26class Migration(migrations.Migration): 27 dependencies = [ 28 ("authentik_core", "0028_provider_authentication_flow"), 29 ("authentik_providers_ldap", "0002_ldapprovider_bind_mode"), 30 ("authentik_providers_scim", "0006_rename_parent_group_scimprovider_filter_group"), 31 ] 32 33 operations = [ 34 migrations.AddField( 35 model_name="provider", 36 name="backchannel_application", 37 field=models.ForeignKey( 38 default=None, 39 help_text="Accessed from applications; optional backchannel providers for protocols like LDAP and SCIM.", 40 null=True, 41 on_delete=django.db.models.deletion.CASCADE, 42 related_name="backchannel_providers", 43 to="authentik_core.application", 44 ), 45 ), 46 migrations.AddField( 47 model_name="provider", 48 name="is_backchannel", 49 field=models.BooleanField(default=False), 50 ), 51 migrations.RunPython(backport_is_backchannel), 52 migrations.AlterField( 53 model_name="propertymapping", 54 name="managed", 55 field=models.TextField( 56 default=None, 57 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 58 null=True, 59 unique=True, 60 verbose_name="Managed by authentik", 61 ), 62 ), 63 migrations.AlterField( 64 model_name="source", 65 name="managed", 66 field=models.TextField( 67 default=None, 68 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 69 null=True, 70 unique=True, 71 verbose_name="Managed by authentik", 72 ), 73 ), 74 migrations.AlterField( 75 model_name="token", 76 name="managed", 77 field=models.TextField( 78 default=None, 79 help_text="Objects that are managed by authentik. These objects are created and updated automatically. This flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.", 80 null=True, 81 unique=True, 82 verbose_name="Managed by authentik", 83 ), 84 ), 85 ]
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_core', '0028_provider_authentication_flow'), ('authentik_providers_ldap', '0002_ldapprovider_bind_mode'), ('authentik_providers_scim', '0006_rename_parent_group_scimprovider_filter_group')]
operations =
[<AddField model_name='provider', name='backchannel_application', field=<django.db.models.fields.related.ForeignKey>>, <AddField model_name='provider', name='is_backchannel', field=<django.db.models.fields.BooleanField>>, <RunPython <function backport_is_backchannel>>, <AlterField model_name='propertymapping', name='managed', field=<django.db.models.fields.TextField>>, <AlterField model_name='source', name='managed', field=<django.db.models.fields.TextField>>, <AlterField model_name='token', name='managed', field=<django.db.models.fields.TextField>>]