adbm-rethinkdb
RethinkDB adapter for adbm database migration tool.
Installation
npm install adbm-rethinkdb
Helpers
This adapter contains a series of helper functions meant to simplify a few common migration tasks. These helper functions have been taken from the now deprecated reconsider module, as has their documentation. Each of these functions will return a database migration object, i.e. an object exposing up
and down
methods, which can then be exported by the migration file.
createTablesMigration
This function will return a migration that will create tables when migrating up and drop these tables when migrating down. createTablesMigration
expects an array of table names.
// In file migrations/xx-create-tables.jsconst helpers = moduleexports = helpers
createIndexMigration
This function will return a migration that will create indices when migrating up and drop these indices when migrating down. createIndexMigration
expects an array of index specifications. Each index specification is an object containing a table
and an index
property, and optionally an options
object and/or a spec
function.
An options
object can be anything that r.indexCreate()
accepts, while the spec
property must be a function that returns an index definition (which, again, can be anything that r.indexCreate()
accepts). spec
will be passed the rethinkdbdash instance when it is executed.
// In file migrations/xx-create-indices.jsconst helpers = const table = 'first_table' moduleexports = helpers
Testing
Running tests requires a rethinkdb database. You can either point the tests to your own rethinkdb server using environment variables (see below) or use the included docker:db
npm script to spin up a docker container called adbm_rethinkdb_dev_db
that will provide you with a basic rethinkdb server. After that, you'll simply want to:
npm run test
Environment Variables
const dbConfig = host: processenvDB_HOST || 'localhost' port: processenvDB_PORT authKey: processenvDB_AUTH_KEY db: processenvDB_NAME || 'adbm_rethinkdb'
I.e. when supplying no configuration, tests will attempt to connect to localhost
on the default port and will attempt to use the adbm_rethinkdb
database (which will be created if it does not already exist).
Author
Michael Smesnik at tailored apps
License
MIT