authentik.sources.saml.migrations.0019_migrate_usersamlsourceconnection_identifier

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

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_saml', '0018_alter_samlsource_slo_url_alter_samlsource_sso_url'), ('authentik_core', '0044_usersourceconnection_new_identifier')]
operations = [<RunPython code=<function migrate_identifier>, reverse_code=<function RunPython.noop>>, <RemoveField model_name='usersamlsourceconnection', name='identifier'>]