upstream fixes

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2023-11-16 13:42:15 +01:00
parent d13631914a
commit f3c552a533
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
4 changed files with 7 additions and 3359 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,24 +2,15 @@
from uuid import uuid4
from django.apps import apps
from django.core.management import call_command
from django.db import connections, models
from django.db import models
from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _
from django_tenants.models import DomainMixin, TenantMixin, post_schema_sync
from django_tenants.postgresql_backend.base import _check_schema_name
from django_tenants.utils import (
get_creation_fakes_migrations,
get_tenant_base_schema,
get_tenant_database_alias,
schema_exists,
)
from rest_framework.serializers import Serializer
from structlog.stdlib import get_logger
from authentik.blueprints.apps import ManagedAppConfig
from authentik.lib.models import SerializerModel
from authentik.tenants.clone import CloneSchema
LOGGER = get_logger()
@ -67,51 +58,6 @@ class Tenant(TenantMixin, SerializerModel):
default=86400,
)
def create_schema(self, check_if_exists=False, sync_schema=True, verbosity=1):
"""
Creates the schema 'schema_name' for this tenant. Optionally checks if
the schema already exists before creating it. Returns true if the
schema was created, false otherwise.
"""
# safety check
connection = connections[get_tenant_database_alias()]
_check_schema_name(self.schema_name)
cursor = connection.cursor()
if check_if_exists and schema_exists(self.schema_name):
return False
fake_migrations = get_creation_fakes_migrations()
if sync_schema:
if fake_migrations:
# copy tables and data from provided model schema
base_schema = get_tenant_base_schema()
clone_schema = CloneSchema()
clone_schema.clone_schema(base_schema, self.schema_name)
call_command(
"migrate_schemas",
tenant=True,
fake=True,
schema_name=self.schema_name,
interactive=False,
verbosity=verbosity,
)
else:
# create the schema
cursor.execute('CREATE SCHEMA "%s"' % self.schema_name)
call_command(
"migrate_schemas",
tenant=True,
schema_name=self.schema_name,
interactive=False,
verbosity=verbosity,
)
connection.set_schema_to_public()
def save(self, *args, **kwargs):
if self.schema_name == "template":
raise Exception("Cannot create schema named template")

8
poetry.lock generated
View File

@ -1284,9 +1284,9 @@ Django = ">=2.1,<4.3"
[package.source]
type = "git"
url = "https://github.com/hho6643/django-tenants.git"
reference = "hho6643-psycopg3_fixes"
resolved_reference = "0895db487811d9864be79ce35fdf88c92ed5fac7"
url = "https://github.com/rissson/django-tenants.git"
reference = "authentik-fixes"
resolved_reference = "31040e911d00a96e9379860d48f458c2b222afc1"
[[package]]
name = "djangorestframework"
@ -4662,4 +4662,4 @@ files = [
[metadata]
lock-version = "2.0"
python-versions = "~3.11"
content-hash = "7c8fba15c50cc7ff0341b6654444d49d69e4e99659ea1cccc411bef9efdcef82"
content-hash = "46e484f52ef3b3b9e64091f3997090bd2a6d9cf489ddf721ff2eb153c2b4f285"

View File

@ -134,7 +134,8 @@ django-model-utils = "*"
django-prometheus = "*"
django-redis = "*"
# See https://github.com/django-tenants/django-tenants/pull/959
django-tenants = { git = "https://github.com/hho6643/django-tenants.git", branch="hho6643-psycopg3_fixes" }
# See https://github.com/django-tenants/django-tenants/pull/997
django-tenants = { git = "https://github.com/rissson/django-tenants.git", branch="authentik-fixes" }
djangorestframework = "*"
djangorestframework-guardian = "*"
docker = "*"