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

Move data between tenants #647

Closed 21adrian1996 closed 4 years ago

21adrian1996 commented 4 years ago

I have a tenant-specific application, which therefore has its own data per tenant.

The application hosts customer data for different companies. If a customer changes the company, his data should also be moved.

The use case requires, that we can create a copy of specific entries to another tenant.

Is there an easy way to do this, or how could this be achieved?

jeroenbrouwer commented 4 years ago

Depends on the amount of data you have to transfer. A simple solution is to use tenant_context(old_tenant) fetch the data and then use tenant_context(new_tenant) to create the new data through the django ORM again. Then clean-up the old data for the old_tenant as the final step. You could also use dumpdata and loaddata for specific tables within the appropriate tenant_context.