Enter the postgres console:
psql postgres
Then run the following SQL commands inside postgres:
CREATE ROLE root WITH LOGIN PASSWORD 'password';
create database petbnb;
./init-db.sh
> cd petbnb
> node app.js
Open the app here: http://localhost:8080/
You're done!
\
npm install
We're using knex to deal with database migrations
Run this to make sure your database schema is up to date
node_modules/.bin/knex migrate:latest
Refer to this instructions for making new changes to the database schema
node_modules/.bin/knex migrate:make <file-name>
For example, if you're creating a new migration file to create a table called "pet", then you would probably run this:
node_modules/.bin/knex migrate:make pet
The output should be something like this:
Created Migration: /Users/sherryxy/Desktop/UBC/cpsc304/cpsc-304/migrations/20200330210715_pet.js
So you can go to that file and write the SQL for the migration. Refer to this sample migration file. The "up" function is for running the migration, and the "down" function is for rollbacks (undoing whatever you did in "up").
To run the migration you just created, simply run:
node_modules/.bin/knex migrate:latest
Database seeds are useful to initialize the database with initial data, or reset the database with the initial data after making changes to the database. We're again using knex to deal with database seeds.
node_modules/.bin/knex seed:run
Refer to this instruction to make changes to the seed data or to generate seed data for new tables.
node_modules/.bin/knex seed:make <file-name>
For example, if you're creating a new seed file to populate a table called "pet", then you'd do this:
node_modules/.bin/knex seed:make pet
The output should be something like this:
Created seed file: /Users/sherryxy/Desktop/UBC/cpsc304/cpsc-304/seeds/petOwner.js
So you can go to that file and write some scripts/SQL for the seed data. Refer to this sample seed file.
To run the seed you just created, simply run:
node_modules/.bin/knex seed:run