authentik.stages.authenticator_totp.migrations.0008_initial

 1from django.conf import settings
 2from django.db import migrations, models
 3
 4import authentik.stages.authenticator_totp.models
 5
 6
 7class Migration(migrations.Migration):
 8    dependencies = [
 9        ("authentik_stages_authenticator_totp", "0007_authenticatortotpstage_friendly_name"),
10        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
11    ]
12
13    operations = [
14        migrations.CreateModel(
15            name="TOTPDevice",
16            fields=[
17                (
18                    "id",
19                    models.AutoField(
20                        verbose_name="ID", serialize=False, auto_created=True, primary_key=True
21                    ),
22                ),
23                (
24                    "name",
25                    models.CharField(
26                        help_text="The human-readable name of this device.", max_length=64
27                    ),
28                ),
29                (
30                    "confirmed",
31                    models.BooleanField(default=True, help_text="Is this device ready for use?"),
32                ),
33                (
34                    "key",
35                    models.CharField(
36                        default=authentik.stages.authenticator_totp.models.default_key,
37                        help_text="A hex-encoded secret key of up to 40 bytes.",
38                        max_length=80,
39                        validators=[authentik.stages.authenticator_totp.models.key_validator],
40                    ),
41                ),
42                (
43                    "step",
44                    models.PositiveSmallIntegerField(
45                        default=30, help_text="The time step in seconds."
46                    ),
47                ),
48                (
49                    "t0",
50                    models.BigIntegerField(
51                        default=0, help_text="The Unix time at which to begin counting steps."
52                    ),
53                ),
54                (
55                    "digits",
56                    models.PositiveSmallIntegerField(
57                        default=6,
58                        help_text="The number of digits to expect in a token.",
59                        choices=[(6, 6), (8, 8)],
60                    ),
61                ),
62                (
63                    "tolerance",
64                    models.PositiveSmallIntegerField(
65                        default=1,
66                        help_text="The number of time steps in the past or future to allow.",
67                    ),
68                ),
69                (
70                    "drift",
71                    models.SmallIntegerField(
72                        default=0,
73                        help_text="The number of time steps the prover is known to deviate from our clock.",
74                    ),
75                ),
76                (
77                    "last_t",
78                    models.BigIntegerField(
79                        default=-1,
80                        help_text="The t value of the latest verified token. The next token must be at a higher time step.",
81                    ),
82                ),
83                (
84                    "user",
85                    models.ForeignKey(
86                        help_text="The user that this device belongs to.",
87                        to=settings.AUTH_USER_MODEL,
88                        on_delete=models.CASCADE,
89                    ),
90                ),
91            ],
92            options={
93                "abstract": False,
94                "verbose_name": "TOTP device",
95            },
96            bases=(models.Model,),
97        ),
98    ]
class Migration(django.db.migrations.migration.Migration):
 8class Migration(migrations.Migration):
 9    dependencies = [
10        ("authentik_stages_authenticator_totp", "0007_authenticatortotpstage_friendly_name"),
11        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12    ]
13
14    operations = [
15        migrations.CreateModel(
16            name="TOTPDevice",
17            fields=[
18                (
19                    "id",
20                    models.AutoField(
21                        verbose_name="ID", serialize=False, auto_created=True, primary_key=True
22                    ),
23                ),
24                (
25                    "name",
26                    models.CharField(
27                        help_text="The human-readable name of this device.", max_length=64
28                    ),
29                ),
30                (
31                    "confirmed",
32                    models.BooleanField(default=True, help_text="Is this device ready for use?"),
33                ),
34                (
35                    "key",
36                    models.CharField(
37                        default=authentik.stages.authenticator_totp.models.default_key,
38                        help_text="A hex-encoded secret key of up to 40 bytes.",
39                        max_length=80,
40                        validators=[authentik.stages.authenticator_totp.models.key_validator],
41                    ),
42                ),
43                (
44                    "step",
45                    models.PositiveSmallIntegerField(
46                        default=30, help_text="The time step in seconds."
47                    ),
48                ),
49                (
50                    "t0",
51                    models.BigIntegerField(
52                        default=0, help_text="The Unix time at which to begin counting steps."
53                    ),
54                ),
55                (
56                    "digits",
57                    models.PositiveSmallIntegerField(
58                        default=6,
59                        help_text="The number of digits to expect in a token.",
60                        choices=[(6, 6), (8, 8)],
61                    ),
62                ),
63                (
64                    "tolerance",
65                    models.PositiveSmallIntegerField(
66                        default=1,
67                        help_text="The number of time steps in the past or future to allow.",
68                    ),
69                ),
70                (
71                    "drift",
72                    models.SmallIntegerField(
73                        default=0,
74                        help_text="The number of time steps the prover is known to deviate from our clock.",
75                    ),
76                ),
77                (
78                    "last_t",
79                    models.BigIntegerField(
80                        default=-1,
81                        help_text="The t value of the latest verified token. The next token must be at a higher time step.",
82                    ),
83                ),
84                (
85                    "user",
86                    models.ForeignKey(
87                        help_text="The user that this device belongs to.",
88                        to=settings.AUTH_USER_MODEL,
89                        on_delete=models.CASCADE,
90                    ),
91                ),
92            ],
93            options={
94                "abstract": False,
95                "verbose_name": "TOTP device",
96            },
97            bases=(models.Model,),
98        ),
99    ]

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_stages_authenticator_totp', '0007_authenticatortotpstage_friendly_name'), ('authentik_core', '__first__')]
operations = [<CreateModel name='TOTPDevice', fields=[('id', <django.db.models.fields.AutoField>), ('name', <django.db.models.fields.CharField>), ('confirmed', <django.db.models.fields.BooleanField>), ('key', <django.db.models.fields.CharField>), ('step', <django.db.models.fields.PositiveSmallIntegerField>), ('t0', <django.db.models.fields.BigIntegerField>), ('digits', <django.db.models.fields.PositiveSmallIntegerField>), ('tolerance', <django.db.models.fields.PositiveSmallIntegerField>), ('drift', <django.db.models.fields.SmallIntegerField>), ('last_t', <django.db.models.fields.BigIntegerField>), ('user', <django.db.models.fields.related.ForeignKey>)], options={'abstract': False, 'verbose_name': 'TOTP device'}, bases=(<class 'django.db.models.base.Model'>,)>]