comparison migrate_couch_to_arango.py @ 256:f79be01821c4

Arangodb backend, first version which barely works for reading
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 30 Jan 2019 07:11:10 +0100
parents b4c83e9b9c7a
children 75b81da8d7a5
comparison
equal deleted inserted replaced
255:b4c83e9b9c7a 256:f79be01821c4
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 import couchdb 4 import couchdb
5 from datetime import datetime
5 import pyArango.connection 6 import pyArango.connection
7
6 8
7 def get_or_cretae_arango_collection(arango_db, collection_name): 9 def get_or_cretae_arango_collection(arango_db, collection_name):
8 if arango_db.hasCollection(collection_name): 10 if arango_db.hasCollection(collection_name):
9 return arango_db[collection_name] 11 return arango_db[collection_name]
10 else: 12 else:
16 return 18 return
17 try: 19 try:
18 if couch_doc['doctype'] == 'feed': 20 if couch_doc['doctype'] == 'feed':
19 arango_doc = arango_feed.createDocument() 21 arango_doc = arango_feed.createDocument()
20 copy(couch_doc, arango_doc) 22 copy(couch_doc, arango_doc)
23 convert_date(couch_doc, arango_doc, 'next_update')
21 arango_doc.save() 24 arango_doc.save()
22 feed_mapping[couch_id] = arango_doc['_key'] 25 feed_mapping[couch_id] = arango_doc['_key']
23 except KeyError: 26 except KeyError:
24 print('**** migrate error ' + str(document)) 27 print('**** migrate error ' + str(document))
28
29 def convert_date(couch_doc, arango_doc, key):
30 date_string = couch_doc[key]
31 couch_date = datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%SZ')
32 # ignore the milliseconds - if they are printed through %f the number of
33 # digits is not what arangodb expects
34 date_string = couch_date.strftime('%Y-%m-%dT%H:%M:%S.000')
35 arango_doc[key] = date_string
25 36
26 def migrate_rest(document): 37 def migrate_rest(document):
27 if document['_id'].startswith('_design'): 38 if document['_id'].startswith('_design'):
28 return 39 return
29 try: 40 try: