authentik.sources.kerberos.migrations.0003_migrate_userkerberossourceconnection_identifier

 1from django.db import migrations
 2
 3
 4def migrate_identifier(apps, schema_editor):
 5    db_alias = schema_editor.connection.alias
 6    UserKerberosSourceConnection = apps.get_model(
 7        "authentik_sources_kerberos", "UserKerberosSourceConnection"
 8    )
 9
10    for connection in UserKerberosSourceConnection.objects.using(db_alias).all():
11        connection.new_identifier = connection.identifier
12        connection.save(using=db_alias)
13
14
15class Migration(migrations.Migration):
16
17    dependencies = [
18        ("authentik_sources_kerberos", "0002_kerberossource_kadmin_type"),
19        ("authentik_core", "0044_usersourceconnection_new_identifier"),
20    ]
21
22    operations = [
23        migrations.RunPython(code=migrate_identifier, reverse_code=migrations.RunPython.noop),
24        migrations.RemoveField(
25            model_name="userkerberossourceconnection",
26            name="identifier",
27        ),
28    ]
def migrate_identifier(apps, schema_editor):
 5def migrate_identifier(apps, schema_editor):
 6    db_alias = schema_editor.connection.alias
 7    UserKerberosSourceConnection = apps.get_model(
 8        "authentik_sources_kerberos", "UserKerberosSourceConnection"
 9    )
10
11    for connection in UserKerberosSourceConnection.objects.using(db_alias).all():
12        connection.new_identifier = connection.identifier
13        connection.save(using=db_alias)
class Migration(django.db.migrations.migration.Migration):
16class Migration(migrations.Migration):
17
18    dependencies = [
19        ("authentik_sources_kerberos", "0002_kerberossource_kadmin_type"),
20        ("authentik_core", "0044_usersourceconnection_new_identifier"),
21    ]
22
23    operations = [
24        migrations.RunPython(code=migrate_identifier, reverse_code=migrations.RunPython.noop),
25        migrations.RemoveField(
26            model_name="userkerberossourceconnection",
27            name="identifier",
28        ),
29    ]

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_sources_kerberos', '0002_kerberossource_kadmin_type'), ('authentik_core', '0044_usersourceconnection_new_identifier')]
operations = [<RunPython code=<function migrate_identifier>, reverse_code=<function RunPython.noop>>, <RemoveField model_name='userkerberossourceconnection', name='identifier'>]