Skip to content
This repository has been archived by the owner on Jul 22, 2021. It is now read-only.

The REST API server for the Chem-lab Notebook project. This API provides an interface for students and instructors to create and complete chemistry lab assignments.

Notifications You must be signed in to change notification settings

sheldonkwoodward/chem-lab-server

Repository files navigation

Chem-lab Server

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.

Local Deployment

Use these steps to setup your local development environment.

MySQL

MySQL is the database server for our API. You will need to install it and there are few options for how.

Docker

  1. 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.

  1. Install MySQL server
$ docker run -d \
  -p 8889:3306 \
  -e MYSQL_ROOT_PASSWORD=root \
  --name=mysql-cptr450 \
  mysql/mysql-server:5.7.24
  1. Enter the MySQL command line, you may need to restart the container first
$ docker exec -it mysql-cptr450 mysql -uroot -proot
  1. Give the root user permission on localhost
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
  1. Create the chemlab table
mysql> CREATE DATABASE chemlab CHARACTER SET utf8 COLLATE utf8_bin;

Local Django Setup

Django is what runs our server.

MacOS and Linux

  1. Install pipenv (make sure you use python 3, not 2)
$ pip install pipenv
  1. 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
  1. Run migrations
$ pipenv run python manage.py migrate
  1. Run server
$ pipenv run python manage.py runserver

Migrating the database

In the case that the database models are slightly modified, you can run the migrations on your local database.

$ python manage.py migrate

Dropping the database

In the case that the database models are heavily modified or your database just needs to be reset, you can copletely recreate the database.

  1. Enter the mysql shell
$ mysql -uroot -proot
  1. Drop the database
mysql> DROP DATABASE chemlab;
  1. Now recreate the database
mysql> CREATE DATABASE chemlab CHARACTER SET utf8 COLLATE utf8_bin;
  1. Exit the mysql shell with ctrl+D
  2. Run the migrations
python manage.py migrate

About

The REST API server for the Chem-lab Notebook project. This API provides an interface for students and instructors to create and complete chemistry lab assignments.

Topics

Resources

Stars

Watchers

Forks