-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongoMigrator.py
138 lines (114 loc) · 5.13 KB
/
mongoMigrator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import time
import pymongo
from pymongo import MongoClient
from bson.objectid import ObjectId
import configs.ConfigHandler as conf
default_data = conf.get_conf('config.ini','DefaultData')
mongoconf = conf.get_conf('config.ini','mongo')
db = None
def usergroups():
try:
db['usergroups'].update_many({}, {'$set': {'businessUnit': default_data['bu']}})
except Exception as err:
print(err)
# def todos():
# try:
# db['todos'].update_many({}, {'$set': {'businessUnit': default_data['bu']}})
# except Exception as err:
# print(err)
# todos - No usage, ticketviews - active, order are present in singer db no need of migration
# ticketstatusnodes - discuss and update category field
# phoneconfigs - phoneType only one ?
# personalmessages - session?
# packages setupFee, spaceLimit, billingType only 2 docs ?
# codecAccessLimits, ownerRef, spaceLimit, timeZone, unitDetails, languages, packageDetails
# customersatisfactions - submitter, requester, ticket
# comments - author_external ?
# cases ignore, some docs have the missing keys
# bulkoperations only one doc. should ignore?
# def engagementsessions():
# try:
# docs = db.engagements.find({})
# for i in docs:
# print(i)
# for j in i["engagements"]:
# print(j)
# if isinstance(i["profile"], str):
# db.engagementsessions.update_one({"_id" : j}, {"$set": {"profile_id": i["profile"], "has_profile": True}})
# else:
# db.engagementsessions.update_one({"_id" : j}, {"$set": {"profile_id": str(i["profile"]), "has_profile": True}})
#
# except Exception as err:
# print(err)
limit = 1000
offset = 0
def engagementsessions(limit, offset):
try:
docs = db.engagements.find({}).limit(limit).skip(offset)
print(docs.count(True))
if docs.count(True) > 0:
for i in docs:
print(i)
for j in i["engagements"]:
print(j)
if isinstance(i["profile"], str):
db.engagementsessions.update_one({"_id" : j}, {"$set": {"profile_id": i["profile"], "has_profile": True}})
else:
db.engagementsessions.update_one({"_id" : j}, {"$set": {"profile_id": str(i["profile"]), "has_profile": True}})
time.sleep(1)
offset += 1000
engagementsessions(limit, offset)
else:
return 0
except Exception as err:
print(err)
def contacts():
try:
db['contacts'].update_many({}, {'$set': {'businessUnit': default_data['bu']}})
except Exception as err:
print(err)
def user_accounts(limit, offset):
try:
docs = db.users.find({}).limit(limit).skip(offset)
print(docs.count(True))
if docs.count(True) > 0:
for i in docs:
print(i)
db.useraccounts.insert({"userref": ObjectId("{0}".format(i['_id'])),
"user_meta": i.get("user_meta"),
"user": i.get("username"),
"tenant": i.get("tenant"),
"company": i.get("company"),
"resource_id": i.get("resourceid"),
"created_at": i.get("created_at"),
"updated_at": i.get("updated_at"),
"multi_login": i.get("multi_login"),
"client_scopes": i.get("client_scopes"),
"user_scopes": i.get("user_scopes"),
"veeryaccount": i.get("veeryaccount"),
"verified": i.get("verified"),
"active": i.get("Active"),
"allowed_file_categories": i.get("allowed_file_categories"),
"joined": i.get("joined"),
"allowoutbound": i.get("allowoutbound")
})
offset += 1000
engagementsessions(limit, offset)
else:
return 0
except Exception as err:
print(err)
if __name__ == "__main__":
HOST = mongoconf['database_2_host']
DB = mongoconf['database_2_name']
username = mongoconf['database_2_username']
password = mongoconf['database_2_password']
# mgo1 = MongoClient('mongodb://duo:DuoS123@104.236.231.11:27017/dvpdb')
mgo = MongoClient(HOST)
# mgo1 = MongoClient('mongodb://{0}:{1}@{2}:{3}/dvpdb'.format(mongoconf['database_1_username'], mongoconf['database_1_password'], HOST1, mongoconf['database_1_port']))
# mgo2 = MongoClient('mongodb://{0}:{1}@{2}:{3}/dvpdb'.format(mongoconf['database_2_username'], mongoconf['database_2_password'], HOST2, mongoconf['database_2_port']))
db = mgo[DB]
db.authenticate(username, password)
# usergroups()
# engagementsessions(limit, offset)
user_accounts(limit, offset)