fxa/packages/fxa-auth-db-mysql
Barry Chen 9593c9f0e5
Release 1.223.2
2022-01-11 17:18:14 -06:00
..
.vscode feat: add vscode tasks for running tests and debugger 2019-10-01 17:27:41 -07:00
bin feat(fxa-shared): Allows sentry events for critical endpoints to be 'tagged' as such. 2021-12-16 13:49:11 -08:00
config chore(deps): updated dependencies 2020-06-22 17:11:50 -07:00
db-server Feedback 2021-12-14 11:14:37 -04:00
docs Feedback 2021-12-14 11:14:37 -04:00
lib Feedback 2021-12-14 11:14:37 -04:00
scripts chore(deps): switch from git to https for deps (#11587) 2022-01-11 16:28:42 -06:00
test chore(auth-server): fly away bluebird 2021-06-24 17:45:01 -07:00
.eslintrc task(monorepo): eslint consolidation 2019-11-15 23:24:09 +00:00
.migration-lint-ignore.json feat(scripts): lint-ignore tables that already have foreign keys 2018-11-28 11:19:07 +00:00
.nsprc fix(deps): Add exception for yargs-parser nsp advisory 1500 2020-05-11 11:40:27 -07:00
.prettierignore chore(style): added prettier to fxa-auth-db-mysql 2019-06-25 09:36:41 -07:00
AUTHORS fix(docs): update authors and node.js version in README 2017-05-01 12:31:29 -04:00
CHANGELOG-server.md chore(style): added prettier to fxa-auth-db-mysql 2019-06-25 09:36:41 -07:00
CHANGELOG.md Release 1.223.2 2022-01-11 17:18:14 -06:00
CONTRIBUTING.md chore(docs): Replace 'master' with 'main' throughout 2020-06-25 13:44:28 -07:00
LICENSE Add the full text of the MPL 2.0 2014-09-23 03:37:09 +12:00
README.md feat(auth): convert remaining auth-server db use to direct db access 2021-06-23 10:44:14 -07:00
index.js chore(format): mass reformat with prettier 2 and single config 2020-05-24 10:51:57 -07:00
package.json Release 1.223.2 2022-01-11 17:18:14 -06:00

README.md

Firefox Accounts database service

Deprecated!

This service is no longer used by auth-server and is in the process of being dismantled. DB migration .sql files should be the only new additions here for the time being. New DB API work should be done in fxa-shared/db.


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

Prerequisites

  • node.js 14
  • npm
  • MySQL (we use version 5.6.42 in production)

Testing

This package uses Mocha to test its code. By default npm test will run all NPM test scripts and then lint the code:

  • npm run test-mysql will test database code under test/backend and test/local.
  • npm run test-server will test server code under db-server/test/local.

Test specific tests with the following commands:

# Test only test/lib/log.js
./scripts/mocha-coverage.js test/lib/log.js

# Grep for "error module" under db-server/test
./scripts/mocha-coverage.js db-server/test/*/** -g "error module"

Refer to Mocha's CLI documentation for more advanced test configuration.

API Server

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

To run the server tests:

npm run test-server

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.

License

MPL 2.0