{"id":16060529,"url":"https://github.com/nodepit/node-migrate-state-store-mongodb","last_synced_at":"2025-03-16T07:32:36.296Z","repository":{"id":37768212,"uuid":"159838206","full_name":"NodePit/node-migrate-state-store-mongodb","owner":"NodePit","description":"MongoDB-based state storage implementation for the migrate aka. node-migrate framework","archived":false,"fork":false,"pushed_at":"2024-08-30T13:26:19.000Z","size":912,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-15T10:33:03.196Z","etag":null,"topics":["migration","mongodb","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/NodePit.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-30T14:55:08.000Z","updated_at":"2024-08-30T13:26:16.000Z","dependencies_parsed_at":"2024-09-02T13:01:20.885Z","dependency_job_id":"c52268b7-f63b-4fd9-b093-e8ba408736a1","html_url":"https://github.com/NodePit/node-migrate-state-store-mongodb","commit_stats":{"total_commits":114,"total_committers":4,"mean_commits":28.5,"dds":"0.26315789473684215","last_synced_commit":"7278386397e42968196e5083fe6de8109f64ede3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodePit%2Fnode-migrate-state-store-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodePit%2Fnode-migrate-state-store-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodePit%2Fnode-migrate-state-store-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NodePit%2Fnode-migrate-state-store-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NodePit","download_url":"https://codeload.github.com/NodePit/node-migrate-state-store-mongodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841156,"owners_count":20356441,"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","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":["migration","mongodb","nodejs"],"created_at":"2024-10-09T04:05:10.411Z","updated_at":"2025-03-16T07:32:35.890Z","avatar_url":"https://github.com/NodePit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-migrate state storage for MongoDB\n\n[![Actions Status](https://github.com/NodePit/node-migrate-state-store-mongodb/workflows/CI/badge.svg)](https://github.com/NodePit/node-migrate-state-store-mongodb/actions)\n[![codecov](https://codecov.io/gh/NodePit/node-migrate-state-store-mongodb/branch/master/graph/badge.svg)](https://codecov.io/gh/NodePit/node-migrate-state-store-mongodb)\n[![npm version](https://badge.fury.io/js/%40nodepit%2Fmigrate-state-store-mongodb.svg)](https://badge.fury.io/js/%40nodepit%2Fmigrate-state-store-mongodb)\n\nThis is a [state storage implementation](https://github.com/tj/node-migrate#custom-state-storage) for the [`node-migrate`](https://github.com/tj/node-migrate) framework. It will store your migation state in a MongoDB collection called `migrations` which contains a single document.\n\nIn case you’re using `node-migrate` for migrating your MongoDB, it makes sense to keep the state within the database itself, instead of a separate file which is used by `node-migrate` per default.\n\n## Installation\n\n```shell\n$ yarn add @nodepit/migrate-state-store-mongodb\n```\n\n## Usage\n\nEither create a wrapper script such as `run-migrations.ts` which calls the migration API like so:\n\n```javascript\nimport * as migrate from 'migrate';\nimport { MongoStateStore } from '@nodepit/migrate-state-store-mongodb';\n\nmigrate.load({\n  stateStore: new MongoStateStore(MONGODB_HOST),\n  // further configuration …\n}, (err, set) =\u003e {\n  // your code …\n});\n```\n\nPer default, the migrations are stored in a collection called `migrations`. If you want to customize the collection name, instantiate the `MongoStateStore` with an object instead:\n\n\n```javascript\nnew MongoStateStore({ uri: MONGODB_HOST, collectionName: 'custom-migrations-collection' });\n```\n\n## Synchronization\n\nIf you’re running in a clustered environments with more than one node, there will likely be concurrency issues when more than one node tries to run a migration (also see [here](https://github.com/NodePit/node-migrate-state-store-mongodb/issues/30)). The plugin provides a locking mechanism which ensures that only one node can run migrations at a given time (and other ones will just wait until the migration has finished). For this, initialize `MongoStateStore` with a `lockCollectionName`:\n\n```javascript\nnew MongoStateStore({\n  uri: MONGODB_HOST,\n  collectionName: 'migrations',\n  lockCollectionName: 'migrationlock'\n});\n```\n\n… then use the `synchronizedUp` function instead of calling `migrate.load` and `set.up` directly to ensure that the migration is only run on one instance at a time:\n\n```javascript\nimport { MongoStateStore, synchronizedUp } from '@nodepit/migrate-state-store-mongodb';\n\nawait synchronizedUp({ stateStore: mongoStateStore });\n```\n\n## CLI Usage\n\nAlternatively, you can also pass the store on the `migrate` CLI using the `--store` flag. For that, create a a file which has as default export a configured subclass with a zero-arg constructor of the `MongoStateStore`. See [here](https://github.com/NodePit/node-migrate-state-store-mongodb/issues/9#issuecomment-658018332) for details. You can then call `migrate up --store=./my-store.js`. Locking is not available in this case.\n\n## Development\n\nInstall NPM dependencies with `yarn`.\n\nTo execute the tests, run the `test` task.\n\nFor the best development experience, make sure that your editor supports [ESLint](https://eslint.org/docs/user-guide/integrations) and [EditorConfig](http://editorconfig.org).\n\n## Releasing to NPM\n\nCommit all changes and run the following:\n\n```shell\n$ npm login\n$ npm version \u003cupdate_type\u003e\n$ npm publish --access public\n```\n\n… where `\u003cupdate_type\u003e` is one of `patch`, `minor`, or `major`. This will update the `package.json`, and create a tagged Git commit with the version number.\n\n\n## Contributing\n\nPull requests are very welcome. Feel free to discuss bugs or new features by opening a new [issue](https://github.com/NodePit/node-migrate-state-store-mongodb/issues).\n\n- - -\n\nCopyright [nodepit.com](https://nodepit.com), 2018 – 2023.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodepit%2Fnode-migrate-state-store-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodepit%2Fnode-migrate-state-store-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodepit%2Fnode-migrate-state-store-mongodb/lists"}