Я ищу модуль узла для миграции баз данных Монго. До сих пор я нашел 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();
};