{"id":22616306,"url":"https://github.com/xpepermint/migratablejs","last_synced_at":"2025-08-04T10:40:20.018Z","repository":{"id":57296963,"uuid":"97989264","full_name":"xpepermint/migratablejs","owner":"xpepermint","description":"General purpose migration framework.","archived":false,"fork":false,"pushed_at":"2017-10-27T21:20:20.000Z","size":22,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T11:34:30.699Z","etag":null,"topics":["javascript","migrating","migration","migrations","nodejs","patch","patcher","patching","seed","seeding","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xpepermint.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-21T21:52:22.000Z","updated_at":"2024-06-10T01:33:56.000Z","dependencies_parsed_at":"2022-09-01T13:01:47.685Z","dependency_job_id":null,"html_url":"https://github.com/xpepermint/migratablejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xpepermint/migratablejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fmigratablejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fmigratablejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fmigratablejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fmigratablejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xpepermint","download_url":"https://codeload.github.com/xpepermint/migratablejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fmigratablejs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268682999,"owners_count":24289722,"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-08-04T02:00:09.867Z","response_time":79,"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":["javascript","migrating","migration","migrations","nodejs","patch","patcher","patching","seed","seeding","typescript"],"created_at":"2024-12-08T19:12:04.184Z","updated_at":"2025-08-04T10:40:19.968Z","avatar_url":"https://github.com/xpepermint.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build Status](https://travis-ci.org/xpepermint/migratablejs.svg?branch=master)\u0026nbsp;[![NPM Version](https://badge.fury.io/js/migratable.svg)](https://badge.fury.io/js/migratable)\u0026nbsp;[![Dependency Status](https://gemnasium.com/xpepermint/migratablejs.svg)](https://gemnasium.com/xpepermint/migratablejs)\n\n# Migratable.js\n\n\u003e General purpose migration framework.\n\nThis is a light weight open source package for NodeJS written with [TypeScript](https://www.typescriptlang.org). It's actively maintained, well tested and already used in production environments. The source code is available on [GitHub](https://github.com/xpepermint/migratablejs) where you can also find our [issue tracker](https://github.com/xpepermint/migratablejs/issues).\n\n## Installation\n\nRun the command below to install the package.\n\n```\n$ npm install --save migratable\n```\n\nThis package uses promises thus you need to use [Promise polyfill](https://github.com/taylorhakes/promise-polyfill) when promises are not supported.\n\n## Usage\n\nThe package provides two core classes. The `Migrator` class is used for running migrations and the `Seeder` is used for performing seed operations.\n\n### Migrations\n\nMigrations are performed in a sequence based on the `index` parameter. If you pass a context object into `Migrator` class the object will be passed to each migration method. Methods `upgrade` and `downgrade` runs migration recipes and memorizes the last successfully performed migration `index` value inside the `./migratable.cache` file (don't forget to add this path to `.gitignore`).\n\n```js\nimport { Migrator } from 'migratable';\n\n// initialize migration class\nconst migrator = new Migrator({\n  ctx: { foo: \"foo\" }, // optional\n  cacheFilePath: \"./migratable.cache\", // optional\n});\n\n// register migrations (you could move this object into a separate file)\nmigrator.add({\n  index: 0, // sequence number\n  upgrade: async (ctx) =\u003e { /* do something */ },\n  downgrade: async (ctx) =\u003e { /* do something */ },\n});\n\n// run `upgrade` migrations\nmigrator.upgrade().then((index) =\u003e { // upgrade optionally accepts the number of steps to perform\n  console.log(\"Done!\");\n}).catch((err) =\u003e {\n  console.log(err);\n});\n// or `downgrade` migrations\nmigrator.downgrade().then((index) =\u003e { // upgrade optionally accepts the number of steps to perform\n  console.log(\"Done!\");\n}).catch((err) =\u003e {\n  console.log(err);\n});\n```\n\nYou can also use `migrator.addDir(\"./seeds\")` to load migrations from folder.\n\n### Seeding\n\nSeed operations are similar to migrations. The difference is only that they can be performed multiple times.\n\n```js\nimport { Seeder } from 'migratable';\n\n// initialize migration class\nconst seeder = new Seeder(\n  ctx: { foo: \"foo\" }, // optional\n);\n\n// register migrations (you could move this object into a separate file)\nseeder.add({\n  index: 0, // sequence number\n  perform: async (ctx) =\u003e { /* do something */ },\n});\n\n// run `perform` methods\nseeder.perform().then(() =\u003e {\n  console.log(\"Done!\");\n}).catch((err) =\u003e {\n  console.log(err);\n});\n```\n\nYou can also use `seeder.addDir(\"./seeds\")` to load seeds from folder.\n\n## License (MIT)\n\n```\nCopyright (c) 2017+ Kristijan Sedlak \u003cxpepermint@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated modelation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Fmigratablejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpepermint%2Fmigratablejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Fmigratablejs/lists"}