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 d6245df7494f..443d917c7358 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 @@ 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 49894c669d8c..c4314da9ec81 100644 --- a/authentik/flows/migrations/0027_auto_20231028_1424.py +++ b/authentik/flows/migrations/0027_auto_20231028_1424.py @@ -21,7 +21,9 @@ 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 7bd9d4f42b89..5d2666461821 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 @@ 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/ldap/migrations/0001_squashed_0012_auto_20210812_1703.py b/authentik/sources/ldap/migrations/0001_squashed_0012_auto_20210812_1703.py index bb13c6a70d75..cf9a9a8a2947 100644 --- a/authentik/sources/ldap/migrations/0001_squashed_0012_auto_20210812_1703.py +++ b/authentik/sources/ldap/migrations/0001_squashed_0012_auto_20210812_1703.py @@ -31,9 +31,9 @@ def set_default_group_mappings(apps: Apps, schema_editor): db_alias = schema_editor.connection.alias for source in LDAPSource.objects.using(db_alias).all(): - if source.property_mappings_group.exists(): + if source.property_mappings_group.using(db_alias).exists(): continue - source.property_mappings_group.set( + source.property_mappings_group.using(db_alias).set( LDAPPropertyMapping.objects.using(db_alias).filter( managed="goauthentik.io/sources/ldap/default-name" ) 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 52335ab8248c..730e64fcd83d 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 @@ 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/authenticator_validate/migrations/0010_remove_authenticatorvalidatestage_configuration_stage_and_more.py b/authentik/stages/authenticator_validate/migrations/0010_remove_authenticatorvalidatestage_configuration_stage_and_more.py index 735a7d70e7e9..61de0f08208c 100644 --- a/authentik/stages/authenticator_validate/migrations/0010_remove_authenticatorvalidatestage_configuration_stage_and_more.py +++ b/authentik/stages/authenticator_validate/migrations/0010_remove_authenticatorvalidatestage_configuration_stage_and_more.py @@ -13,7 +13,7 @@ def migrate_configuration_stage(apps: Apps, schema_editor: BaseDatabaseSchemaEdi for stage in AuthenticatorValidateStage.objects.using(db_alias).all(): if stage.configuration_stage: - stage.configuration_stages.set([stage.configuration_stage]) + stage.configuration_stages.using(db_alias).set([stage.configuration_stage]) stage.save() 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 5da254fa8ae4..e1cc14d4ebb8 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,9 +13,9 @@ 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): - stage.sources.set(sources) + sources = Source.objects.using(db_alias).all() + for stage in IdentificationStage.objects.using(db_alias).all(): + stage.sources.using(db_alias).set(sources) stage.save() diff --git a/authentik/stages/prompt/migrations/0009_prompt_name.py b/authentik/stages/prompt/migrations/0009_prompt_name.py index ccaebe2e6ab4..c66b9def0d4f 100644 --- a/authentik/stages/prompt/migrations/0009_prompt_name.py +++ b/authentik/stages/prompt/migrations/0009_prompt_name.py @@ -12,7 +12,7 @@ def set_generated_name(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): for prompt in Prompt.objects.using(db_alias).all(): name = prompt.field_key - stage = prompt.promptstage_set.order_by("name").first() + stage = prompt.promptstage_set.using(db_alias).order_by("name").first() if stage: name += "_" + stage.name else: