Vad*_*est 10 database-migration mongodb node.js
我正在寻找一个节点模块来进行mongo数据库迁移.到目前为止,我发现mongo-migrate,但不够强大.(总比没有好,但我需要更多,我习惯使用非常强大的Ruby迁移!)
几个星期前我找到了另一个,功能强大,但没有处理mongoDb,只有MySQL,PostGre等等.
你知道一个可以帮助我的模块或东西吗?我的意思是,我不是第一个想要处理数据库迁移的人,你如何管理?我的项目很大,我需要控制.
这是我到目前为止所做的一个例子:
*0010-init_category_table.js*
var mongodb = require('mongodb');
exports.up = function(db, next){
var documentName = 'category';
var collection = mongodb.Collection(db, documentName);
var index;
var indexOptions;
/**
* Create indexes.
*/
index = { "code": 1 };
indexOptions = { unique: true };
collection.ensureIndex( index, {unique: true, w: 1}, function(error, data){
console.log(error ? error : documentName + ': [ensureIndex] ' + JSON.stringify(index) + JSON.stringify(indexOptions));
});
index = { "name": 1 };
indexOptions = { unique: true };
collection.ensureIndex( index, {unique: true, w: 1}, function(error, data){
console.log(error ? error : documentName + ': [ensureIndex] ' + JSON.stringify(index) + JSON.stringify(indexOptions));
});
/**
* Create basic data.
*/
collection.insert({
code: 'a',
name: 'languageStatus'
}, {w: 1}, function(error, data){
console.log(error ? error : documentName + ': [insert] ' + JSON.stringify(data));
});
collection.insert({
code: 'b',
name: 'accessName'
}, {w: 1}, function(error, data){
console.log(error ? error : documentName + ': [insert] ' + JSON.stringify(data));
});
collection.insert({
code: 'c',
name: 'roleName'
}, {w: 1}, function(error, data){
console.log(error ? error : documentName + ': [insert] ' + JSON.stringify(data));
});
collection.insert({
code: 'd',
name: 'translationStatus'
}, {w: 1}, function(error, data){
console.log(error ? error : documentName + ': [insert] ' + JSON.stringify(data));
});
/**
* Display index information.
*/
collection.indexInformation(function(error, data){
console.log(error ? error : documentName + ': [indexes] ' + JSON.stringify(data));
});
next();
};
exports.down = function(db, next){
var documentName = 'category';
var document = mongodb.Collection(db, documentName);
var query = {
$or: [
{name: 'languageStatus'},
{name: 'accessName'},
{name: 'roleName'},
{name: 'translationStatus'}
]
};
document.find(query, function(error, data){
data.each(function(error, data){
document.remove(data, {w: 1}, function(error, number){
console.log(error ? error : documentName + ': [remove] (' + number + ') ' + JSON.stringify(data));
})
});
});
next();
};
Run Code Online (Sandbox Code Playgroud)
我刚开发了这个:https://github.com/eberhara/mongration - 你也可以在npm找到.
我们需要一个良好的mongodb节点迁移框架,但找不到 - 所以我们建了一个.
它具有许多比常规迁移框架更好的功能:
| 归档时间: |
|
| 查看次数: |
8737 次 |
| 最近记录: |