{"id":26938742,"url":"https://github.com/meteor/meteor-migrations","last_synced_at":"2025-04-09T15:02:21.019Z","repository":{"id":13120455,"uuid":"15802298","full_name":"meteor/meteor-migrations","owner":"meteor","description":"Simple migration system for Meteor","archived":false,"fork":false,"pushed_at":"2024-07-31T16:56:18.000Z","size":140,"stargazers_count":244,"open_issues_count":17,"forks_count":60,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-09T15:00:55.851Z","etag":null,"topics":["hacktoberfest","meteor"],"latest_commit_sha":null,"homepage":"https://atmospherejs.com/percolate/migrations","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/meteor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2014-01-10T15:56:10.000Z","updated_at":"2025-03-31T22:25:50.000Z","dependencies_parsed_at":"2025-01-12T16:04:13.715Z","dependency_job_id":"3bc73015-4448-4747-acf2-7afdb5d2de50","html_url":"https://github.com/meteor/meteor-migrations","commit_stats":{"total_commits":116,"total_committers":30,"mean_commits":"3.8666666666666667","dds":0.6982758620689655,"last_synced_commit":"57e6b08aecb2ab9f6ce6ca063b6617d90892494e"},"previous_names":["meteor/meteor-migrations"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fmeteor-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fmeteor-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fmeteor-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fmeteor-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meteor","download_url":"https://codeload.github.com/meteor/meteor-migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040156,"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":["hacktoberfest","meteor"],"created_at":"2025-04-02T14:13:42.528Z","updated_at":"2025-04-09T15:02:20.983Z","avatar_url":"https://github.com/meteor.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# percolate:migrations\n\n[![Build Status](https://travis-ci.org/percolatestudio/meteor-migrations.svg?branch=master)](https://travis-ci.org/percolatestudio/meteor-migrations)\n\nA simple migration system for [Meteor](http://meteor.com) supporting up/downwards migrations and command line usage. There is also [a fork available](https://github.com/emmanuelbuah/mgdb-migrator) for use outside of Meteor.\n\n## Installation\n\nMeteor Migrations can be installed through Meteor's package manager. Type:\n\n``` sh\n$ meteor add percolate:migrations\n```\n\n## API\n\n### Basics\n\nTo write a simple migration, somewhere in the server section of your project define:\n\n``` javascript\nMigrations.add({\n  version: 1,\n  up: function() {//code to migrate up to version 1}\n});\n```\n\nTo run this migration from within your app call:\n\n``` javascript\nMeteor.startup(() =\u003e {\n  Migrations.migrateTo('latest');\n});\n```\n\n### Advanced\n\nA more complete set of migrations might look like:\n\n``` javascript\nMigrations.add({\n  version: 1,\n  name: 'Adds pants to some people in the db.',\n  up: function() {//code to migrate up to version 1}\n  down: function() {//code to migrate down to version 0}\n});\n\nMigrations.add({\n  version: 2,\n  name: 'Adds a hat to all people in the db who are wearing pants.',\n  up: function() {//code to migrate up to version 2}\n  down: function() {//code to migrate down to version 1}\n});\n```\n\nAs in 'Basics', you can migrate to the latest by running:\n\n``` javascript\nMeteor.startup(function() {\n  Migrations.migrateTo('latest');\n});\n```\n\n*Note: Migrations should be run from `Meteor.startup` to allow for log output configuration.*\n\nBy specifying a version, you can migrate directly to that version (if possible). The migrations system will automatically determine which direction to migrate in.\n\nIn the above example, you could migrate directly to version 2 by running:\n\n``` javascript\nMigrations.migrateTo(2);\n```\n\nIf you wanted to undo all of your migrations, you could migrate back down to version 0 by running:\n\n``` javascript\nMigrations.migrateTo(0);\n```\n\nSometimes (usually when somethings gone awry), you may need to re-run a migration. You can do this with the rerun subcommand, like:\n\n``` javascript\nMigrations.migrateTo('3,rerun');\n```\n\n**NOTE**: You cannot create your own migration at version 0. This version is reserved by migrations for a 'vanilla' system, that is, one without any migrations applied.\n\nTo see what version the database is at, call:\n\n``` javascript\nMigrations.getVersion();\n```\n\n### Configuration\n\nYou can configure Migrations with the `config` method. Defaults are:\n\n``` javascript\nMigrations.config({\n  // Log job run details to console\n  log: true,\n\n  // Use a custom logger function (defaults to Meteor's logging package)\n  logger: null,\n\n  // Enable/disable logging \"Not migrating, already at version {number}\"\n  logIfLatest: true,\n\n  // migrations collection name to use in the database\n  collectionName: \"migrations\"\n});\n```\n\n### Logging\n\nMigrations uses Meteor's `logging` package by default. If you want to use your\nown logger (for sending to other consumers or similar) you can do so by\nconfiguring the `logger` option.\n\nMigrations expects a function as `logger`, and will pass arguments to it for\nyou to take action on.\n\n```js\nvar MyLogger = function(opts) {\n  console.log('Level', opts.level);\n  console.log('Message', opts.message);\n  console.log('Tag', opts.tag);\n}\n\nMigrations.config({\n  logger: MyLogger\n});\n\nMigrations.add({ name: 'Test Job', ... });\n```\n\nThe `opts` object passed to `MyLogger` above includes `level`, `message`, and `tag`.\n\n- `level` will be one of `info`, `warn`, `error`, `debug`.\n- `message` is something like `Finished migrating.`.\n- `tag` will always be `\"Migrations\"` (handy for filtering).\n\n### Custom collection name\n\nBy default, the collection name is **migrations**. There may be cases where this is inadequate such as using the same Mongo database for multiple Meteor applications that each have their own set of migrations that need to be run.\n\n### Command line use\n\n*** DEPRECATED ***\n\nThis info is for pre 0.9 users as post 0.9 the `migrate.sh` script is no longer included in the package folder.\n\nYou can also run migrations from the command line using the included shell script. This will\n\n1. Launch your Meteor app\n2. Call `Migrations.migrateTo(version)`\n3. Exit your app\n\nFor instance, from your project's root, run:\n\n``` sh\n$ ./packages/percolatestudio-migrations/migrate.sh latest\n```\n\nYou can also specify additional arguments to be passed into meteor, like:\n\n``` sh\n$ ./packages/percolatestudio-migrations/migrate.sh latest --settings ./setting.json\n```\n\n### Errors\n1. `Not migrating, control is locked`\n\n  Migrations set a lock when they are migrating, to prevent multiple instances of your clustered app from running migrations simultaneously. If your migrations throw an exception, you will need to manually remove the lock (and ensure your db is still consistent) before re-running the migration.\n  \n  From the mongo shell update the migrations collection like this:\n\n  ```\n  $ meteor mongo\n\n  db.migrations.update({_id:\"control\"}, {$set:{\"locked\":false}});\n  exit\n  ```\n  \n  Alternatively you can unlock the collection from either server code or the meteor shell using:\n\n  ```\n  Migrations.unlock();\n  ```\n\n### Threading and Callbacks\nThe following is example code to wait for asynchronous code to complete prior to going on to next migration.\n\n```js\nMigrations.add({\n  version: 1,\n  up: Meteor.wrapAsync(async (_, next) =\u003e {\n    await doSomethingAsynchonously();\n    next();\n  }),\n  down: Meteor.wrapAsync(async (_, next) =\u003e {\n    await doDownAsynchronously();\n    next();\n  }),\n});\n```\n\nFor Meteor 2.8+ you can pass async function directly.\n\n* Note: You may want to call migration after startup in case your host (such as Heroku) limits the amount of time given for startup\n``` javascript\nMeteor.startup(function() {\n  setTimetout(\"Migrations.migrateTo('latest')\", 0);\n});\n```\n\n\n## License\n\nMIT. (c) Percolate Studio, Meteor Software\n\nMeteor Migrations was developed as part of the [Verso](http://versoapp.com) project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeteor%2Fmeteor-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeteor%2Fmeteor-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeteor%2Fmeteor-migrations/lists"}