This app is written in Python with Flask and SQLAlchemy, as a part of the Udacity's Full Stack Web Developer Nanodegree program.
In order to run this app, the following dependencies must have been already installed:
- Postgres.
- Start manually:
pg_ctl -D /usr/local/var/postgres start
- Stop manually:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
- Flask
The database relations todos(id, description, complete, list_id)
and todolists(id, name)
must have been already created in Postgres. We have assumed that the Postgres is running on default port 5432.
dropdb todoapp -p 5432 && createdb todoapp -p 5432
- Open the database prompt -
psql -p 5432
- Connect to the database -
\c todoapp
- Displays the tables in the database
\dt
- Displays the schema of the 'todos' table
\d todos
- Displays the schema of the 'todolists' table
\d todolists
You can insert a few rows in both the tables. Insert first in the todolists
relation.
First of all locate to app directory using: cd todoapp
python3 -m venv env
set the virtual environment for Pyhtonsource env/bin/activate
activate the venv
python -m pip install -r requirements.txt
to install dependencies. For Mac users, if you face difficulty in installing thepsycopg2
, you may consider intalling thesudo brew install libpq
before running therequirement.txt
.
flask db init
to create the migrations directory structuredropdb todoapp
if you already have itcreatedb todoapp
flask db migrate
(Detects the model changes to be made and creates a migration file with upgrade and downgrade logic setup.- Using
flask db uprade
when you want to commit your changes to database - Using
flask db migrate
when you want to rollback the changes.
export FLASK_APP=app.py
export FLASK_DEBUG=true
- Then
flask run
to run the app (http://127.0.0.1:5000/ or http://localhost:5000) deactivate
de-activate the virtual environment