The backend of sniffr, an application for finding play dates for your dog. ๐
A python flask app, which is dockerizerd
cd sniffr-be
- If you are going to be changing code then switch to a new branch using:
git checkout xxxx
-
Add a blank file called
.env
into the repo so the app can pull sensitive information. Fill the.env
file with the information from the .env pinned message in our discord.
-
Set up a virtual environment (a mini python development workspace) using pipenv by running
pipenv install
when in the app's base directory:
๐จ This step will produce more code than just shown below and could take a few minutes depending on dependancy installation / your machine.
-
Activate your environment by running
pipenv shell
as the prompt says. This will load the things you placed in .env and activate the necessary python imports.
-
We need to set up the database next. You are going to run three commands in sequence into your bash terminal once you have started your pipenv shell in step 6:
flask db init flask db migrate flask db upgrade
The above commands will set up the initial sqlite db, create a migration script that will set up the db as we have written it in
models.py
, and the third command will run the migration script (2
) and upgrade (3
) our initial (1
) sqlite database.๐ป You should end up with a folder called
migrations/
and the filesniffrdb.db
, which contains our blank tables, if everything went well. -
Lastly, we need to seed our database with starter information. To do so, run
python seed_db.py
when in the base directory to activate the seed script. If successful, it should print out new entries in each of the tables that were seeded. Example:
Supposing you did steps 1-8 above already...
-
Make sure you are in the correct branch!
-
Then activate your pipenv shell:
pipenv shell
-
Once active, you can run the flask app:
flask run
โ๏ธ This should run up the app. You can view the exact url and port you need in the output. And now you can now use curl , postman , thunder client , or a browser to access routes
If you made changes to models.py
during development... you do not need to completely remake the database. Instead, you can migrate and upgrade the database (usually). Try running:
flask db migrate flask db upgrade
If successful, then you should be able to seed and use the new database tables/columns. If not, you may need to remake it from scratch after deleting the sniffrdb.db
file and migrations
folder.
heroku run bash --app sniffr-be
To run all of the tests:
pytest -v tests/sniffr_tests
To run coverage analysis:
pytest tests/sniffr_tests --cov=sniffr
If you want to quickly run a docker container of this app then you can:
- Download the repo
- Run
docker-compose up --build
- docker start sniffr-be...
- docker stop sniffr-be...