Skip to content

Backend: Create a local PostgreSQL database

Tim K edited this page Sep 3, 2018 · 9 revisions

Since it's hard to produce universal instructions for both Linux and Windows, you'll need to google around yourself.

These instructions are only meant to be used to create a local instance of the Fizzyo database for development and testing. That is, all actions and commands mentioned here must be executed on your own laptop/PC and not the Fizzyo server.

  1. First, you need to install PostgreSQL 9.6.

  2. In PostgreSQL, create a user named fizzyo_db. Make sure that the new user is a superuser and that you spell the name correctly.

  3. Create a database named fizzyo_db. This step is required by postgres, we won't use this database in the future.

  4. Now you should be able to log in into PostgreSQL as the user we just created: fizzyo_db. Change the password to something simple (the password doesn't have to be secure since you are the only person who will access the database).

    • If you have access to the Postgres shell, you can use the \password command after logging in as fizzyo_db.
    • If you're on Linux, you might have to change the password twice: Once for the PostgreSQL user and once for the Unix user.
  5. Make sure you're logged in as fizzyo_db user, then create two databases – one for testing and the other for development. The respective SQL commands are:

    CREATE DATABASE fizzyo_local_test; 
    CREATE DATABASE fizzyo_local_dev; 
  6. Now we need to upload a schema to fizzyo_local_dev and populate it with some dummy data. This is the bare minimum required for the app to function correctly. To do that, you'll need to go to your Fizzyo-backend folder and execute the db/schema.sql and db/dummy-data.sql against the database, in that order.

    • To run an .sql script against the database, you can either use psql command line tool or use a PostgreSQL database editor like DataGrip.
    • fizzyo_local_test is populated automatically, so we don't need to do anything about it.
  7. Go to your local Fizzyo-backend install (step 2 from this guide). In your config.json, change two lines as shown below. I will assume your password is 123456, change it to match whatever you set.

    "devDbUrl": "postgres://fizzyo_db:123456@localhost:5432/fizzyo_local_dev", 
    "testDbUrl": "postgres://fizzyo_db:123456@localhost:5432/fizzyo_local_test", 
    • If you don't have a config.json, make a copy of config.example.json and renamed it into config.json.
  8. Now, install all dependencies using npm install and run all tests using npm run test-all.

  9. If all tests passed for you, you have successfully setup a local database instance.