- Install Heroku CLI.
- Optionally, install psql if you want to connect to the Postgres database on Heroku from the command line.
- Clone this repository:
$ git clone git@github.com:swifthorseman/flask-peewee-heroku-setup.git
- Create the app on Heroku and deploy it:
$ heroku login $ heroku create $ git push heroku master
Running heroku create
will generate the name and the URL from which it can be accessed.
- Create a new database on Heroku as an add-on to the app:
Verify that the database has been created by running:
$ heroku addons:create heroku-postgresql:hobby-dev
$ heroku pg:info
- Set up a config variable:
$ heroku config:set HEROKU=1
- Verify that the required environment variables are set:
The values for both
$ heroku config
DATABASE_URL
andHEROKU
should be set.
-
Launch a shell on Heroku:
$ heroku run bash
-
Run:
$ python tellytubbies.py
-
From a local shell, verify that the table was created successfully:
$ heroku pg:info
The command should output the number tables (1) and the number of rows (4).
-
Use
psql
to connect to the database and query the tables:$ heroku pg:psql ::DATABASE=> \dt List of relations Schema | Name | Type | Owner --------+------------+-------+---------------- public | tellytubby | table | sgaluyzmzkklpj (1 row) ::DATABASE=> select * from tellytubby; id | name | colour ----+-------------+-------- 1 | Tinky Winky | Purple 2 | Dipsy | Green 3 | Laa-Laa | Yellow 4 | Po | Red (4 rows)
Connecting to the app through the URL (which was generated when heroku create
was run) will retrieve entries from the database and display them in the browser.