authentik.flows.migrations.0012_auto_20200908_1542_squashed_0017_auto_20210329_1334
1# Generated by Django 3.2.8 on 2021-10-10 16:08 2 3import django.db.models.deletion 4from django.apps.registry import Apps 5from django.db import migrations, models 6from django.db.backends.base.schema import BaseDatabaseSchemaEditor 7 8import authentik.lib.models 9from authentik.flows.models import FlowDesignation 10 11 12def update_flow_designation(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 13 Flow = apps.get_model("authentik_flows", "Flow") 14 db_alias = schema_editor.connection.alias 15 16 for flow in Flow.objects.using(db_alias).all(): 17 if flow.designation == "stage_setup": 18 flow.designation = FlowDesignation.STAGE_CONFIGURATION 19 flow.save() 20 21 22class Migration(migrations.Migration): 23 replaces = [ 24 ("authentik_flows", "0012_auto_20200908_1542"), 25 ("authentik_flows", "0013_auto_20200924_1605"), 26 ("authentik_flows", "0014_auto_20200925_2332"), 27 ("authentik_flows", "0015_flowstagebinding_evaluate_on_plan"), 28 ("authentik_flows", "0016_auto_20201202_1307"), 29 ("authentik_flows", "0017_auto_20210329_1334"), 30 ] 31 32 dependencies = [ 33 ("authentik_flows", "0011_flow_title"), 34 ] 35 36 operations = [ 37 migrations.AlterField( 38 model_name="flowstagebinding", 39 name="stage", 40 field=authentik.lib.models.InheritanceForeignKey( 41 on_delete=django.db.models.deletion.CASCADE, to="authentik_flows.stage" 42 ), 43 ), 44 migrations.AlterField( 45 model_name="stage", 46 name="name", 47 field=models.TextField(unique=True), 48 ), 49 migrations.AlterField( 50 model_name="flow", 51 name="designation", 52 field=models.CharField( 53 choices=[ 54 ("authentication", "Authentication"), 55 ("authorization", "Authorization"), 56 ("invalidation", "Invalidation"), 57 ("enrollment", "Enrollment"), 58 ("unenrollment", "Unrenollment"), 59 ("recovery", "Recovery"), 60 ("stage_configuration", "Stage Configuration"), 61 ], 62 max_length=100, 63 ), 64 ), 65 migrations.RunPython( 66 code=update_flow_designation, 67 ), 68 migrations.AlterModelOptions( 69 name="flowstagebinding", 70 options={ 71 "ordering": ["target", "order"], 72 "verbose_name": "Flow Stage Binding", 73 "verbose_name_plural": "Flow Stage Bindings", 74 }, 75 ), 76 migrations.AlterField( 77 model_name="flowstagebinding", 78 name="re_evaluate_policies", 79 field=models.BooleanField( 80 default=False, 81 help_text=( 82 "When this option is enabled, the planner will re-evaluate policies bound to" 83 " this binding." 84 ), 85 ), 86 ), 87 migrations.AlterField( 88 model_name="flowstagebinding", 89 name="re_evaluate_policies", 90 field=models.BooleanField( 91 default=False, 92 help_text="Evaluate policies when the Stage is presented to the user.", 93 ), 94 ), 95 migrations.AddField( 96 model_name="flowstagebinding", 97 name="evaluate_on_plan", 98 field=models.BooleanField( 99 default=True, 100 help_text=( 101 "Evaluate policies during the Flow planning process. Disable this for" 102 " input-based policies." 103 ), 104 ), 105 ), 106 migrations.AddField( 107 model_name="flow", 108 name="background", 109 field=models.FileField( 110 blank=True, 111 default="../static/dist/assets/images/flow_background.jpg", 112 help_text="Background shown during execution", 113 upload_to="flow-backgrounds/", 114 ), 115 ), 116 migrations.AlterField( 117 model_name="flow", 118 name="designation", 119 field=models.CharField( 120 choices=[ 121 ("authentication", "Authentication"), 122 ("authorization", "Authorization"), 123 ("invalidation", "Invalidation"), 124 ("enrollment", "Enrollment"), 125 ("unenrollment", "Unrenollment"), 126 ("recovery", "Recovery"), 127 ("stage_configuration", "Stage Configuration"), 128 ], 129 help_text=( 130 "Decides what this Flow is used for. For example, the Authentication flow is" 131 " redirect to when an un-authenticated user visits authentik." 132 ), 133 max_length=100, 134 ), 135 ), 136 migrations.AlterField( 137 model_name="flow", 138 name="slug", 139 field=models.SlugField(help_text="Visible in the URL.", unique=True), 140 ), 141 migrations.AlterField( 142 model_name="flow", 143 name="title", 144 field=models.TextField(help_text="Shown as the Title in Flow pages."), 145 ), 146 migrations.AlterModelOptions( 147 name="flow", 148 options={ 149 "permissions": [ 150 ("export_flow", "Can export a Flow"), 151 ("view_flow_cache", "View Flow's cache metrics"), 152 ("clear_flow_cache", "Clear Flow's cache metrics"), 153 ], 154 "verbose_name": "Flow", 155 "verbose_name_plural": "Flows", 156 }, 157 ), 158 ]
def
update_flow_designation( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
13def update_flow_designation(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 14 Flow = apps.get_model("authentik_flows", "Flow") 15 db_alias = schema_editor.connection.alias 16 17 for flow in Flow.objects.using(db_alias).all(): 18 if flow.designation == "stage_setup": 19 flow.designation = FlowDesignation.STAGE_CONFIGURATION 20 flow.save()
class
Migration(django.db.migrations.migration.Migration):
23class Migration(migrations.Migration): 24 replaces = [ 25 ("authentik_flows", "0012_auto_20200908_1542"), 26 ("authentik_flows", "0013_auto_20200924_1605"), 27 ("authentik_flows", "0014_auto_20200925_2332"), 28 ("authentik_flows", "0015_flowstagebinding_evaluate_on_plan"), 29 ("authentik_flows", "0016_auto_20201202_1307"), 30 ("authentik_flows", "0017_auto_20210329_1334"), 31 ] 32 33 dependencies = [ 34 ("authentik_flows", "0011_flow_title"), 35 ] 36 37 operations = [ 38 migrations.AlterField( 39 model_name="flowstagebinding", 40 name="stage", 41 field=authentik.lib.models.InheritanceForeignKey( 42 on_delete=django.db.models.deletion.CASCADE, to="authentik_flows.stage" 43 ), 44 ), 45 migrations.AlterField( 46 model_name="stage", 47 name="name", 48 field=models.TextField(unique=True), 49 ), 50 migrations.AlterField( 51 model_name="flow", 52 name="designation", 53 field=models.CharField( 54 choices=[ 55 ("authentication", "Authentication"), 56 ("authorization", "Authorization"), 57 ("invalidation", "Invalidation"), 58 ("enrollment", "Enrollment"), 59 ("unenrollment", "Unrenollment"), 60 ("recovery", "Recovery"), 61 ("stage_configuration", "Stage Configuration"), 62 ], 63 max_length=100, 64 ), 65 ), 66 migrations.RunPython( 67 code=update_flow_designation, 68 ), 69 migrations.AlterModelOptions( 70 name="flowstagebinding", 71 options={ 72 "ordering": ["target", "order"], 73 "verbose_name": "Flow Stage Binding", 74 "verbose_name_plural": "Flow Stage Bindings", 75 }, 76 ), 77 migrations.AlterField( 78 model_name="flowstagebinding", 79 name="re_evaluate_policies", 80 field=models.BooleanField( 81 default=False, 82 help_text=( 83 "When this option is enabled, the planner will re-evaluate policies bound to" 84 " this binding." 85 ), 86 ), 87 ), 88 migrations.AlterField( 89 model_name="flowstagebinding", 90 name="re_evaluate_policies", 91 field=models.BooleanField( 92 default=False, 93 help_text="Evaluate policies when the Stage is presented to the user.", 94 ), 95 ), 96 migrations.AddField( 97 model_name="flowstagebinding", 98 name="evaluate_on_plan", 99 field=models.BooleanField( 100 default=True, 101 help_text=( 102 "Evaluate policies during the Flow planning process. Disable this for" 103 " input-based policies." 104 ), 105 ), 106 ), 107 migrations.AddField( 108 model_name="flow", 109 name="background", 110 field=models.FileField( 111 blank=True, 112 default="../static/dist/assets/images/flow_background.jpg", 113 help_text="Background shown during execution", 114 upload_to="flow-backgrounds/", 115 ), 116 ), 117 migrations.AlterField( 118 model_name="flow", 119 name="designation", 120 field=models.CharField( 121 choices=[ 122 ("authentication", "Authentication"), 123 ("authorization", "Authorization"), 124 ("invalidation", "Invalidation"), 125 ("enrollment", "Enrollment"), 126 ("unenrollment", "Unrenollment"), 127 ("recovery", "Recovery"), 128 ("stage_configuration", "Stage Configuration"), 129 ], 130 help_text=( 131 "Decides what this Flow is used for. For example, the Authentication flow is" 132 " redirect to when an un-authenticated user visits authentik." 133 ), 134 max_length=100, 135 ), 136 ), 137 migrations.AlterField( 138 model_name="flow", 139 name="slug", 140 field=models.SlugField(help_text="Visible in the URL.", unique=True), 141 ), 142 migrations.AlterField( 143 model_name="flow", 144 name="title", 145 field=models.TextField(help_text="Shown as the Title in Flow pages."), 146 ), 147 migrations.AlterModelOptions( 148 name="flow", 149 options={ 150 "permissions": [ 151 ("export_flow", "Can export a Flow"), 152 ("view_flow_cache", "View Flow's cache metrics"), 153 ("clear_flow_cache", "Clear Flow's cache metrics"), 154 ], 155 "verbose_name": "Flow", 156 "verbose_name_plural": "Flows", 157 }, 158 ), 159 ]
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.
replaces =
[('authentik_flows', '0012_auto_20200908_1542'), ('authentik_flows', '0013_auto_20200924_1605'), ('authentik_flows', '0014_auto_20200925_2332'), ('authentik_flows', '0015_flowstagebinding_evaluate_on_plan'), ('authentik_flows', '0016_auto_20201202_1307'), ('authentik_flows', '0017_auto_20210329_1334')]
operations =
[<AlterField model_name='flowstagebinding', name='stage', field=<authentik.lib.models.InheritanceForeignKey>>, <AlterField model_name='stage', name='name', field=<django.db.models.fields.TextField>>, <AlterField model_name='flow', name='designation', field=<django.db.models.fields.CharField>>, <RunPython code=<function update_flow_designation>>, <AlterModelOptions name='flowstagebinding', options={'ordering': ['target', 'order'], 'verbose_name': 'Flow Stage Binding', 'verbose_name_plural': 'Flow Stage Bindings'}>, <AlterField model_name='flowstagebinding', name='re_evaluate_policies', field=<django.db.models.fields.BooleanField>>, <AlterField model_name='flowstagebinding', name='re_evaluate_policies', field=<django.db.models.fields.BooleanField>>, <AddField model_name='flowstagebinding', name='evaluate_on_plan', field=<django.db.models.fields.BooleanField>>, <AddField model_name='flow', name='background', field=<django.db.models.fields.files.FileField>>, <AlterField model_name='flow', name='designation', field=<django.db.models.fields.CharField>>, <AlterField model_name='flow', name='slug', field=<django.db.models.fields.SlugField>>, <AlterField model_name='flow', name='title', field=<django.db.models.fields.TextField>>, <AlterModelOptions name='flow', options={'permissions': [('export_flow', 'Can export a Flow'), ('view_flow_cache', "View Flow's cache metrics"), ('clear_flow_cache', "Clear Flow's cache metrics")], 'verbose_name': 'Flow', 'verbose_name_plural': 'Flows'}>]