authentik.sources.ldap.migrations.0010_ldapsource_user_membership_attribute
1# Generated by Django 5.1.9 on 2025-05-29 11:22 2 3from django.apps.registry import Apps 4from django.db import migrations, models 5from django.db.backends.base.schema import BaseDatabaseSchemaEditor 6 7 8def set_user_membership_attribute(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 9 LDAPSource = apps.get_model("authentik_sources_ldap", "LDAPSource") 10 db_alias = schema_editor.connection.alias 11 12 LDAPSource.objects.using(db_alias).filter(group_membership_field="memberUid").all().update( 13 user_membership_attribute="ldap_uniq" 14 ) 15 16 17class Migration(migrations.Migration): 18 dependencies = [ 19 ("authentik_sources_ldap", "0009_groupldapsourceconnection_validated_by_and_more"), 20 ] 21 22 operations = [ 23 migrations.AddField( 24 model_name="ldapsource", 25 name="user_membership_attribute", 26 field=models.TextField( 27 default="distinguishedName", 28 help_text="Attribute which matches the value of `group_membership_field`.", 29 ), 30 ), 31 migrations.RunPython(set_user_membership_attribute, migrations.RunPython.noop), 32 ]
def
set_user_membership_attribute( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
9def set_user_membership_attribute(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 10 LDAPSource = apps.get_model("authentik_sources_ldap", "LDAPSource") 11 db_alias = schema_editor.connection.alias 12 13 LDAPSource.objects.using(db_alias).filter(group_membership_field="memberUid").all().update( 14 user_membership_attribute="ldap_uniq" 15 )
class
Migration(django.db.migrations.migration.Migration):
18class Migration(migrations.Migration): 19 dependencies = [ 20 ("authentik_sources_ldap", "0009_groupldapsourceconnection_validated_by_and_more"), 21 ] 22 23 operations = [ 24 migrations.AddField( 25 model_name="ldapsource", 26 name="user_membership_attribute", 27 field=models.TextField( 28 default="distinguishedName", 29 help_text="Attribute which matches the value of `group_membership_field`.", 30 ), 31 ), 32 migrations.RunPython(set_user_membership_attribute, migrations.RunPython.noop), 33 ]
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.