hugobessa / django-shared-schema-tenants

A lib to help in the creation of shared schema multi tenants applications without suffering
MIT License
20 stars 9 forks source link

Add support to tenant specific fields on tables #20

Closed hugobessa closed 6 years ago

hugobessa commented 7 years ago

Description

Today, if you want to add new table fields to a tenant you will have to add this field to all tenants. Would be good if we could add specific fields only to some tenants.

Proposed solution

  1. Hard coded of tenant specific fields schemas: A meta class attribute that receives a dict with the tenant slugs pointing to its respective specific fields schema for the model. You also would have to add the CodebaseSchemaSpecificFieldsMixin to the model class.
  2. Client customizable tenant specific fields schemas: Creation of this two tables to store the specific fields metadata:

    TenantSpecificField
    - tenant: foreign key to a tenant, 
    - content_type: foreign key to django ContentType table
    - name: char field, 
    - data_type: choices char field
    - is_required: boolean, 
    - default_value: text_field, 
    - validators: many to many field
    TenantSpecificFieldsValidator
    - module_path: string
    - tenants: many to many field to tenants

    You would have to add the DatabaseSchemaSpecificFieldsMixin to the model class. It would add a JSONField (or TextField if JSONField is not supported by the database) in the original table where we should have the specific fields values.

  3. Client customizable tenant specific tables: Creation of this three tables to store the specific tables and its fields metadata:

    TenantSpecificTable
    - tenant: foreign key to a tenant,
    - name: char field,
    TenantSpecificTableField
    - tenant: foreign key to a tenant, 
    - tenant_specific_table: foreign key to TenantSpecificTable
    - name: char field, 
    - data_type: choices char field
    - is_required: boolean, 
    - default_value: text_field, 
    - validators: many to many field
    TenantSpecificFieldsValidator
    - module_path: string
    - tenants: many to many field to tenants

Other requirements