Importing data from Production to Development - DesignSafe-CI/portal GitHub Wiki
The database used in local development is a SQLite database, whereas in production the database is MySQL. We can just import a MySQL database dump into our SQLite database.
To move data from production to development use the Django dumpdata command.
Run an instance of the DesignSafe django
container with a production environment config. Map in a local volume to export data to:
user@localhost $ docker run -it --rm -v /path/to/datadump:/datadump \
--env-file designsafe.env portal_django bash
root@<container> # python manage.py dumpdata --natural-foreign --natural-primary \
--exclude=cmsplugin_cascade.Segmentation \
> /datadump/datadump.json
root@<container> # exit
Then we can use the loaddata command to load datadump.json
into our MySQL instance. We also need to flush the local database to empty all existing data. IMPORTANT: if you need to backup your local database do it now!
user@localhost $ docker-compose up -d
user@localhost $ cp db.sqlite3 db.sqlite3.bak
user@localhost $ cp /path/to/datadump/datadump.json .
user@localhost $ docker exec -it portal_django_1 bash
root@<container> # ./manage.py flush --no-initial-data
root@<container> # ./manage.py loaddata datadump.json