herteby:migrate

v1.0.4Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Migrate

Ultra-simple way to create migrations that run only once

meteor add herteby:migrate
1import migrate from 'meteor/herteby:migrate'
2
3migrate([
4  ()=>{ //We don't use these thumbnails anymore
5    Files.update({'copies.thumbnail':{$exists:true}}, {$unset:{'copies.thumbnail':1}, {multi:true})
6  },
7  ()=>{
8    Posts.find({user:{$exists:true}}).forEach(post => { //rename the "user" field to "userId"
9    	Posts.update(post._id, {$set:{userId:post.user}, {$unset:{user:1}}})    
10    })
11  }
12  //etc...
13])

migrate() can be called with either a single function or an array of functions

When migrate() is run, it turns each function into a string, and checks for a match in the _migrations collection. If no match is found, it executes the function and then adds the string to _migrations. If any edit is done to the function (except spacing, indentation, comments and semicolons) it will count as new and be executed again.