-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_migration.py
35 lines (25 loc) · 1006 Bytes
/
db_migration.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
from concurrent.futures.thread import ThreadPoolExecutor
from infinitewisdom.persistence.sqlalchemy import SQLAlchemyPersistence
p1 = SQLAlchemyPersistence(url="sqlite:///source_infinitewisdom.db")
p2 = SQLAlchemyPersistence(url="postgresql://infinitewisdom:infinitewisdom@localhost/infinitewisdom")
p1_total = p1.count()
added = 0
skipped = 0
total = 0
def migrate_entity(entity):
global added
global skipped
global total
if len(p2.find_by_image_hash(entity.image_hash)) <= 0:
print("Adding: {}".format(entity.image_hash))
p2.add(entity)
added += 1
else:
print("Skipping: {}".format(entity.image_hash))
skipped += 1
total = added + skipped
print("Progress: {}/{}".format(total, p1_total))
with ThreadPoolExecutor(max_workers=4, thread_name_prefix="db-migration") as executor:
for e in p1.get_all():
future = executor.submit(migrate_entity, e)
print("Added {}/{} entries ({} skipped)".format(added, total, skipped))