The REST API server for the Chem Lab Notebook project for CPTR 450. Built with Django 2, the Django REST Framework, and Python 3.7.
Refer to the wiki for implementation details.
Use these steps to setup your local development environment.
MySQL is the database server for our API. You will need to install it and there are few options for how.
- Install Docker
Download your OS' Docker version here and install it. You will need to make an account. Linux users can probably install it with your respective package manager.
- Install MySQL server
$ docker run -d \
-p 8889:3306 \
-e MYSQL_ROOT_PASSWORD=root \
--name=mysql-cptr450 \
mysql/mysql-server:5.7.24
- Enter the MySQL command line, you may need to restart the container first
$ docker exec -it mysql-cptr450 mysql -uroot -proot
- Give the root user permission on localhost
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
- Create the chemlab table
mysql> CREATE DATABASE chemlab CHARACTER SET utf8 COLLATE utf8_bin;
Django is what runs our server.
- Install pipenv (make sure you use python 3, not 2)
$ pip install pipenv
- Install dependencies
On MacOS, use brew to install mysql and set two environment variables so pipenv can find the OpenSSL libraries. For Linux, the default package managers may work but you can install and use linuxbrew as well.
Install brew using the command in one of the above links then run these three commands:
$ brew install mysql
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
After that you should be able to install the dependencies with pipenv.
$ pipenv install
- Run migrations
$ pipenv run python manage.py migrate
- Run server
$ pipenv run python manage.py runserver
In the case that the database models are slightly modified, you can run the migrations on your local database.
$ python manage.py migrate
In the case that the database models are heavily modified or your database just needs to be reset, you can copletely recreate the database.
- Enter the mysql shell
$ mysql -uroot -proot
- Drop the database
mysql> DROP DATABASE chemlab;
- Now recreate the database
mysql> CREATE DATABASE chemlab CHARACTER SET utf8 COLLATE utf8_bin;
- Exit the mysql shell with ctrl+D
- Run the migrations
python manage.py migrate