Skip to content

Database

Dave Walker edited this page Aug 19, 2024 · 2 revisions

Database Schema

Nature Recorder Database Diagram

Further details are provided in the documentation within the repository. Please see the section on generating the project documentation for more information.

Pre-requisites

To create the database for the first time, a virtual environment should be created, the requirements should be installed from the "requirements.txt" file using pip and the environment should be activated.

Creating an Empty Database

With the pre-requisites in place, an empty database with the correct schema in place can be created by running the following commands from the root of the project:

Windows (PowerShell)

$env:NATURE_RECORDER_DB="$pwd\data\naturerecorder.db"
$env:PYTHONPATH="$pwd\src"
python -m naturerec_model

Linux or MacOS

export NATURE_RECORDER_DB="`pwd`/data/naturerecorder.db"
export PYTHONPATH=`pwd`/src
python -m naturerec_model

This will create a database called "naturerecorder.db" in the "data" sub-folder of the working copy from which the commands are run. To create the database elsewhere, change the path assigned to the NATURE_RECORDER_DB environment variable.

Adding a User to the Database

Once the database has been created, enter the following commands from the root of the project to prompt for a username and password and add that user to the database:

Windows (PowerShell)

$env:NATURE_RECORDER_DB="$pwd\data\naturerecorder.db"
$env:PYTHONPATH="$pwd\src"
python -m naturerec_model

Linux or MacOS

export NATURE_RECORDER_DB="`pwd`/data/naturerecorder.db"
export PYTHONPATH=`pwd`/src
python add_user.py

This creates the user in the copy of the database in the "data" sub-folder of the working copy from which the commands are run. To create the user in a database held elsewhere, change the path assigned to the NATURE_RECORDER_DB environment variable.

Clone this wiki locally