bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

How to add integrate this with the cookiecutter-django and dj-database-url projects #292

Closed tkovalsky closed 8 years ago

tkovalsky commented 9 years ago

Hi - I am trying to build a multi-tennant app based on the cookiecutter-django project. If these projects are all integrated, you have a great boilerplate SaaS project...which would be amazing.

The cookiecutter-django project uses this implementation for the Database: https://github.com/kennethreitz/dj-database-url

How could we make that happen?

bernardopires commented 9 years ago

I don't understand what's the problem? Are you forced to use dj-database-url? That should be optional.

tkovalsky commented 9 years ago

Hi - got it - do I need to setup the models and "customer" app first?

Sent from my iPhone

On Oct 11, 2015, at 7:30 AM, Bernardo Pires notifications@github.com wrote:

I don't understand what's the problem? Are you forced to use dj-database-url? That should be optional.

— Reply to this email directly or view it on GitHub.

bernardopires commented 9 years ago

I thought dj-database-url was just a different way to initialize your database settings, i.e, how to connect to the database? It has nothing to do with setting up your models. Just set up your database settings using the standard way.

tkovalsky commented 9 years ago

i guess my issue (aside from being a novice dev) was the change of the database engine.... the url format is postgres::user:pass@url/dbname I assume "postgres" is the db engine, which threw me off.

After the installation, Do I have 3 sets of Apps? Installed, Shared, Tenant?

If I have a "contacts" app where each tenant should have their own contacts data, which app would it be installed under?

Do you have githib references to others who have implemented this django package?

thanks for the help!

bernardopires commented 9 years ago

You really don't have to use their format for specifying how to connect the database. You can use the standard way:

DATABASES = {
    'default': {
        'ENGINE': 'tenant_schemas.postgresql_backend',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

If you really want to use their format or if you have to, you'll have to make changs to their code so you can support the engine tenant_schemas.postgresql_backend.

As a novice dev I would suggest you to first understand how a Django project works before trying to use more complicated apps.

tkovalsky commented 9 years ago

Thanks for the response. I understand how django works which is why I am fighting the uphill battle to build something that is scalable. My dev skills are way less than my system architect skills but my goal is to build it once properly and iterate. If I have the backend in place, I "should" be better than having a full rewrite.

I spun up an Apache server and wanted to get the multi tenant db implemented next so I can start migrating my models in to the multi tenant structure. I have this functional as a I single user type of app but I need clients to be able to share views of data within their companies.

I basically have 3 apps - contacts, deals, listings, each of which should any client would use.

If I could get these models working with multi tenants I would be in a good place and not have to deal with the folks I speak with on upwork.

Any advice would be greatly appreciated.

Sent from my iPhone

On Oct 11, 2015, at 4:39 PM, Bernardo Pires notifications@github.com wrote:

You really don't have to use their format for specifying how to connect the database. You can use the standard way:

DATABASES = { 'default': { 'ENGINE': 'tenant_schemas.postgresql_backend', 'NAME': 'mydatabase', 'USER': 'mydatabaseuser', 'PASSWORD': 'mypassword', 'HOST': '127.0.0.1', 'PORT': '5432', } }

If you really want to use their format or if you have to, you'll have to make changs to their code so you can support the backend tenant_schemas.postgresql_backend.

As a novice dev I would suggest you to first understand how a Django project works before trying to use more complicated apps.

— Reply to this email directly or view it on GitHub.

fgmacedo commented 9 years ago

Hi!

When you define postgres:// dj-database-url sets the engine to Django's default postgres engine instead of the required 'tenant_schemas.postgresql_backend'.

In order to use dj-database-url alongside this project, you must specify the engine parameter into config, because dj-database-url doesn't know about this project's custom engine.

Something like this:

{ 'default': config( 'postgres://user:pass@url/dbname', engine='tenant_schemas.postgresql_backend') }

Best regards,

bernardopires commented 9 years ago

:+1: