Skip to content

Instantly share code, notes, and snippets.

@Nainterceptor
Created November 19, 2014 08:40
Show Gist options
  • Save Nainterceptor/50cb4394a3c777e5273c to your computer and use it in GitHub Desktop.
Save Nainterceptor/50cb4394a3c777e5273c to your computer and use it in GitHub Desktop.
Copy Rubedo preproduction to production
const prod = 'myRubedoProd';
const prodUrl = 'http://my-rubedo.com/';
const preprod = 'myRubedoPreprod';
const preprodUrl = 'http://my-rubedo.local/';
const tablesToClean = ['UrlCache', 'sessions', 'Cache'];
//Drop And Copy Database
var conn = new Mongo();
var db = conn.getDB(prod);
db.dropDatabase();
db.copyDatabase(preprod, prod);
//Replace URL
var cursor = db.Contents.find();
regexPreprodUrl = new RegExp(preprodUrl, 'g');
while (cursor.hasNext()) {
var entry = cursor.next();
['workspace', 'live'].forEach(function (env){
Object.keys(entry[env].i18n).forEach(function(lang){
Object.keys(entry[env].i18n[lang].fields).forEach(function(field){
if(typeof entry[env].i18n[lang].fields[field] === 'string') {
entry[env].i18n[lang].fields[field] = entry[env].i18n[lang].fields[field]
.replace(regexPreprodUrl, prodUrl);
}
});
});
});
db.Contents.update({_id : entry._id}, entry);
}
//Clean cache tables and sessions from preprod
tablesToClean.forEach(function(table) {
db[table].drop();
});
@Nainterceptor
Copy link
Author

Execute this with "mongo copyRubedoToProd.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment