authentik.brands.migrations.0008_brand_branding_custom_css
1# Generated by Django 5.0.12 on 2025-02-22 01:51 2 3from pathlib import Path 4from django.db import migrations, models 5from django.apps.registry import Apps 6 7from django.db.backends.base.schema import BaseDatabaseSchemaEditor 8 9 10def migrate_custom_css(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 11 Brand = apps.get_model("authentik_brands", "brand") 12 13 db_alias = schema_editor.connection.alias 14 15 path = Path("/web/dist/custom.css") 16 if not path.exists(): 17 return 18 css = path.read_text() 19 Brand.objects.using(db_alias).all().update(branding_custom_css=css) 20 21 22class Migration(migrations.Migration): 23 24 dependencies = [ 25 ("authentik_brands", "0007_brand_default_application"), 26 ] 27 28 operations = [ 29 migrations.AddField( 30 model_name="brand", 31 name="branding_custom_css", 32 field=models.TextField(blank=True, default=""), 33 ), 34 migrations.RunPython(migrate_custom_css), 35 ]
def
migrate_custom_css( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
11def migrate_custom_css(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 12 Brand = apps.get_model("authentik_brands", "brand") 13 14 db_alias = schema_editor.connection.alias 15 16 path = Path("/web/dist/custom.css") 17 if not path.exists(): 18 return 19 css = path.read_text() 20 Brand.objects.using(db_alias).all().update(branding_custom_css=css)
class
Migration(django.db.migrations.migration.Migration):
23class Migration(migrations.Migration): 24 25 dependencies = [ 26 ("authentik_brands", "0007_brand_default_application"), 27 ] 28 29 operations = [ 30 migrations.AddField( 31 model_name="brand", 32 name="branding_custom_css", 33 field=models.TextField(blank=True, default=""), 34 ), 35 migrations.RunPython(migrate_custom_css), 36 ]
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.