bernardopires / django-tenant-schemas

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

Migrating existing data #449

Open bodgerbarnett opened 7 years ago

bodgerbarnett commented 7 years ago

Is there a way I can move my existing project to use this app so that it becomes a multi-tenanted site?

We already have tons and tons of data which ought to have been split off into multiple tenants in the first place but wasn't. Now I'm trying to split it all up but I'm not sure if this app is the way to go.

If I wanted to do that, how would I go about it? Would it work?

I've got some foreign keys on some models which I could use to decide which tenants those instances should be connected to but how would I migrate them? Just write some sort of monster data migration maybe?

goodtune commented 7 years ago

Have a look at the django documentation on the dumpdata and loaddata commands; they can be used with this application.

You may need to do some pre processing on the JSON the dumpdata produces, but it's your best bet.

bodgerbarnett commented 7 years ago

Are you saying that I should dumpdata from my existing db, drop the db, edit the JSON to assign the objects to the right tenants, then recreate the db and load the fixtures back in?