Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created October 11, 2019 14:12
Show Gist options
  • Save rwaldron/6a1dc20f217de2634a49e88e494e3fa9 to your computer and use it in GitHub Desktop.
Save rwaldron/6a1dc20f217de2634a49e88e494e3fa9 to your computer and use it in GitHub Desktop.

Teacher Moments

Development

Local Setup

  1. Install Node.js (version >=10.0.0).
  2. Install yarn (version >=1.19.x): npm install yarn@latest -g
  3. Install Dependencies: yarn install
  4. Set up local database: Local Database Setup
  5. Start the development server
    • This is the list of all environment variables that are are pre-populated in config/dev, need to be exported prior to running the Teacher Moments server:
      PGUSER=
      PGPASSWORD=
      PGDATABASE=
      PGHOST=
      PGPORT=
      
      export AWS_PROFILE=
      export S3_BUCKET=
      
    • If you are using Mac or Linux, export the required environment variables first:
      export $(cat config/dev)
      
    • And then run the dev server with:
      yarn dev
      
    • All at once:
      export $(cat config/dev); yarn dev
      
      ...You should see your local site at http://localhost:3000.

Build

yarn build

Linting Code

This project uses Eslint for linting. To catch syntax and style errors, run

yarn lint

Local Database Setup

  1. Export config/dev

    export $(cat config/dev);
    

    You may need to run:

    export PGUSER=`whoami`;
    
  2. Install PostgreSQL (unless already installed)

    ...Make sure that the Postgres version installed is 11.4.

  3. Start PostgreSQL and make yourself a default database

  • Mac:
    brew services start postgresql
    createdb # creates a default database under your user name
    
  • Linux
    sudo su postgres
    createuser --interactive # enter your username and make yourself a super user
    su yourusername
    createdb # creates a default database under the current user
    
  1. Initialize local database The following should be run with a $PGUSER & $PGPASSWORD for a super user who can create databases and roles (see step 1):
yarn db-init-local

This command creates a database called teachermoments and then sets up a role called tm and then creates all of the tables in teachermoments. To do this manually, create a database called teachermoments: $createdb teachermoments, then create the role tm with a password teachermoments, then run db-migrate up.

Creating Database Migrations

yarn create-migration <migration name>

# Example
yarn create-migration create-users-table

db-migrate tool will subsequently create a JS migration file that can be edited in the migrations folder.

Applying Database Migrations

yarn db-migrate-up

This command can be customized with the following options: https://db-migrate.readthedocs.io/en/latest/Getting%20Started/usage/#running-migrations

Example: Passing a count: npm run db-migrate-down -- -c 1

Reverting Database Migrations

yarn db-migrate-down

This command can be customized with the following options https://db-migrate.readthedocs.io/en/latest/Getting%20Started/commands/#down

S3 Integration

The AWS bucket used for development is called v2-moments-dev. For access, please contact the AWS administrator for TSL.

The app uses for credentials either

  • default credential in your home directory at ~/.aws/credentials with this file format:
[default] #TSL
aws_access_key_id = <your access key id>
aws_secret_access_key = <your secret access key id>
  • or set the environment variable AWS_PROFILE
export AWS_PROFILE=tsl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment