Big Poppa is a notorious manager who keeps track of all his users. He knows who owes him money and when it is due. He also stores other attributes for his users and only gives out this information to those he deems worthy.
The first step is to install postgres. From the command-line (on Mac OSX) run the following:
- brew install postgresql- Installs postgresql locally
- initdb /usr/local/var/postgres -E utf8- Initializes a postgres cluster
- ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents- instruct OSX to automatically launch postgres on login.
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist- start postgres on your computer.
Once you have installed postgres you'll need to run the following from the big-poppa project repository directory:
- npm run init-db
This script creates a super user named big_poppa and two databases on your machine:
big_poppa (used for local development) and big_poppa_test (used by the test suite).
big-poppa uses knex to access the postgresql
database. It also uses knex-migrate for
handling migration. You should always use knex-migrate instead of knex for
migrations. knex-migrate allows for finer grain control over which migrations
to run at any given point.
The first thing you'll need to do after installing postgres is to run the knex migrations to create the database schema. From the big-poppa project repository directory run the following:
- npm install- Install required libraries
- npm run migrate- Migrates the test and local development databases to the latest migration.
In order to rollback a migration, do the following:
- Run knex-migrate pendingto list all pending migrations.
- Run knex-migrate listto make sure you're in the correct migration.
- After confirming, you're where you expetecd to be, run npm run rollback(short forknex-migrate down) which will rollback a single migration (a single file).
In order to create a new migration:
- Run knex migrate:make NAME_OF_MIGRATION
- Write your migration. Migrations should be not depend on any other scripts. migrate-...script is an anti-pattern, because it means migrations can't be run correctly.
- Test your migration with knex-migrate redo(rollbacks last migration and re-runs it) with your local database
- Recommended: Test your migration against a local copy of gamma and delta locally
- Test your migration against gamma.
In order to fully test the codebase you will need to install RabbitMQ locally on your machine. Run the following commands to do so:
- brew update
- brew install rabbitmq
Once installed, brew should instruct you on how to ensure that RabbitMQ is launched at reboot and login. Copy the commands from the brew output and execute them on your machine.
For more information see: RabbitMQ Homebrew Install Instructions
The infrastructure data model may change over time due to new constraints. When the schema needs to change you'll have to write your own migrations in order to update the database. While a full treatment of how to write db migrations is outside the scope of this document, we will cover the basic commands you'll need to know in order to do so.
Here is a list of the relevant commands:
- knex migrate:latest- Update the database schema to the latest migration.
- knex migrate:rollback- Rolls the last migration back to the previous state.
- knex migrate:make <name>- Creates a new migration with the given name in the- migrations/directory in the project repository.
The database environment affected is chosen by setting the NODE_ENV
environment variable. By default the development database is changed, here are
the other options for NODE_ENV:
- test- Apply migration changes to the test database
- production- Apply migration changes to the production database
Note that the production environment is not available when developing.
For more information on how to build migrations, take a look at the source code
for the existing migrations in the migrations/ directory and read the
knex schema documentation.
In order to update the big-poppa client, do the following:
- Run npm version ...in the/clientdiretory
- Push your changes to the repository through a PR
- Create and push a new BP version
- Run npm publishin the client directory
There are two testing environments:
- test: Routes all Github API requests through mehpi
- test-integration: Uses a token to make real Github API calls
There are several testing commands:
- npm test: Lints code and runs unit and functional tests
- npm run test-unit: Runs only unit tests.
- npm run test-functional: Runs only functional tests.
- npm run test-integration: Runs only integration tests.
- npm run test-integration-env: Lints code and runs unit and functional test for all services with real GithubAPI calls (- test-integrationENV)
There are three types of tests in this project:
- Unit tests: Tests units of codes and stubs out any external code.
- Functional tests: Tests the complete functionality of a method and only stubs out HTTP calls. Should interact with the database.
- docker inspectanother container in- app-servicesthat runs mongo (pheidi)
- Copy the MONGOenv
- Go to docker container docker exec -it CONTAINER_ID bash
- npm installwhich installs mongoDB from dev dependency (If you get errors connecting to the DB it might be the client version).
- Run the following command: MONGO=MONGO_ENV NODE_PATH=./lib/ node scripts/migrate-user-whitelists-as-orgs.js | bunyan
- Check logs to make sure logs were successfully created
The methods updateOrganization and createOrUpdateUser instead of just returning
object for the model now return an object with two properties model and updates.
In order to migrate your existing code, just get the model properties from model
from the resolve value.
// Before
client.updateOrganization({ hello: 'world' })
	.then(function (model) {  })
// Now
client.updateOrganization({ hello: 'world' })
	.then(function (response) {
		let model = response.model
		let updaptes = response.updates
 	})