Backend server code for Baot mentorship application.
- Install Docker and verify installation.
- Install pgAdmin (or your favorite PostgreSQL GUI client).
- In the command line, tun
docker run -p 5432:5432 --name baot-mentors -e POSTGRES_PASSWORD=somePassword -d postgres
. baot-mentors is the docker container's name and can be changed freely. - Connect to this DB using your PostgresSQL client with the following details:
- host: localhost
- port: 5432
- username: postgres
- password: somePassword
-
Clone this repository and install all dependencies using
pip install -r requirements.txt
. Consider using Python's virtual environment (venv) to prevent versioning conflicts.📣 If you're experiencing installation problems with psycopg2, try installing it separately using the command
pip install psycopg2-binary
. -
Set the following environment variables (you can do so in PyCharm's run configurations):
DATABASE_URL=postgresql://postgres:somePassword@localhost/postgres
SECRET_KEY=someSecretStringUsedByFlask
APP_SETTINGS=config.DevelopmentConfig
GOOGLE_APPLICATION_CREDENTIALS=secretKey
- for prod use FIREBASE_CONFIG instead
-
Run
python reset_db.py
to initialize the DB tables. -
Run
python main_app.py
and verify (using the console output) that the server is running. -
Browse to
http://localhost:5000
in your browser and verify you get a Hello World page.
- main_app.py: This file runs the application instance. Heroku knows to run this file as it is pointed to by Procfile (using gunicorn).
- app.py - defines the application, its configuration and the DB.
- config.py: declares different configuration schemes for the application. The configuration
is set to an environment variable
APP_SETTINGS
. - models.py: defines the DB model. Each class is a DB table. Refer to Peewee ORM for more details and documentation.
- views.py: This file contains all application routing. Namely, it is responsible for all exposed APIs.
- Procfile tells Heroku which process to run on initialization.
- runtime.txt tells Heroku which Python version it should use.
To perform changes on the DB, follow these guidelines:
- Backup the database's current state (you can do this manually from the database's resource page on Heroku).
- Edit migrate.py to perform the desired operations on the DB. Use Peewee's Schema Migrations documentation and examples.
- Make sure you edit models.py to reflect your new schema.
- Once the script is final (and tested locally! 😉), push it to the remote repository.
- Run it on the staging app with
heroku run python migrate.py --app baot-mentors-stage
(you'll need Heroku CLI). - Do the same with production:
heroku run python migrate.py --app baot-mentors-prod
To apply migrations to the local DB (and if you don't mind losing all local data) - simply run reset_db.py which will re-create the DB according to the schema in models.py.
heroku logs --app <app_name>
to show recent logs (use after crash...).- Both staging and production applications deploy automatically from
master
.