Created
November 19, 2014 08:40
-
-
Save Nainterceptor/50cb4394a3c777e5273c to your computer and use it in GitHub Desktop.
Copy Rubedo preproduction to production
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute this with "mongo copyRubedoToProd.js"