authentik.sources.plex.migrations.0005_migrate_userplexsourceconnection_identifier

 1from django.db import migrations
 2
 3
 4def migrate_identifier(apps, schema_editor):
 5    db_alias = schema_editor.connection.alias
 6    UserPlexSourceConnection = apps.get_model("authentik_sources_plex", "UserPlexSourceConnection")
 7
 8    for connection in UserPlexSourceConnection.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        (
17            "authentik_sources_plex",
18            "0004_groupplexsourceconnection_plexsourcepropertymapping_and_more",
19        ),
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="userplexsourceconnection",
27            name="identifier",
28        ),
29    ]
def migrate_identifier(apps, schema_editor):
 5def migrate_identifier(apps, schema_editor):
 6    db_alias = schema_editor.connection.alias
 7    UserPlexSourceConnection = apps.get_model("authentik_sources_plex", "UserPlexSourceConnection")
 8
 9    for connection in UserPlexSourceConnection.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        (
18            "authentik_sources_plex",
19            "0004_groupplexsourceconnection_plexsourcepropertymapping_and_more",
20        ),
21        ("authentik_core", "0044_usersourceconnection_new_identifier"),
22    ]
23
24    operations = [
25        migrations.RunPython(code=migrate_identifier, reverse_code=migrations.RunPython.noop),
26        migrations.RemoveField(
27            model_name="userplexsourceconnection",
28            name="identifier",
29        ),
30    ]

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_plex', '0004_groupplexsourceconnection_plexsourcepropertymapping_and_more'), ('authentik_core', '0044_usersourceconnection_new_identifier')]
operations = [<RunPython code=<function migrate_identifier>, reverse_code=<function RunPython.noop>>, <RemoveField model_name='userplexsourceconnection', name='identifier'>]