From baa77eaa2748f6caca59d3b23bf080c20181bf83 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 12 Nov 2020 12:40:38 +1100 Subject: [PATCH 1/4] Updated instructions for migration of database content --- docs/start/migrate.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/start/migrate.md b/docs/start/migrate.md index 6376362..9b3fa26 100644 --- a/docs/start/migrate.md +++ b/docs/start/migrate.md @@ -11,8 +11,14 @@ In the case that data needs to be migrated from one database installation to ano ### Export Data +Export the database contents to a JSON file using the following command: + +!!! info "Directory" + The following command must be performed from the directory which contains the manage.py file + ``` -python3 InvenTree/manage.py dumpdata --exclude contenttypes --exclude auth.permission --indent 2 > data.json +cd InvenTree +python3 manage.py dumpdata --exclude contenttypes --exclude auth.permission --indent 2 --output data.json ``` This will export all data (including user information) to a json data file. @@ -32,7 +38,7 @@ invoke migrate The new database should now be correctly initialized with the correct table structures requried to import the data. Run the following command to load the databased dump file into the new database. ``` -python3 InvenTree/manage.py loaddata data.json +python3 manage.py loaddata data.json ``` !!! info "Character Encoding" From 253d14f6342d3f70b4de21c974c3df8183d3e7c2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 12 Nov 2020 13:44:15 +1100 Subject: [PATCH 2/4] Further updates to match new invoke commands --- docs/start/migrate.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/start/migrate.md b/docs/start/migrate.md index 9b3fa26..c287985 100644 --- a/docs/start/migrate.md +++ b/docs/start/migrate.md @@ -6,22 +6,26 @@ title: Migrating Data In the case that data needs to be migrated from one database installation to another, the following procedure can be used to export data, initialize the new database, and re-import the data. +For example, if you wish to migrate from an SQLite database backend to a MySQL database backend, you will need to export the data into a standardized format, and then read it back in to the new database. + !!! warning "Backup Database" Ensure that the original database is securely backed up first! +!!! info "Up to Date" + Ensure that the original database is up to date, by running `invoke migrate` + ### Export Data Export the database contents to a JSON file using the following command: -!!! info "Directory" - The following command must be performed from the directory which contains the manage.py file - ``` -cd InvenTree -python3 manage.py dumpdata --exclude contenttypes --exclude auth.permission --indent 2 --output data.json +invoke export-records -f data.json ``` -This will export all data (including user information) to a json data file. +This will create JSON file at the specified location which contains all database records. + +!!! info "Specifying filename" + The filename of the exported file can be specified using the `-f` option ### Initialize New Database @@ -33,13 +37,18 @@ Then, ensure that the database schema are correctly initialized in the new datab invoke migrate ``` +This ensures that the required database tables exist, which must be the case before data can be imported. + ### Import Data The new database should now be correctly initialized with the correct table structures requried to import the data. Run the following command to load the databased dump file into the new database. ``` -python3 manage.py loaddata data.json +invoke import-records -f data.json ``` +!!! info "Import Filename" + A different filename can be specified using the `-f` option + !!! info "Character Encoding" If the character encoding of the data file does not exactly match the target database, the import operation may not succeed. In this case, some manual editing of the database JSON file may be required. From c58e21b667ea1aaa6fd87cf3553fefa569e25a0d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 12 Nov 2020 13:51:48 +1100 Subject: [PATCH 3/4] Some warnings --- docs/start/deploy.md | 3 +++ docs/start/migrate.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/start/deploy.md b/docs/start/deploy.md index c0e6677..74f248f 100644 --- a/docs/start/deploy.md +++ b/docs/start/deploy.md @@ -32,6 +32,9 @@ To enable access to the InvenTree server from other computers on a local network invoke server -a 192.168.120.1:8000 ``` +!!! warning "Not For Production" + It should be noted that the *development server* provided with django / InvenTree is probably not suitable for your production environment. Instead, use a proper web-server (such as Gunicorn, below). + ## Gunicorn Following is a simple tutorial on serving InvenTree using [Gunicorn](https://gunicorn.org/). Gunicorn is a Python WSGI server which provides a multi-worker server which is well suited to handling multiple simultaneous requests. Gunicorn is a solid choice for a production server which is easy to configure and performs well in a multi-user environment. diff --git a/docs/start/migrate.md b/docs/start/migrate.md index c287985..8ff3d0d 100644 --- a/docs/start/migrate.md +++ b/docs/start/migrate.md @@ -50,5 +50,5 @@ invoke import-records -f data.json !!! info "Import Filename" A different filename can be specified using the `-f` option -!!! info "Character Encoding" +!!! warning "Character Encoding" If the character encoding of the data file does not exactly match the target database, the import operation may not succeed. In this case, some manual editing of the database JSON file may be required. From 176717c0642f5687d9d5df9ae8abf90d0a7a4ed9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 12 Nov 2020 16:00:07 +1100 Subject: [PATCH 4/4] Add warning for gunicorn setup --- docs/start/deploy.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/start/deploy.md b/docs/start/deploy.md index 74f248f..173cc17 100644 --- a/docs/start/deploy.md +++ b/docs/start/deploy.md @@ -47,6 +47,9 @@ Gunicorn can be installed using PIP: pip3 install gunicorn ``` +!!! warning "Python Environment" + Ensure that gunicorn is installed within the same python environment context as the InvenTree install - otherwise gunicorn will not be able to import the correct python modules. + ### Configure Static Directories Directories for storing *media* files and *static* files should be specified in the ``config.yaml`` configuration file. These directories are the ``MEDIA_ROOT`` and ``STATIC_ROOT`` paths required by the Django app. Ensure that both of these directories are correctly configured for your setup.