authentik.enterprise.lifecycle.migrations.0006_userexpirationrule_and_offboarding_rule

  1# Generated by Django 5.2.17 on 2026-09-15 15:13
  2
  3import authentik.enterprise.lifecycle.expiration.models
  4import authentik.lib.models
  5import authentik.lib.utils.time
  6import django.contrib.postgres.fields
  7import django.db.models.deletion
  8import uuid
  9from django.conf import settings
 10from django.db import migrations, models
 11
 12
 13class Migration(migrations.Migration):
 14
 15    dependencies = [
 16        ("authentik_core", "0064_user_authentik_c_usernam_2f0e4b_idx"),
 17        ("authentik_events", "0020_alter_event_action"),
 18        ("authentik_lifecycle", "0005_useroffboarding"),
 19        ("authentik_policies", "0012_alter_policybinding_managers_policybinding_expires_and_more"),
 20        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
 21    ]
 22
 23    operations = [
 24        migrations.CreateModel(
 25            name="UserExpirationRuleNotificationTransport",
 26            fields=[
 27                (
 28                    "id",
 29                    models.AutoField(
 30                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
 31                    ),
 32                ),
 33            ],
 34            options={
 35                "verbose_name": "User Expiration Rule Notification Transport",
 36                "verbose_name_plural": "User Expiration Rule Notification Transports",
 37                "db_table": "authentik_lifecycle_userexpirationrule_notification_transports",
 38            },
 39            bases=(models.Model, authentik.lib.models.InternallyManagedMixin),
 40        ),
 41        migrations.CreateModel(
 42            name="UserExpirationRule",
 43            fields=[
 44                (
 45                    "policybindingmodel_ptr",
 46                    models.OneToOneField(
 47                        auto_created=True,
 48                        on_delete=django.db.models.deletion.CASCADE,
 49                        parent_link=True,
 50                        to="authentik_policies.policybindingmodel",
 51                    ),
 52                ),
 53                ("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
 54                ("name", models.TextField(unique=True)),
 55                ("enabled", models.BooleanField(default=False)),
 56                (
 57                    "activity_basis",
 58                    models.TextField(
 59                        choices=[
 60                            ("last_login", "Last login"),
 61                            ("successful_events", "Last activity"),
 62                        ],
 63                        default="successful_events",
 64                        help_text="Measure inactivity from the last login or successful user activity.",
 65                    ),
 66                ),
 67                (
 68                    "user_types",
 69                    django.contrib.postgres.fields.ArrayField(
 70                        base_field=models.TextField(
 71                            choices=[
 72                                ("internal", "Internal"),
 73                                ("external", "External"),
 74                                ("service_account", "Service Account"),
 75                                ("internal_service_account", "Internal Service Account"),
 76                            ]
 77                        ),
 78                        blank=True,
 79                        default=authentik.enterprise.lifecycle.expiration.models.default_user_types,
 80                        help_text="Only expire users of these types. Service accounts are excluded by default.",
 81                        size=None,
 82                    ),
 83                ),
 84                (
 85                    "inactivity_duration",
 86                    models.TextField(
 87                        default="days=90",
 88                        help_text="How long a user may be inactive before they are expired.",
 89                        validators=[authentik.lib.utils.time.timedelta_string_validator],
 90                    ),
 91                ),
 92                (
 93                    "action",
 94                    models.TextField(
 95                        choices=[("deactivate", "Deactivate"), ("delete", "Delete")],
 96                        default="deactivate",
 97                    ),
 98                ),
 99                ("revoke_sessions", models.BooleanField(default=True)),
100                ("revoke_tokens", models.BooleanField(default=True)),
101                (
102                    "warn_before",
103                    models.TextField(
104                        blank=True,
105                        default=None,
106                        help_text="Schedule the offboarding and notify the user this long before they expire. Leave empty to expire users without warning.",
107                        null=True,
108                        validators=[authentik.lib.utils.time.timedelta_string_validator],
109                    ),
110                ),
111                (
112                    "exclude_superusers",
113                    models.BooleanField(
114                        default=True, help_text="Never expire members of a superuser group."
115                    ),
116                ),
117                (
118                    "group",
119                    models.ForeignKey(
120                        blank=True,
121                        default=None,
122                        help_text="Only expire members of this group (including descendant groups). Leave empty to apply to every user.",
123                        null=True,
124                        on_delete=django.db.models.deletion.CASCADE,
125                        to="authentik_core.group",
126                    ),
127                ),
128            ],
129            options={
130                "verbose_name": "User Expiration Rule",
131                "verbose_name_plural": "User Expiration Rules",
132            },
133            bases=("authentik_policies.policybindingmodel", models.Model),
134        ),
135        migrations.AddField(
136            model_name="useroffboarding",
137            name="rule",
138            field=models.ForeignKey(
139                default=None,
140                null=True,
141                on_delete=django.db.models.deletion.SET_NULL,
142                related_name="offboardings",
143                to="authentik_lifecycle.userexpirationrule",
144            ),
145        ),
146        migrations.AddField(
147            model_name="useroffboarding",
148            name="generated",
149            field=models.BooleanField(db_default=False, default=False),
150        ),
151        migrations.AddIndex(
152            model_name="useroffboarding",
153            index=models.Index(
154                condition=models.Q(("generated", True)),
155                fields=["user", "executed_at"],
156                name="generated_offboarding_idx",
157            ),
158        ),
159        migrations.AddField(
160            model_name="userexpirationrulenotificationtransport",
161            name="notification_transport",
162            field=models.ForeignKey(
163                db_column="notificationtransport_id",
164                on_delete=django.db.models.deletion.CASCADE,
165                to="authentik_events.notificationtransport",
166            ),
167        ),
168        migrations.AddField(
169            model_name="userexpirationrulenotificationtransport",
170            name="user_expiration_rule",
171            field=models.ForeignKey(
172                db_column="userexpirationrule_id",
173                on_delete=django.db.models.deletion.CASCADE,
174                to="authentik_lifecycle.userexpirationrule",
175            ),
176        ),
177        migrations.AddField(
178            model_name="userexpirationrule",
179            name="notification_transports",
180            field=models.ManyToManyField(
181                blank=True,
182                help_text="Select which transports should be used to warn the user. If none are selected, the notification will only be shown in the authentik UI.",
183                through="authentik_lifecycle.UserExpirationRuleNotificationTransport",
184                to="authentik_events.notificationtransport",
185            ),
186        ),
187        migrations.AlterUniqueTogether(
188            name="userexpirationrulenotificationtransport",
189            unique_together={("user_expiration_rule", "notification_transport")},
190        ),
191    ]
class Migration(django.db.migrations.migration.Migration):
 14class Migration(migrations.Migration):
 15
 16    dependencies = [
 17        ("authentik_core", "0064_user_authentik_c_usernam_2f0e4b_idx"),
 18        ("authentik_events", "0020_alter_event_action"),
 19        ("authentik_lifecycle", "0005_useroffboarding"),
 20        ("authentik_policies", "0012_alter_policybinding_managers_policybinding_expires_and_more"),
 21        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
 22    ]
 23
 24    operations = [
 25        migrations.CreateModel(
 26            name="UserExpirationRuleNotificationTransport",
 27            fields=[
 28                (
 29                    "id",
 30                    models.AutoField(
 31                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
 32                    ),
 33                ),
 34            ],
 35            options={
 36                "verbose_name": "User Expiration Rule Notification Transport",
 37                "verbose_name_plural": "User Expiration Rule Notification Transports",
 38                "db_table": "authentik_lifecycle_userexpirationrule_notification_transports",
 39            },
 40            bases=(models.Model, authentik.lib.models.InternallyManagedMixin),
 41        ),
 42        migrations.CreateModel(
 43            name="UserExpirationRule",
 44            fields=[
 45                (
 46                    "policybindingmodel_ptr",
 47                    models.OneToOneField(
 48                        auto_created=True,
 49                        on_delete=django.db.models.deletion.CASCADE,
 50                        parent_link=True,
 51                        to="authentik_policies.policybindingmodel",
 52                    ),
 53                ),
 54                ("id", models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
 55                ("name", models.TextField(unique=True)),
 56                ("enabled", models.BooleanField(default=False)),
 57                (
 58                    "activity_basis",
 59                    models.TextField(
 60                        choices=[
 61                            ("last_login", "Last login"),
 62                            ("successful_events", "Last activity"),
 63                        ],
 64                        default="successful_events",
 65                        help_text="Measure inactivity from the last login or successful user activity.",
 66                    ),
 67                ),
 68                (
 69                    "user_types",
 70                    django.contrib.postgres.fields.ArrayField(
 71                        base_field=models.TextField(
 72                            choices=[
 73                                ("internal", "Internal"),
 74                                ("external", "External"),
 75                                ("service_account", "Service Account"),
 76                                ("internal_service_account", "Internal Service Account"),
 77                            ]
 78                        ),
 79                        blank=True,
 80                        default=authentik.enterprise.lifecycle.expiration.models.default_user_types,
 81                        help_text="Only expire users of these types. Service accounts are excluded by default.",
 82                        size=None,
 83                    ),
 84                ),
 85                (
 86                    "inactivity_duration",
 87                    models.TextField(
 88                        default="days=90",
 89                        help_text="How long a user may be inactive before they are expired.",
 90                        validators=[authentik.lib.utils.time.timedelta_string_validator],
 91                    ),
 92                ),
 93                (
 94                    "action",
 95                    models.TextField(
 96                        choices=[("deactivate", "Deactivate"), ("delete", "Delete")],
 97                        default="deactivate",
 98                    ),
 99                ),
100                ("revoke_sessions", models.BooleanField(default=True)),
101                ("revoke_tokens", models.BooleanField(default=True)),
102                (
103                    "warn_before",
104                    models.TextField(
105                        blank=True,
106                        default=None,
107                        help_text="Schedule the offboarding and notify the user this long before they expire. Leave empty to expire users without warning.",
108                        null=True,
109                        validators=[authentik.lib.utils.time.timedelta_string_validator],
110                    ),
111                ),
112                (
113                    "exclude_superusers",
114                    models.BooleanField(
115                        default=True, help_text="Never expire members of a superuser group."
116                    ),
117                ),
118                (
119                    "group",
120                    models.ForeignKey(
121                        blank=True,
122                        default=None,
123                        help_text="Only expire members of this group (including descendant groups). Leave empty to apply to every user.",
124                        null=True,
125                        on_delete=django.db.models.deletion.CASCADE,
126                        to="authentik_core.group",
127                    ),
128                ),
129            ],
130            options={
131                "verbose_name": "User Expiration Rule",
132                "verbose_name_plural": "User Expiration Rules",
133            },
134            bases=("authentik_policies.policybindingmodel", models.Model),
135        ),
136        migrations.AddField(
137            model_name="useroffboarding",
138            name="rule",
139            field=models.ForeignKey(
140                default=None,
141                null=True,
142                on_delete=django.db.models.deletion.SET_NULL,
143                related_name="offboardings",
144                to="authentik_lifecycle.userexpirationrule",
145            ),
146        ),
147        migrations.AddField(
148            model_name="useroffboarding",
149            name="generated",
150            field=models.BooleanField(db_default=False, default=False),
151        ),
152        migrations.AddIndex(
153            model_name="useroffboarding",
154            index=models.Index(
155                condition=models.Q(("generated", True)),
156                fields=["user", "executed_at"],
157                name="generated_offboarding_idx",
158            ),
159        ),
160        migrations.AddField(
161            model_name="userexpirationrulenotificationtransport",
162            name="notification_transport",
163            field=models.ForeignKey(
164                db_column="notificationtransport_id",
165                on_delete=django.db.models.deletion.CASCADE,
166                to="authentik_events.notificationtransport",
167            ),
168        ),
169        migrations.AddField(
170            model_name="userexpirationrulenotificationtransport",
171            name="user_expiration_rule",
172            field=models.ForeignKey(
173                db_column="userexpirationrule_id",
174                on_delete=django.db.models.deletion.CASCADE,
175                to="authentik_lifecycle.userexpirationrule",
176            ),
177        ),
178        migrations.AddField(
179            model_name="userexpirationrule",
180            name="notification_transports",
181            field=models.ManyToManyField(
182                blank=True,
183                help_text="Select which transports should be used to warn the user. If none are selected, the notification will only be shown in the authentik UI.",
184                through="authentik_lifecycle.UserExpirationRuleNotificationTransport",
185                to="authentik_events.notificationtransport",
186            ),
187        ),
188        migrations.AlterUniqueTogether(
189            name="userexpirationrulenotificationtransport",
190            unique_together={("user_expiration_rule", "notification_transport")},
191        ),
192    ]

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', '0064_user_authentik_c_usernam_2f0e4b_idx'), ('authentik_events', '0020_alter_event_action'), ('authentik_lifecycle', '0005_useroffboarding'), ('authentik_policies', '0012_alter_policybinding_managers_policybinding_expires_and_more'), ('authentik_core', '__first__')]
operations = [<CreateModel name='UserExpirationRuleNotificationTransport', fields=[('id', <django.db.models.fields.AutoField>)], options={'verbose_name': 'User Expiration Rule Notification Transport', 'verbose_name_plural': 'User Expiration Rule Notification Transports', 'db_table': 'authentik_lifecycle_userexpirationrule_notification_transports'}, bases=(<class 'django.db.models.base.Model'>, <class 'authentik.lib.models.InternallyManagedMixin'>)>, <CreateModel name='UserExpirationRule', fields=[('policybindingmodel_ptr', <django.db.models.fields.related.OneToOneField>), ('id', <django.db.models.fields.UUIDField>), ('name', <django.db.models.fields.TextField>), ('enabled', <django.db.models.fields.BooleanField>), ('activity_basis', <django.db.models.fields.TextField>), ('user_types', <django.contrib.postgres.fields.array.ArrayField>), ('inactivity_duration', <django.db.models.fields.TextField>), ('action', <django.db.models.fields.TextField>), ('revoke_sessions', <django.db.models.fields.BooleanField>), ('revoke_tokens', <django.db.models.fields.BooleanField>), ('warn_before', <django.db.models.fields.TextField>), ('exclude_superusers', <django.db.models.fields.BooleanField>), ('group', <django.db.models.fields.related.ForeignKey>)], options={'verbose_name': 'User Expiration Rule', 'verbose_name_plural': 'User Expiration Rules'}, bases=('authentik_policies.policybindingmodel', <class 'django.db.models.base.Model'>)>, <AddField model_name='useroffboarding', name='rule', field=<django.db.models.fields.related.ForeignKey>>, <AddField model_name='useroffboarding', name='generated', field=<django.db.models.fields.BooleanField>>, <AddIndex model_name='useroffboarding', index=<Index: fields=['user', 'executed_at'] name='generated_offboarding_idx' condition=(AND: ('generated', True))>>, <AddField model_name='userexpirationrulenotificationtransport', name='notification_transport', field=<django.db.models.fields.related.ForeignKey>>, <AddField model_name='userexpirationrulenotificationtransport', name='user_expiration_rule', field=<django.db.models.fields.related.ForeignKey>>, <AddField model_name='userexpirationrule', name='notification_transports', field=<django.db.models.fields.related.ManyToManyField>>, <AlterUniqueTogether name='userexpirationrulenotificationtransport', unique_together={('user_expiration_rule', 'notification_transport')}>]