diff --git a/authentik/core/migrations/0029_provider_backchannel_applications_and_more.py b/authentik/core/migrations/0029_provider_backchannel_applications_and_more.py index d6245df749..443d917c73 100644 --- a/authentik/core/migrations/0029_provider_backchannel_applications_and_more.py +++ b/authentik/core/migrations/0029_provider_backchannel_applications_and_more.py @@ -7,12 +7,13 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditor def backport_is_backchannel(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + db_alias = schema_editor.connection.alias from authentik.providers.ldap.models import LDAPProvider from authentik.providers.scim.models import SCIMProvider for model in [LDAPProvider, SCIMProvider]: try: - for obj in model.objects.only("is_backchannel"): + for obj in model.objects.using(db_alias).only("is_backchannel"): obj.is_backchannel = True obj.save() except (DatabaseError, InternalError, ProgrammingError): diff --git a/authentik/flows/migrations/0027_auto_20231028_1424.py b/authentik/flows/migrations/0027_auto_20231028_1424.py index 49894c669d..24d068d319 100644 --- a/authentik/flows/migrations/0027_auto_20231028_1424.py +++ b/authentik/flows/migrations/0027_auto_20231028_1424.py @@ -21,7 +21,7 @@ def set_oobe_flow_authentication(apps: Apps, schema_editor: BaseDatabaseSchemaEd pass if users.exists(): - Flow.objects.filter(slug="initial-setup").update(authentication="require_superuser") + Flow.objects.using(db_alias).filter(slug="initial-setup").update(authentication="require_superuser") class Migration(migrations.Migration): diff --git a/authentik/outposts/migrations/0001_squashed_0017_outpost_managed.py b/authentik/outposts/migrations/0001_squashed_0017_outpost_managed.py index 7bd9d4f42b..5d26664618 100644 --- a/authentik/outposts/migrations/0001_squashed_0017_outpost_managed.py +++ b/authentik/outposts/migrations/0001_squashed_0017_outpost_managed.py @@ -13,16 +13,17 @@ import authentik.outposts.models def fix_missing_token_identifier(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + db_alias = schema_editor.connection.alias User = apps.get_model("authentik_core", "User") Token = apps.get_model("authentik_core", "Token") from authentik.outposts.models import Outpost - for outpost in Outpost.objects.using(schema_editor.connection.alias).all().only("pk"): + for outpost in Outpost.objects.using(db_alias).all().only("pk"): user_identifier = outpost.user_identifier - users = User.objects.filter(username=user_identifier) + users = User.objects.using(db_alias).filter(username=user_identifier) if not users.exists(): continue - tokens = Token.objects.filter(user=users.first()) + tokens = Token.objects.using(db_alias).filter(user=users.first()) for token in tokens: if token.identifier != outpost.token_identifier: token.identifier = outpost.token_identifier @@ -37,8 +38,8 @@ def migrate_to_service_connection(apps: Apps, schema_editor: BaseDatabaseSchemaE "authentik_outposts", "KubernetesServiceConnection" ) - docker = DockerServiceConnection.objects.filter(local=True).first() - k8s = KubernetesServiceConnection.objects.filter(local=True).first() + docker = DockerServiceConnection.objects.using(db_alias).filter(local=True).first() + k8s = KubernetesServiceConnection.objects.using(db_alias).filter(local=True).first() try: for outpost in Outpost.objects.using(db_alias).all().exclude(deployment_type="custom"): @@ -54,21 +55,21 @@ def migrate_to_service_connection(apps: Apps, schema_editor: BaseDatabaseSchemaE def remove_pb_prefix_users(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - alias = schema_editor.connection.alias + db_alias = schema_editor.connection.alias User = apps.get_model("authentik_core", "User") Outpost = apps.get_model("authentik_outposts", "Outpost") - for outpost in Outpost.objects.using(alias).all(): - matching = User.objects.using(alias).filter(username=f"pb-outpost-{outpost.uuid.hex}") + for outpost in Outpost.objects.using(db_alias).all(): + matching = User.objects.using(db_alias).filter(username=f"pb-outpost-{outpost.uuid.hex}") if matching.exists(): matching.delete() def update_config_prefix(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - alias = schema_editor.connection.alias + db_alias = schema_editor.connection.alias Outpost = apps.get_model("authentik_outposts", "Outpost") - for outpost in Outpost.objects.using(alias).all(): + for outpost in Outpost.objects.using(db_alias).all(): config = outpost._config for key in list(config): if "passbook" in key: diff --git a/authentik/sources/saml/migrations/0001_squashed_0009_auto_20210301_0949.py b/authentik/sources/saml/migrations/0001_squashed_0009_auto_20210301_0949.py index 52335ab824..730e64fcd8 100644 --- a/authentik/sources/saml/migrations/0001_squashed_0009_auto_20210301_0949.py +++ b/authentik/sources/saml/migrations/0001_squashed_0009_auto_20210301_0949.py @@ -10,6 +10,8 @@ from authentik.sources.saml.processors import constants def update_algorithms(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): + db_alias = schema_editor.connection.alias + SAMLSource = apps.get_model("authentik_sources_saml", "SAMLSource") signature_translation_map = { "rsa-sha1": constants.RSA_SHA1, @@ -22,7 +24,7 @@ def update_algorithms(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): "sha256": constants.SHA256, } - for source in SAMLSource.objects.all(): + for source in SAMLSource.objects.using(db_alias).all(): source.signature_algorithm = signature_translation_map.get( source.signature_algorithm, constants.RSA_SHA256 ) diff --git a/authentik/stages/identification/migrations/0002_auto_20200530_2204_squashed_0013_identificationstage_passwordless_flow.py b/authentik/stages/identification/migrations/0002_auto_20200530_2204_squashed_0013_identificationstage_passwordless_flow.py index 5da254fa8a..d1963ee252 100644 --- a/authentik/stages/identification/migrations/0002_auto_20200530_2204_squashed_0013_identificationstage_passwordless_flow.py +++ b/authentik/stages/identification/migrations/0002_auto_20200530_2204_squashed_0013_identificationstage_passwordless_flow.py @@ -13,8 +13,8 @@ def assign_sources(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): IdentificationStage = apps.get_model("authentik_stages_identification", "identificationstage") Source = apps.get_model("authentik_core", "source") - sources = Source.objects.all() - for stage in IdentificationStage.objects.all().using(db_alias): + sources = Source.objects.using(db_alias).all() + for stage in IdentificationStage.objects.using(db_alias).all(): stage.sources.set(sources) stage.save()