MySql backend for the fxa-auth-db-server
JavaScript PLpgSQL SQLPL Shell
Latest commit 70dcc5b Feb 24, 2017 @vladikoff vladikoff committed on GitHub feat(sessions): update the sessions query to include device informati…
…on (#203) r=vbudhram

Connects to mozilla/fxa-content-server#4585
Permalink
Failed to load latest commit information.
bin feat(eventLog): Remove the unused "eventLog" feature. Nov 7, 2016
config feat(tokens): add prune token maxAge and update pruning (#206); r=rfk Feb 15, 2017
docs feat(db): add emailBounces table Feb 8, 2017
fxa-auth-db-server feat(sessions): update the sessions query to include device informati… Feb 24, 2017
grunttasks chore(lint): Include ./bin/*.js in eslint coverage Nov 7, 2016
lib feat(sessions): update the sessions query to include device informati… Feb 24, 2017
scripts fix(scripts): add process.exit to populate script Aug 19, 2016
test fix(email): Return `createdAt` when calling db.emailRecord (#209), r=@… Feb 23, 2017
.dockerignore feat(docker): Additional Dockerfile for self-hosting Jan 21, 2016
.eslintrc chore(eslint): change complexity rule Sep 2, 2015
.gitignore fix(tests): switch coverage tool, add coveralls (#145) r=vbudhram Jul 20, 2016
.travis.yml chore(travis): add node 6 explicitly to travis (#175) r=vladikoff Sep 30, 2016
AUTHORS chore(project): merge db-server project admin/config stuff to top level Aug 4, 2015
CHANGELOG-server.md chore(project): merge db-server project admin/config stuff to top level Aug 4, 2015
CHANGELOG.md Release v0.81.0 Feb 23, 2017
CONTRIBUTING.md docs(contributing): Mention git commit guidelines Jan 21, 2016
Dockerfile feat(docker): Dockerfile and README update for basic docker developme… Feb 18, 2015
Gruntfile.js chore(project): merge db-server project admin/config stuff to top level Aug 4, 2015
LICENSE Add the full text of the MPL 2.0 Sep 22, 2014
README.md chore(readme): update travis status badge url Jul 19, 2016
index.js reshuffle package.json Aug 6, 2015
npm-shrinkwrap.json Release v0.81.0 Feb 23, 2017
package.json Release v0.81.0 Feb 23, 2017

README.md

Firefox Accounts database service

Build Status

Node.js-based database service for Firefox Accounts. Includes:

  • The API server. Also published independently via npm as fxa-auth-db-server, to enable use with alternative backend storage.
  • A memory-store backend. Useful as a stub for testing against.
  • A MySQL backend. Used in production.

To run the tests for all components:

npm test

Prerequisites

  • Node.js 0.10 or later
  • npm
  • MySQL (we use version 5.6.21 in production)

API Server

See the API documentation. Backend implementers should also read the database documentation.

For example usage, see the readme.

To run the server tests:

npm run test-server

Memory-store backend

Implements the backend API as a memory store.

This is the backend store that is loaded by the default export from the npm package, so the following call to require will return a server that uses the memory-store backend:

var fxadb = require('fxa-auth-db-mysql')

To run the memory-store tests:

npm run test-mem

MySQL backend

Implements the backend API as a MySQL database.

To run the MySQL tests:

npm run test-mysql

Configuration

Both the server and the database patcher read values from a config file config/$NODE_ENV.json, where NODE_ENV is an environment variable set in the shell.

For local development, set NODE_ENV to dev then create a new JSON file called config/dev.json. In there, you can set any values that you'd like to override the master config file, config/config.js.

For instance:

{
  "master": {
    "user": "root",
    "password": "foo"
  },
  "slave": {
    "user": "root",
    "password": "bar"
  }
}

Starting the server

You can start the server like so:

npm start

This will set up the database for you then start the server on whichever port is configured in config/$NODE_ENV.json (port 8000 by default).

If the server fails to start, check that MySQL is running and that your active config has the correct settings to connect to the database.

Setting-up the database separately

If you want to run the database patcher on its own, use the following command:

node bin/db_patcher.js

This command creates the database if it doesn't exist, then runs migrations from lib/db/schema in the appropriate order. Both forward and reverse migrations are contained in this directory, but note that the reverse migrations are commented out as a precaution against accidental execution.

If the command fails, check that MySQL is running and that your active config has the correct settings to connect to the database.

Clean-up

If you want to clean the database, just drop it in MySQL:

mysql -u root -p -e 'DROP DATABASE fxa'

It will be recreated automatically next time you run npm start.

Docker-based development

To run the MySQL backend inside a container, use the following commands:

docker build --rm -t mozilla/fxa_auth_db_mysql .
docker run --rm -v $PWD:/opt/fxa mozilla/fxa_auth_db_mysql npm install
docker run -it --rm -v $PWD:/opt/fxa --net=host mozilla/fxa_auth_db_mysql

This method shares the codebase into a container and runs the MySQL backend inside it. You can npm install and edit code in your normal desktop environment and the changes will be picked up automatically.

License

MPL 2.0