Executors for django-tenants which check whether any migrations need running before running them, making it faster.
Maintained. Last release 3 months ago, commits in 7 of the last 26 weeks. Weaker on contributor spread.
pip install django-tenants-smart-executorDjango Tenants Smart Executor
When using django-tenants, running migrations becomes quite a problem time-wise, especially as your list of tenants grows and the number of your apps and models increases. This is the case even if there are actually no migrations to run.
This package provides two methods of speeding up migrations for django-tenants.
- The first method is to skip running the migration on a schema if there are no migrations to run. If there are no migrations to run, the
schema_migratedsignal is still triggered. - The second method is to skip applying the state part of migrations in a schema when running a migration from the other schema. For example, if running a migration in the public schema, applying the tenant app state migrations is not necessary.
Installation
Install using pip (or your package manager of choice):
pip install django-tenants-smart-executor
Skipping schema migration if there are no migrations to run
Configure the GET_EXECUTOR_FUNCTION in your settings.py:
GET_EXECUTOR_FUNCTION = "django_tenants_smart_executor.load_executor"
This will tell django-tenants to use the executor from this package, which will skip the migrations if there is nothing to run.
When you run migrations when all tenants are migrated, the output will look something like this:
$ python manage.py migrate_schemas
No migrations needed for schema public, only triggering signals
No migrations needed for schema test, only triggering signals
The multiprocessing executor is also supported.
$ python manage.py migrate_schemas --executor multiprocessing
No migrations needed for schema public, only triggering signals
No migrations needed for schema test, only triggering signals
Skipping state migration on schema
By default, this functionality is off. If you want to use it, you need to use the GET_EXECUTOR_FUNCTION configuration mentioned above.
There are three possible modes for this functionality, configured by the SMART_EXECUTOR_LIMIT_STATE_TO_SCHEMA setting.
- Full (
full). You can use this if there are no relationships between the public and tenant schemas. - Public (
public). This will skip the state migrations of tenant apps when running on public schema. This is safe to use when there are no relationships from the tenant schema to the public schema.