{"id":22080457,"url":"https://github.com/msmesnik/reconsider","last_synced_at":"2026-04-06T04:06:03.783Z","repository":{"id":57349287,"uuid":"53737185","full_name":"msmesnik/reconsider","owner":"msmesnik","description":"A minimalistic promise based database migration tool for rethinkdb","archived":false,"fork":false,"pushed_at":"2017-04-26T11:01:41.000Z","size":432,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T11:11:14.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msmesnik.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-12T14:59:37.000Z","updated_at":"2018-07-06T11:19:31.000Z","dependencies_parsed_at":"2022-08-29T18:41:30.142Z","dependency_job_id":null,"html_url":"https://github.com/msmesnik/reconsider","commit_stats":null,"previous_names":["daerion/reconsider"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/msmesnik/reconsider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmesnik%2Freconsider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmesnik%2Freconsider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmesnik%2Freconsider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmesnik%2Freconsider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msmesnik","download_url":"https://codeload.github.com/msmesnik/reconsider/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msmesnik%2Freconsider/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266855811,"owners_count":23995556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T23:14:30.250Z","updated_at":"2026-04-06T04:06:03.613Z","avatar_url":"https://github.com/msmesnik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reconsider\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n\n**DEPRECATED** -\nUse [adbm](https://github.com/daerion/adbm) in combination with the [adbm-rethinkdb](https://github.com/daerion/adbm-rethinkdb) adapter as a replacement if you're on node \u003e= 7.6.0. Helper functions have been moved to `adbm-rethinkdb/helpers`.\n---\n\nReconsider is a minimalistic promise based database migration tool for rethinkdb that is meant to be called programmatically. Currently there is no CLI for it, though I am willing to add one if there is any sort of demand for it.\n\nReconsider is not currently compatible with the native rethinkdb driver but instead requires [rethinkdbdash](https://github.com/neumino/rethinkdbdash).\n\n## Installation\n```\nnpm install --save reconsider\n```\n\n## Usage\n### Defining Migrations\nEach migration must be a module exporting an object with an `up` and a `down` function, residing in the configured migrations directory (`migrations/` by default). Both methods will be passed the rethinkdb driver instance as their first parameter, and the logger instance as the second one. Since all the database operations performed in a migration are inherently async, both methods must return a Promise.\n\n#### Sample Migration File\n```js\n// File migrations/001-create-tables.js\n\n'use strict'\n\nconst tableName = 'my_table'\n\nmodule.exports = {\n  up: function (r, logger) {\n    logger.verbose(`Creating table ${tableName}.`)\n\n    return r.tableCreate(tableName).run()\n      .then(() =\u003e r.table(tableName).indexCreate('some_property').run())\n  },\n\n  down: function (r, logger) {\n    logger.verbose(`Dropping table ${tableName}.`)\n\n    return r.tableDrop(tableName).run()\n  }\n}\n```\n\n### Running Migrations\nWhen instantiating the Reconsider class, you must provide it with an already connected rethinkdbdash object and a database name. Reconsider will attempt to create both the database and it's own migrations table if either don't exist.\n\n```js\nimport rethinkdb from 'rethinkdbdash'\nimport Reconsider from 'reconsider' // or `const Reconsider = require('reconsider').default`\n\nconst db = 'my_database'\nconst r = rethinkdb({ host: 'localhost', db })\nconst recon = new Reconsider(r, { db })\n```\n\nMigrating up or down is as simple as calling the `migrateUp()` or `migrateDown()` method of the Reconsider instance. Both these methods will return a promise that resolves to an array of operation info objects, each one of them containing an `id` and an `elapsed` property.\nWhen migrating up, Reconsider will attempt to run all pending migrations found in the `migrations/` directory of the current process by default. When migrating down, Reconsider will revert all migrations stored in the `_reconsider_migration` table.\nOnce a migration has been run successfully, it will not be run again on subsequent invocations of the `migrateUp` method, unless it has been reverted via `migrateDown()`.\n\n```js\n// Run all pending migrations\nrecon.migrateUp().then((ops) =\u003e console.dir(ops))\n\n// Or, if you're using babel\nconst ops = await recon.migrateUp()\n\n// ops will be something like this\n[{\n  id: '001-create-tables',  // id of the migration\n  elapsed: 7.597834  // Time it took for the migration to complete (in seconds)\n}, {\n  id: '002-add-initial-values',\n  elapsed: 0.0123168\n}]\n```\n\n### Configuration Options\nCurrently, the config object passed into the Reconsider constructor supports the following properties:\n\n| Property | Default | Description |\n| --- | --- | --- |\n| `db` |  | Database name (*required*)  |\n| `sourceDir` | `migrations/` | Directory containing the migrations |\n| `tableName` | `_reconsider_migration` | Database table containing information about previously run migrations |\n| `logLevel` | `info` | Minimum log level |\n\n### Error Handling\nReconsider does **not** catch any errors on purpose, it is the caller's responsibility to handle errors appropriately. The basic reason for this is that handling migration errors would either involve too much guesswork or introduce a host of new config options for no good reason (Revert everything? Don't revert anything? Attempt to call the failed migration's `down` method?).\n\n```js\nrecon.migrateUp()\n  .then((ops) =\u003e console.dir(ops))\n  .catch((err) =\u003e {\n    // Handle error here\n  })\n```\n\nOne consequence of Reconsider's lack of error catching is that an error in any migration will prevent all subsequent migrations from running. This, too, is intended behavior, since database migrations will more often than not rely on changes introduced by previous migrations. Since no automatic rollback is performed, and since all successful migrations will still register, `migrateUp` and `migrateDown` can safely be called again once the problem has been resolved.\n\nThis should also encourage the user to write small migrations that change one thing at a time, as opposed to huge migration files with several chained `.then`s.\n\n### Logging\nReconsider will output various messages to stdout by default, using `console.log`, `console.info` and `console.warn` as appropriate. All output is categorized into one of the following log levels: `debug`, `verbose`, `info`, `warn`, `error`. Minimum log level can be set via the `logLevel` config option.\n\n``` js\n// Use built in logger, don't output anything below \"info\" level (default config)\nconst recon = new Reconsider(r, {\n  db: 'my_database',\n  logLevel: 'info'\n})\n\n// Disable logging\nconst recon = new Reconsider(r, { db: 'my_database' }, false)\n```\n\nAlternatively, you can provide a custom logger implementation, e.g. an instance of [winston](https://github.com/winstonjs/winston) or similar. When doing so, the provided object must implement methods for all supported log levels. Note that setting a `logLevel` via the config object will have no effect in this case, since Reconsider will assume that your logger has already been configured appropriately.\n\n```js\n// Provide custom logger implementation\nconst myLoggerInstance = getLoggerInstanceSomehow()\nconst recon = new Reconsider(r, { db: 'my_database' }, myLoggerInstance)\n```\n\n## Helpers\nAs of version 1.1.0, Reconsider includes a small set of helper functions meant to simplify and automate common database migration tasks, namely creating tables or indices. 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.  \n\n### createTablesMigration\nThis 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.\n\n```js\n// In file migrations/xx-create-tables.js\nconst { helpers } = require('reconsider')\n\nmodule.exports = helpers.createTablesMigration([ 'first_table', 'second_table' ])\n````\n\n### createIndexMigration\nThis 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.\nAn `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.\n\n```js\n// In file migrations/xx-create-indices.js\nconst { helpers } = require('reconsider')\nconst table = 'first_table'\n\nmodule.exports = helpers.createIndexMigration([\n    { table, index: 'someProp' }, // Simple index\n    { table, index: 'compoundIndex', spec: (r) =\u003e [ r.row('firstProp'), r.row('secondProp') ] }, // Compound index\n    { table, index: 'geoProp', options: { geo: true } }, // Geo index\n    { table, index: 'multiIndex', options: { multi: true } }, // Multi index\n    { table, index: 'arbitraryExpr', spec: (r) =\u003e (doc) =\u003e r.branch(doc.hasFields('foo'), doc('foo'), doc('bar')) } // Index based on an arbitrary expression\n])\n```\n\n## Testing\nA simple Vagrant VM running a RethinkDB server has been included in the `test/misc` folder.\n \n```\nnpm run test\n```\n\n## API Docs\nOfficial API documentation lives [here](https://daerion.github.io/reconsider).\n\n## Author\n[Michael Smesnik](https://github.com/daerion)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsmesnik%2Freconsider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsmesnik%2Freconsider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsmesnik%2Freconsider/lists"}