2
0
mirror of https://github.com/inventree/inventree-docs.git synced 2025-04-28 05:36:46 +00:00

Merge pull request #219 from inventree/postgresql-dev

Postgresql dev
This commit is contained in:
Oliver 2021-12-21 00:44:26 +11:00 committed by GitHub
commit eb1474e20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 35 deletions

View File

@ -14,7 +14,6 @@ database:
# --- Available options: ---
# ENGINE: Database engine. Selection from:
# - sqlite3
# - mysql
# - postgresql
# NAME: Database name
@ -23,10 +22,6 @@ database:
# HOST: Database host address (if required)
# PORT: Database host port (if required)
# --- Example Configuration - sqlite3 ---
# ENGINE: sqlite3
# NAME: '/home/inventree/database.sqlite3'
# --- Example Configuration - MySQL ---
#ENGINE: mysql
#NAME: inventree

View File

@ -7,8 +7,7 @@ title: Features
InvenTree is an open-source inventory management system which provides intuitive parts management and stock control.
It is designed to be lightweight and easy to use for SME or hobbyist applications, where many existing stock management solutions are bloated and cumbersome to use. However, powerful business logic works in the background to ensure that stock tracking history is maintained, and users have ready access to stock level information. InvenTree is designed to allow for a flexible installation. You could run the InvenTree server on Raspberry Pi SBC and have a simple single-user setup with a lightweight SQLite database. Or it can be run on the "cloud" using MySQL or PostgreSQL and support multiple simultaneous users.
It is designed to be lightweight and easy to use for SME or hobbyist applications, where many existing stock management solutions are bloated and cumbersome to use. However, powerful business logic works in the background to ensure that stock tracking history is maintained, and users have ready access to stock level information. InvenTree is designed to allow for a flexible installation.
InvenTree is a [Python](https://www.python.org/) and [Django](https://www.djangoproject.com/) application which stores data in a relational database, and serves this data to the user(s) via a web browser, and (optionally) can be integrated into custom applications via an API.

View File

@ -13,6 +13,9 @@ There are some key differences compared to the [docker production setup](./docke
- The django webserver is used, instead of running behind Gunicorn
- The server will automatically reload when code changes are detected
!!! info "Static and Media Files"
The development server runs in DEBUG mode, and serves static and media files natively.
The [InvenTree docker image](https://github.com/inventree/InvenTree/blob/master/docker/Dockerfile) uses a [multi-stage build](https://docs.docker.com/develop/develop-images/multistage-build/) process to allow both production and development setups from the same image. The key difference is that the production image is pre-built using InvenTree source code from GitHub, while the development image uses the source code from your local machine (allowing live code updates).
### Docker Compose
@ -23,12 +26,27 @@ This script specifies the following containers:
| Container | Description |
| --- | --- |
| inventree-dev-db | Database image (PostgreSQL) |
| inventree-dev-server | Web server using the django development server |
| inventree-dev-worker | Background task manager |
!!! success "Works out of the box"
You should not need to make any changes to the `docker-compose.dev.yml` file to run the development docker container
#### PostgreSQL Database
A PostgreSQL database container requires a username:password combination (which can be changed). This uses the official [PostgreSQL image](https://hub.docker.com/_/postgres).
*__Note__: An empty database must be manually created as part of the setup (below)*.
#### Web Server
Runs an InvenTree web server instance, powered by Django's built-in webserver.
#### Background Worker
Runs the InvenTree background worker process.
### Environment Variables
Environment variables for the docker containers can be found in the file `dev-config.env` in the `docker` directory.
@ -57,20 +75,45 @@ docker-compose -f docker-compose.dev.yml build
### Create Database
!!! info "First Run Only"
If this is the first time you are interacting with the docker containers, the InvenTree database has not yet been created.
!!! success "First Run Only"
This command only needs to be executed on the first run, if the development database has not already been initialized
Run the following command to open a shell session for the database
```
docker-compose -f docker-compose.dev.yml run inventree-dev-server pgcli -h inventree-db -p 5432 -u pguser
```
!!! info "User"
If you have changed the `POSTGRES_USER` variable in the compose file, replace `pguser` with the different username.
You will be prompted to enter the database user password (default="pgpassword", unless altered in the compose file).
Once logged in, run the following command in the database shell:
```
create database inventree;
```
Then exit the shell with <kbd>Ctrl</kbd>+<kbd>d</kbd>
### Database Setup
The database has now been created, but it is empty! Perform the initial database setup by running the following command:
```
docker-compose -f docker-compose.dev.yml run inventree-dev-server invoke update
```
This command performs the following tasks:
This command performs the following steps:
- Install required python packages into a local python virtual environment
- Create an SQLite database and perform schema migrations
- Collect static files
- Ensure required python packages are installed
- Perform the required schema updates to create the required database tables
- Update translation files
### Create Superuser
### Create Admin Account
!!! info "First Run Only"
This command only needs to be executed on the first run, if you have not already created a superuser account for the database

View File

@ -33,7 +33,7 @@ The example docker-compose file launches the following containers:
#### PostgreSQL Database
A postgresql database container which creates a postgres user:password combination (which can be changed). This uses the official [PostgreSQL image](https://hub.docker.com/_/postgres).
A PostgreSQL database container which requires a username:password combination (which can be changed). This uses the official [PostgreSQL image](https://hub.docker.com/_/postgres).
*__Note__: An empty database must be manually created as part of the setup (below)*.
@ -116,7 +116,7 @@ This starts the database container (in this example, a PostgreSQL server).
### Create Database
If this is the first time we are interacting with the docker containers, the InvenTree database has not yet been created.
If this is the first time you are interacting with the docker containers, the InvenTree database has not yet been created.
!!! success "First Run Only"
If you have already created the InvenTree database you can progress to the next step
@ -128,7 +128,7 @@ docker-compose run inventree-server pgcli -h inventree-db -p 5432 -u pguser
```
!!! info "User"
If you have changed the `POSTGRES_USER` variable in the compose file, replace `pguser` with the different user.
If you have changed the `POSTGRES_USER` variable in the compose file, replace `pguser` with the different username.
You will be prompted to enter the database user password (default="pgpassword", unless altered in the compose file).

View File

@ -190,24 +190,6 @@ mysql> EXIT;
!!! info "Username / Password"
You should change the username and password from the values specified above. This username and password will also be for the InvenTree database connection configuration.
### SQLite
SQLite uses a simple portable database file which is easy to use for debug and testing purposes.
Install required packages as follows:
!!! info "Sudo Actions"
Perform sudo actions from a separate shell, as 'inventree' user does not have sudo access
```
sudo apt-get install sqlite3
```
A `.sqlite3` database file will be automatically created, at the location specified in the configuration options. No further steps necessary.
!!! warning "SQLite Case Sensitivity"
SQLite has a known [string matching limitation](https://docs.djangoproject.com/en/dev/ref/databases/#substring-matching-and-case-sensitivity) for non ASCII characters. If you are using non ASCII characters (e.g. Cyrillic text), it is recommended that you do not use SQLite, as search functionality will not work correctly.
## Configure InvenTree Options
Once the required software packages are installed and the database has been created, the InvenTree server options must be configured.

View File

@ -6,7 +6,6 @@ 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!