2020-09-24 14:02:39 +02:00
// Authentication???
2020-03-31 14:02:29 +02:00
// 1. copy database with name "test" in folder "/home/konstantina/mongo_backups"
2020-09-24 14:02:39 +02:00
// mongodump --db test --out /home/konstantina/mongo_backups
2020-03-31 14:02:29 +02:00
// 2. paste database with name "test", which is in folder "/home/konstantina/mongo_backups/test", into database with name "test2" | Drop collections if test2 already exists
2020-09-24 14:02:39 +02:00
// mongorestore --db test2 --drop /home/konstantina/mongo_backups/test
2020-03-31 14:02:29 +02:00
2020-09-24 14:02:39 +02:00
// Be careful with function parameters: names of dbs, name of portal
2020-03-31 14:02:29 +02:00
// 3. If needed run init script
// 4. Run synchronize_dbs.js
// 5. Run migrateCommunityIn_db.js
2020-09-24 14:02:39 +02:00
2020-03-31 14:02:29 +02:00
//version compatibility: 1.1.1-SNAPSHOT
print ( "synchronization of DBs script running..." ) ;
function keep _Beta _Production _DBs _synchronized ( beta _db _name , production _db _name ) {
beta _db = db . getSiblingDB ( beta _db _name ) ;
2020-12-04 10:41:00 +01:00
// db.auth("your_username", "your_password");
2020-03-31 14:02:29 +02:00
prod _db = db . getSiblingDB ( production _db _name ) ;
2020-12-04 10:41:00 +01:00
// db.auth("your_username", "your_password");
2020-03-31 14:02:29 +02:00
print ( "keep_Beta_Production_DBs_synchronized - both dbs (" + beta _db _name + ", " + production _db _name + ") are here" ) ;
// synchronize entities
beta _db . entity . find ( ) . forEach ( function ( beta _entity ) {
//var prod_entityId = prod_db.entity.find( { name: beta_entity.name }).map( function(prod_entity) { return prod_entity._id.str; } ).toString();
var prod _entity = prod _db . entity . findOne ( { pid : beta _entity . pid } ) ;
if ( ! prod _entity ) {
prod _db . entity . save ( { "pid" : beta _entity . pid , "name" : beta _entity . name } ) ;
print ( "Entity with pid: " + beta _entity . pid + " is created in " + production _db _name + " database" ) ;
// synchronize this entity for all available communities
//prod_entityId = prod_db.entity.find( { pid: beta_entity.pid }).map( function(prod_entity) { return prod_entity._id.str; } ).toString();
var prod _entity _id = prod _db . entity . findOne ( { pid : beta _entity . pid } ) . _id . str ;
2020-09-24 14:02:39 +02:00
beta _db . portal . find ( ) . forEach ( function ( beta _portal ) {
var prod _portal = prod _db . portal . findOne ( { pid : beta _portal . pid } ) ;
if ( prod _portal ) {
var prod _portal _entities = prod _portal . entities ;
prod _portal _entities [ prod _entity _id ] = beta _portal . entities [ beta _entity . _id . str ] ;
prod _db . portal . update ( { pid : prod _portal . pid } , { $set : { entities : prod _portal _entities } } )
2020-03-31 14:02:29 +02:00
2020-09-24 14:02:39 +02:00
print ( "Entity was created for portal with pid: " + prod _portal . pid + " that exists on production db: " + production _db _name ) ;
2020-03-31 14:02:29 +02:00
} else {
2020-09-24 14:02:39 +02:00
print ( "\nERROR: Portal with pid: " + beta _portal . pid + " does not exist on production db: " + production _db _name + "\n" ) ;
2020-03-31 14:02:29 +02:00
}
} ) ;
print ( "" ) ;
}
} ) ;
print ( "Entities are synchronized\n" ) ;
// synchronize pages
beta _db . page . find ( ) . forEach ( function ( beta _page ) {
//var prod_pageId = prod_db.page.find( { route: beta_page.route }).map( function(prod_page) { return prod_page._id.str; } ).toString();
2020-09-24 14:02:39 +02:00
var prod _page = prod _db . page . findOne ( { route : beta _page . route , portalType : beta _page . portalType } ) ; //._id.str;
2020-03-31 14:02:29 +02:00
if ( ! prod _page ) {
var prod _page _entities = [ ] ;
beta _page . entities . forEach ( function ( beta _page _entity ) {
var beta _page _entity _ObjectId = ObjectId ( beta _page _entity ) ;
//var beta_pageEntity_pid = beta_db.entity.find( { _id: beta_page_entity_ObjectId } ).map(function(entity) { return entity.pid; }).toString();
var beta _pageEntity = beta _db . entity . findOne ( { _id : beta _page _entity _ObjectId } ) ;
if ( beta _pageEntity ) {
//var prod_pageEntity_id = prod_db.entity.find( { pid: beta_pageEntity_pid } ).map(function(entity) { return entity._id.str; }).toString();
var prod _pageEntity = prod _db . entity . findOne ( { pid : beta _pageEntity . pid } ) ; //._id.str;
if ( prod _pageEntity ) {
prod _page _entities . push ( prod _pageEntity . _id . str ) ;
} else {
print ( "\nERROR: Entity with pid: " + beta _pageEntity . pid + " does not exist on production db: " + production _db _name + "\n" ) ;
}
} else {
print ( "\nERROR: Entity with id: " + beta _page _entity + " (of page: " + beta _page . name + ") does not exist on beta db: " + beta _db _name + "\n" ) ;
}
} )
2020-09-24 14:02:39 +02:00
prod _db . page . save ( {
"name" : beta _page . name ,
"route" : beta _page . route ,
"type" : beta _page . type ,
"portalType" : beta _page . portalType ,
"entities" : prod _page _entities ,
"top" : beta _page . top , "bottom" : beta _page . bottom , "left" : beta _page . left , "right" : beta _page . right
} ) ;
2020-03-31 14:02:29 +02:00
print ( "Page: " + beta _page . name + " is created in " + production _db _name + " database" ) ;
// synchronize this page and its contents for all available communities
//prod_pageId = prod_db.page.find( { route: beta_page.route }).map( function(prod_page) { return prod_page._id.str; } ).toString();
2020-09-24 14:02:39 +02:00
var prod _pageId = prod _db . page . findOne ( { route : beta _page . route , portalType : beta _page . portalType } ) . _id . str ;
beta _db . portal . find ( { type : beta _page . portalType } ) . forEach ( function ( beta _portal ) {
var prod _portal = prod _db . portal . findOne ( { pid : beta _portal . pid } ) ;
if ( prod _portal ) {
var prod _portal _pages = prod _portal . pages ;
prod _portal _pages [ prod _pageId ] = beta _portal . pages [ beta _page . _id . str ] ;
prod _db . portal . update ( { pid : prod _portal . pid } , { $set : { pages : prod _portal _pages } } )
2020-03-31 14:02:29 +02:00
2020-09-24 14:02:39 +02:00
print ( "Page was created for portal: " + prod _portal . name + " that exists on production" ) ;
2020-03-31 14:02:29 +02:00
2020-09-24 14:02:39 +02:00
beta _db . pageHelpContent . find ( { portal : beta _portal . _id . str , page : beta _page . _id . str } ) . forEach ( function ( beta _pageHelpContent ) {
prod _db . pageHelpContent . save ( { "page" : prod _pageId , "portal" : prod _portal . _id . str , "content" : beta _pageHelpContent . content , "placement" : beta _pageHelpContent . placement , "order" : beta _pageHelpContent . order , "isActive" : beta _pageHelpContent . isActive , "isPriorTo" : beta _pageHelpContent . isPriorTo } ) ;
2020-03-31 14:02:29 +02:00
} ) ;
2020-09-24 14:02:39 +02:00
print ( "PageHelpContents were created for portal: " + prod _portal . name + " that exists on production" ) ;
2020-03-31 14:02:29 +02:00
}
print ( "" ) ;
} ) ;
print ( "" ) ;
}
} ) ;
print ( "Pages are synchronized\n" ) ;
// synchronize divIds
beta _db . divId . find ( ) . forEach ( function ( beta _divId ) {
//var prod_divIdId = prod_db.divId.find( { name: beta_divId.name }).map( function(prod_divId) { return prod_divId._id.str; } ).toString();
2020-09-24 14:02:39 +02:00
var prod _divId = prod _db . divId . findOne ( { name : beta _divId . name , portalType : beta _divId . portalType } ) ; //._id.str;
2020-03-31 14:02:29 +02:00
if ( ! prod _divId ) {
var prod _divId _pages = [ ] ;
beta _divId . pages . forEach ( function ( beta _divId _page ) {
var beta _divId _page _ObjectId = ObjectId ( beta _divId _page ) ;
//var beta_divIdPage_route = beta_db.page.find( { _id: beta_divId_page_ObjectId } ).map(function(page) { return page.route; }).toString();
var beta _divIdPage = beta _db . page . findOne ( { _id : beta _divId _page _ObjectId } ) ; //.route;
if ( beta _divIdPage ) {
//var prod_divIdPage_id = prod_db.page.find( { route: beta_divIdPage_route } ).map(function(page) { return page._id.str; }).toString();
2020-09-24 14:02:39 +02:00
var prod _divIdPage = prod _db . page . findOne ( { route : beta _divIdPage . route , portalType : beta _divIdPage . portalType } ) ; //._id.str;
2020-03-31 14:02:29 +02:00
if ( prod _divIdPage ) {
prod _divId _pages . push ( prod _divIdPage . _id . str ) ;
} else {
print ( "\nERROR: Page with route: " + beta _divIdPage . route + " does not exist on production db: " + production _db _name + "\n" ) ;
}
} else {
print ( "\nERROR: Page with id: " + beta _divId _page + " (of divId: " + beta _divId . name + ") does not exist on beta db: " + beta _db _name + "\n" ) ;
}
} )
2020-09-24 14:02:39 +02:00
prod _db . divId . save ( { "name" : beta _divId . name , "pages" : prod _divId _pages , "portalType" : beta _divId . portalType } ) ;
2020-03-31 14:02:29 +02:00
print ( "DivId: " + beta _divId . name + " is created in " + production _db _name + " database" ) ;
// synchronize this divId's contents for all available communities
//prod_divIdId = prod_db.divId.find( { name: beta_divId.name }).map( function(prod_divId) { return prod_divId._id.str; } ).toString();
2020-09-24 14:02:39 +02:00
var prod _divIdId = prod _db . divId . findOne ( { name : beta _divId . name , portalType : beta _divId . portalType } ) . _id . str ;
beta _db . portal . find ( { type : beta _divId . portalType } ) . forEach ( function ( beta _portal ) {
var prod _portal = prod _db . portal . findOne ( { pid : beta _portal . pid } ) ;
if ( prod _portal ) {
beta _db . divHelpContent . find ( { portal : beta _portal . _id . str , divId : beta _divId . _id . str } ) . forEach ( function ( beta _divHelpContent ) {
prod _db . divHelpContent . save ( { "divId" : prod _divIdId , "portal" : prod _portal . _id . str , "content" : beta _divHelpContent . content , "isActive" : beta _divHelpContent . isActive } ) ;
2020-03-31 14:02:29 +02:00
} ) ;
2020-09-24 14:02:39 +02:00
print ( "DivHelpContents were created for portal: " + prod _portal . name + " that exists on production" ) ;
2020-03-31 14:02:29 +02:00
}
} ) ;
print ( "" ) ;
}
} ) ;
print ( "DivIds are synchronized" ) ;
}
2020-12-04 10:41:00 +01:00
keep _Beta _Production _DBs _synchronized ( "openaireconnect_new" , "openaireconnect" ) ;
2020-03-31 14:02:29 +02:00