Skip to content
Heroku Workshops

Instructions

  1. Clone the application code we will be using in this workshop and change into the directory created:

    git clone https://github.com/heroku-reference-apps/openapi-fastify-jwt  
    cd openapi-fastify-jwt

    💡 Note: Ignore the instructions in the README file; those are included in this workshop.

  2. Create a Heroku application, replacing the <username> and <your-enterprise-team> values in the command below according to the instructions:

    heroku create <username>-getting-started --team <your-enterprise-team>

    💡 Tip: Change <username> to your name to use as a prefix for the app name to make it unique, for example:

    marcb-data-getting-started

    💡 Tip: For <your-enterprise-team>, refer to your email from noreply@heroku.com inviting you to join an Enterprise team. Look for an email subject like Invited to the "an-event-workshop" Team on Heroku.

  3. Add a Heroku Postgres database to your application by running the command below:

    heroku addons:create heroku-postgresql:essential-0

    💡 Tip: As recommended when the above command completes, use the command heroku addons:info <yourdatabase-name> to monitor the progress of creating your database and wait for the database to be created. This Postgres database is running in the cloud on the Heroku service.

  4. Run the following commands to execute .sql scripts to create some test data:

    heroku pg:psql -f data/create_schema.sql
    heroku pg:psql -f data/create_records.sql

    This database will automatically be attached to your application code once deployed.

  5. To further interact with the database from the command line, run the following command to enter the psql terminal:

    heroku psql

    Enter the following to describe the users table created by the create_schema.sql script above:

    \d users describe table;

    Enter the following to query the users:

    select * from users;

    To exit the psql terminal, enter \q.

    💡 Side Bar: Your database was provisioned using AWS Aurora behind the scenes and fully managed on your behalf by Heroku. So you can now marvel in the knowledge you just deployed AWS Aurora with one command!

  6. Deploy the application to Heroku and test the application API:

    git push heroku main
    heroku open

    Navigate to the /directory API in the browser and click Try it out, then Execute. You should see the API return a list of users seeded into the database earlier.

    image-1

    💡 Code: If you would like to see the code behind this API, review /routes/directory.js. The web page was generated by the project including the Swagger framework.

  7. Log in to your Heroku account in your web browser and search for your application using the name you provided in step 2.

    image-1

  8. Locate the Resources tab and click on Heroku Postgres to open the Datastores page for your database.

    image-1

  9. On the Datastores page, locate the Dataclips tab and click the Create Dataclip button, completing the page as shown below to run your query by clicking the Save & Run button.

    image-1

    💡 Tip: You can create as many Dataclips as you like and even use the Share button to share them with others. Continue to explore and you will find you can also create graphs as well!

Congratulations! You have provisioned a Heroku Postgres database, seeded it with data, and explored that data from the command line, from the application logic, and finally using the Heroku Dataclip feature.