-
Notifications
You must be signed in to change notification settings - Fork 61
Tethys tenants #1210
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
Open
msouff
wants to merge
37
commits into
tethysplatform:main
Choose a base branch
from
Aquaveo:tethys_tenants
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tethys tenants #1210
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
d218232
working on adding tenants
msouff 4d3301a
working on adding tenants
msouff b647cff
simplified tethys_tenant base structure
msouff 8336a6c
harverster or middleware won't work for tenant-aware apps
romer8 5eee441
more simplifications to the core tethys_tenants
msouff 03f8244
fixing broken tests
msouff 0fe616c
revert test_harvester.py
msouff 8267196
tests
msouff b05d84a
context_processor.request is already in there
msouff 3944006
removed tenants postgis backend. Not needed
msouff 2b97459
tests
msouff baee361
linting
msouff ccc1f67
apply tenant migration only if has_module django tenants; more test u…
msouff 0d62232
moved tethys_tenants app to django tenants settings
msouff a479437
working on documentation
msouff fb02b92
documentation
msouff a3e1b9a
fixed tests; more documentation
msouff 54e87d6
Updated migration to only be detected if django_tenants is installed
jakeymac 7ab9d65
Updated whats new page in docs
jakeymac 36bc74d
Added warning in settings to make sure users are using django_tenants…
jakeymac 0275ad3
Updated order of sections in production doc page
jakeymac 0d372f6
Updates to documentation
jakeymac 176258a
Fixed documentation
jakeymac 88f2d29
Merge remote-tracking branch 'upstream/main' into tethys_tenants
jakeymac f788438
Updated tethys installation script to use django_tenants postgresql b…
jakeymac c88c451
Formatting fixes
jakeymac ee310b0
Fixed tests
jakeymac 32718be
Updated configurations to display warnings to user concening tethys t…
jakeymac 8c3c5c5
Formatting
jakeymac 32a1eee
Merge branch 'main' into tethys_tenants
jakeymac a71e231
Updated documentation for tenants configurations
jakeymac 91f6c7c
flake fix
jakeymac 09af76a
Converted tests to pytest
jakeymac 1c97e0c
formatting fixes
jakeymac 21ac0b6
Updated default portal config in installation script to enable tenants
jakeymac ef3ddf1
Fixed config in install script
jakeymac 2cca9e7
One more portal_config fix in install script
jakeymac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...lation/production/manual/configuration/advanced/images/tethys_tenants_admin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 149 additions & 0 deletions
149
docs/installation/production/manual/configuration/advanced/multi_tenancy.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| .. _multi_tenancy_config: | ||
|
|
||
| ************************ | ||
| Multi Tenancy (Optional) | ||
| ************************ | ||
|
|
||
| **Last Updated:** December 2025 | ||
|
|
||
| .. important:: | ||
|
|
||
| This capability requires the ``django-tenants`` third-party library to be installed. Starting with Tethys 5.0 or if you are using ``micro-tethys-platform``, you will need to install ``django-tenants`` using conda or pip as follows: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # conda: conda-forge channel strongly recommended | ||
| conda install -c conda-forge django-tenants | ||
|
|
||
| # pip | ||
| pip install django-tenants | ||
|
|
||
| .. important:: | ||
|
|
||
| Multi-tenancy requires PostgreSQL as the database backend. SQLite is not supported. | ||
|
|
||
| Tethys Portal supports only one tenant per portal by default. Multi-tenancy allows you to run multiple tenants (isolated instances of Tethys Portal) within a single deployment. This is useful for organizations or providers that want to provide separate environments for different groups or customers. In addition, multi-tenancy enables the ability to separate and customize the look and resources of the Tethys Portal based on each tenant. This functionality extends to the app level. | ||
|
|
||
|
|
||
| Enable Multi-Tenancy | ||
| ==================== | ||
|
|
||
| Use the following instructions to setup multi-tenancy for your Tethys Portal deployment. See the `Django-tenants Documentation <https://django-tenants.readthedocs.io/en/latest/use.html>`_ for more information. | ||
|
|
||
| Configuration | ||
| ------------- | ||
|
|
||
| Enable multi-tenancy by making the following changes to your settings: | ||
|
|
||
| Begin by enabling Tethys Tenants: | ||
|
|
||
| .. code-block:: yaml | ||
| :emphasize-lines: 3-4 | ||
|
|
||
| settings: | ||
| ... | ||
| TENANTS_CONFIG: | ||
| ENABLED: true | ||
|
|
||
| Next, override the database engine to use the ``django-tenants`` backend: | ||
|
|
||
| .. code-block:: yaml | ||
| :emphasize-lines: 4 | ||
|
|
||
| settings: | ||
| DATABASES: | ||
| default: | ||
| ENGINE: django_tenants.postgresql_backend | ||
|
|
||
| You can customize the multi-tenancy behavior with the following settings: | ||
|
|
||
| .. code-block:: yaml | ||
| :emphasize-lines: 4-9 | ||
|
|
||
| settings: | ||
| TENANTS_CONFIG: | ||
| ENABLED: true | ||
| TENANT_APPS: | ||
| - "tethys_apps" | ||
| - "tethys_config" | ||
| TENANT_LIMIT_SET_CALLS: false | ||
| TENANT_COLOR_ADMIN_APPS: true | ||
| SHOW_PUBLIC_IF_NO_TENANT_FOUND: false | ||
|
|
||
| Configuration Options | ||
| ===================== | ||
|
|
||
| **TENANT_APPS** | ||
| List of Django apps that should be isolated per tenant. These apps will have their database tables created in each tenant's schema. | ||
|
|
||
| **TENANT_LIMIT_SET_CALLS** | ||
| Boolean (default: ``false``). When ``true``, limits database SET calls for performance optimization. | ||
|
|
||
| **TENANT_COLOR_ADMIN_APPS** | ||
| Boolean (default: ``true``). When ``true``, colors tenant-enabled sections dark green in the site admin. | ||
|
|
||
| **SHOW_PUBLIC_IF_NO_TENANT_FOUND** | ||
| Boolean (default: ``false``). When ``true``, shows the public schema when no tenant is found instead of returning a 404 error. | ||
|
|
||
| Working with Tenants | ||
| ==================== | ||
|
|
||
| **Run migrations**: | ||
|
|
||
| If the Tethys database is being created for the first time, new tenant tables are created as part of it by detecting and applying migrations in the following way. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage makemigrations <app_label> | ||
| tethys manage migrate_schemas | ||
|
|
||
| If existing django-apps become tenant aware (are moved to the `TENANT_APPS` list) later on, django will not recognize that new migrations need to be applied by default. Use the ``migrate`` command to first unapply the migrations at the tenant level and then reapply them properly using the ``zero`` parameter and the ``--tenant``` flag in the following way. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage migrate <app_label> zero --fake --tenant | ||
| tethys manage migrate <app_label> --tenant | ||
|
|
||
| After updating your :file:`portal_config.yml` file: | ||
|
|
||
| **Create tenant**: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage create_tenant | ||
|
|
||
| See the `Django-tenants Documentation <https://django-tenants.readthedocs.io/en/latest/use.html#create-tenant>`_ for more details on using the `create_tenant` command or run ``tethys manage create_tenant --django-help`` on the active tethys environment terminal. | ||
|
|
||
| Even though it already exists, the default public schema must be added to the Tenants table using the `create_tenant` command. See the example below: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage create_tenant --schema_name public --name Public --domain-domain localhost | ||
|
|
||
| **Create tenant superuser**: | ||
|
|
||
| Each tenant requires its own portal admin account. Create a superuser for a specific tenant by running the following command: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage create_tenant_superuser | ||
|
|
||
| New tenants and tenant domains can be added via the Tethys Portal Admin interface once multi-tenancy is enabled. The Tethys Tenants admin block is only visible to superusers of the public schema. | ||
|
|
||
| .. figure:: ./images/tethys_tenants_admin.png | ||
| :width: 800px | ||
|
|
||
| Management | ||
| ---------- | ||
|
|
||
| Django-tenants includes two very useful commands to help manage database schemas. | ||
|
|
||
| - `tenant_command <https://django-tenants.readthedocs.io/en/latest/use.html#tenant-command>`_: Runs any django manage command on an individual schema | ||
| - `all_tenants_command <https://django-tenants.readthedocs.io/en/latest/use.html#all-tenants-command>`_: Runs any django manage command on all schemas | ||
|
|
||
| For example, to show the applied migrations for a specific tenant schema or for all tenant schemas, use the following commands: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| tethys manage tenant_command showmigrations <app_label> --schema <schema_name> | ||
| tethys manage all_tenants_command showmigrations <app_label> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.