Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds optional cursor override to support django schema tenants #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

onGranot
Copy link

@onGranot onGranot commented Sep 26, 2024

Subject: Add support for django tenants integration

Feature or Bugfix

  • Feature
  • Bugfix

Purpose

  • This PR aims to add support for django-tenants, which is a schema based tenant extension for Django. To achieve this, it is necessary to set the SEARCH_PATH to the correct schema based on the context. We can achieve this by setting the search path on the cursor prior to returning it, making consequent queries context aware.

Detail

  • Feature 1: Given the Django setting is enabled, set SEARCH_PATH to the relevant tenant & public schemas.

Relates

Resolves #157

Comment on lines +1407 to +1408
if DJANGO_REDSHIFT_ENABLE_TENANT_SCHEMA:
cursor.execute(f"SET SEARCH_PATH TO '{connection.schema_name}', public")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a feature of the Redshift Backend.
I understand that you can't use ‘django_tenants.postgresql_backend’ provided by django-tenants, but I think you should implement a DatabaseWrapper in your application, as django-tenants does.
https://github.com/django-tenants/django-tenants/blob/c02b5a46ae8abc089c3f5f355b4d116e25572a6a/django_tenants/postgresql_backend/base.py#L60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for django tenants integration
2 participants