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

Domain aliases for flexibility in schema selection. #10

Closed
develmaycare opened this issue Aug 11, 2012 · 6 comments
Closed

Domain aliases for flexibility in schema selection. #10

develmaycare opened this issue Aug 11, 2012 · 6 comments

Comments

@develmaycare
Copy link

My particular use-case may be on the edge, but I have a situation where I need the dynamic schema selection to occur on two or more domain names. For example, subdomain1.example.com and subdomain2.example.net could both use the same postgres schema. The solution I implemented was to:

  • Add a domain_aliases field to the TenantMixin as a TextField. Aliases would be entered as space separated values.
  • Alter the middleware to first check for the domain_url, but then also check for domains_aliases__contains.
  • An Http404 is still raised if neither is found.

One could implement the domain_aliases as an external table, but it seems like this simpler approach would work, and saves an additional relationship. I suppose my solution could be reduced to a single database call by using filter() once instead of get() twice, but the result would be less precise.

At any rate, I pushed this change into production these evening and it works great.

Would anyone like to see the code? Or receive a pull request?

@bernardopires
Copy link
Owner

Hello bogeymin,

thank you very much for your feedback! From your user case, I wonder if simply having multiple lines with the same schema_name would work? The field schema_name does not need to be unique, so I think you should also be ok without having to change any code. If you want I can take a look at your code. :)

Cheers,
Bernardo

@develmaycare
Copy link
Author

The schema_name (and domain_url) field is currently a varchar, but isn't it the domain_url that gets checked to determine which schema to use? That's the situation I'm in. My admin site is located at one domain, but I need a public domain to host the non-admin views using the same schema as the admin site -- that is, I need two domain_urls to point to the same schema. It's sort of like Apacghe's ServerAlias directive which listens to more domain names but still points at the same document root.

I will fork the code and push my changes if you want to have a look.

Though I have implemented multi-tenancy in the past, and I have looked at all of the available solutions, I think Tenant Schemas is the best work I've seen thus far, and I would be happy to contribute to the project.

On Aug 12, 2012, at 5:27 PM, Bernardo Pires wrote:

Hello bogeymin,

thank you very much for your feedback! From your user case, I wonder if simply having multiple lines with the same schema_name would work? The field schema_name does not need to be unique, so I think you should also be ok without having to change any code. If you want I can take a look at your code. :)

Cheers,
Bernardo


Reply to this email directly or view it on GitHub.

@bernardopires
Copy link
Owner

Yes, it's the domain_url that gets checked to determine the schema to use. But I'm not sure if I understood your problem correctly. You want subdomain1.domain.com/my/view to be the exact same page (and schema) as on subdomain2.domain.com/my/view, correct? If that's the case, you should be able to have your lines on the database like this:

<domain_url>
subdomain1.domain.com my_schema my_data
subdomain2.domain.com my_schema my_data

And it should work exactly as what you wanted. But it seems you have other view routing needs, as you use the same schema but have different views. And yes, I'd love to take a look at your code. It's very satisfying to see people are using and liking this app! Thanks for the compliments and I'd love your help! You can take a look at our list of issues when you have the time. :)

@develmaycare
Copy link
Author

In this particular project, the admin site is located on one subdomain and the public site is located on another subdomain, but both use to the same database schema.

On Aug 14, 2012, at 5:12 AM, Bernardo Pires wrote:

Yes, it's the domain_url that gets checked to determine the schema to use. But I'm not sure if I understood your problem correctly. You want subdomain1.domain.com/my/view to be the exact same page (and schema) as on subdomain2.domain.com/my/view, correct? If that's the case, you should be able to have your lines on the database like this:

subdomain1.domain.com my_schema my_data
subdomain2.domain.com my_schema my_data

And it should work exactly as what you wanted. But it seems you have other view routing needs, as you use the same schema but have different views. And yes, I'd love to take a look at your code. It's very satisfying to see people are using and liking this app! Thanks for the compliments and I'd love your help! You can take a look at our list of issues when you have the time. :)


Reply to this email directly or view it on GitHub.

@develmaycare
Copy link
Author

https://github.com/bogeymin/django-tenant-schemas/tree/develop/tenant_schemas

Changes were made in middleware.py and models.py to add a domain_aliases (text field) to effectively allow multiple domains to answer for a single tenant.

As a refresher, the feature in question is basically to allow subdomain1.example.com/admin and and subdomain2.example.com to both use the same postgres schema.

@tobiasgoecke
Copy link

@bernardopires Is the field domain_aliases not existing in the master branch version?

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

No branches or pull requests

3 participants