deb*_*lis 35
没有内置的东西.我现在所做的与Rails的工作方式类似,但是作为启动的一部分而不是单独的任务.首先创建一个Meteor.Collection名为Migrations,然后为每个离散迁移,server在启动时运行的子目录下创建一个函数.它应该只在以前没有运行的情况下运行迁移,并且应该在迁移集合完成后标记迁移.
// database migrations
Migrations = new Meteor.Collection('migrations');
Meteor.startup(function () {
if (!Migrations.findOne({name: "addFullName"})) {
Users.find().forEach(function (user) {
Users.update(user._id, {$set: {fullname: users.firstname + ' ' + users.lastname}});
});
Migrations.insert({name: "addFullName"});
}
});
Run Code Online (Sandbox Code Playgroud)
您可以扩展这种技术支持下迁移(寻找特定迁移的存在和扭转它),实施对迁移排序顺序,以及每个迁移拆分成一个独立的文件,如果你想要的.
考虑一个用于自动化的智能软件包会很有趣.
正如Aram已经在评论中指出的那样,迁移包可以为您提供所需的内容.样品
Migrations.add({
version: 1,
name: 'Adds pants to some people in the db.',
up: function() {//code to migrate up to version 1}
down: function() {//code to migrate down to version 0}
});
Migrations.add({
version: 2,
name: 'Adds a hat to all people in the db who are wearing pants.',
up: function() {//code to migrate up to version 2}
down: function() {//code to migrate down to version 1}
});
Run Code Online (Sandbox Code Playgroud)
我为此用例创建了一个智能包。
参见https://atmosphere.meteor.com/package/migrations