diff options
| author | Alon Levy <alon@pobox.com> | 2015-06-04 14:18:56 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-06-04 14:22:21 +0300 |
| commit | 9f96fbc3c5b53e5cbd07ddd5d70e11141a4417f3 (patch) | |
| tree | 16cd018c5ef80bd577f13dc9a8f6b870540b83bf | |
| parent | 222fd42ad588595c3df826007ef1d1278a82ca68 (diff) | |
temporary/migrate: add a tool to update the commit blobs until we have a proper exporter/importer tool
| -rw-r--r-- | src/temporary/migrate.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/temporary/migrate.py b/src/temporary/migrate.py new file mode 100644 index 00000000..a62040f8 --- /dev/null +++ b/src/temporary/migrate.py @@ -0,0 +1,59 @@ +""" +This tool does some migrations on the database. + +We intend to have a format to export to be used for migration to a newer/older rhizi database, +but since this tool is currently written and useful it is being put, intended as temporary, to the db. +""" + +import base64 +import gzip + +from py2neo import Graph, watch + +graph_db = None + +def base64_gzip(text): + return base64.encodestring(gzip.zlib.compress(text)) + +def update_blob_compression_to_gzip(): + nodes = [row.x for row in graph_db.cypher.execute('match (x:__COMMIT) return x')] + changed = 0 + for node in nodes: + if node['name'] == 'root-commit': + continue + blob = node['blob'] + if blob[:1] != '{': + decoded = base64.decodestring(blob) + try: + blob = gzip.zlib.decompress(decoded) + except: + try: + blob = gzip.zlib.decompress(decoded, 16) + except: + import pdb; pdb.set_trace() + new_blob = base64_gzip(blob) + if new_blob != node['blob']: + changed += 1 + node['blob'] = new_blob + if changed > 0: + print('updated %s commit node blobs' % changed) + graph_db.push(*nodes) + else: + print("all commit node blobs are up to date") + +def rhizi_db_version(): + return map(int, graph_db.cypher.execute('match (x:__RZDB_META) return x')[0].x['schema_version'].split('.')) + +def main(): + global graph_db + watch("httpstream") + graph_db = Graph('http://localhost:17474/db/data') + + rhizi_major, rhizi_minor, rhizi_micro = rhizi_db_version() + print("rhizi db schema version: %r.%r.%r" % (rhizi_major, rhizi_minor, rhizi_micro)) + + if rhizi_major <= 0 and rhizi_minor <= 2: + update_blob_compression_to_gzip() + +if __name__ == '__main__': + main() |
