summaryrefslogtreecommitdiff
path: root/scripts/migration/0.8.2/migrate.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-07-29 10:01:46 -0300
committerdrebs <drebs@leap.se>2016-08-01 21:09:04 -0300
commitbc28ea6e652418791dcf63fadcc81db9c50e2d45 (patch)
tree8ee54c15dc636c4ab347b5387ea3da268ebf7259 /scripts/migration/0.8.2/migrate.py
parent72ee56e3863729b148cf8cc16e4004dc7b52acdd (diff)
[pkg] add couch schema migration script
Diffstat (limited to 'scripts/migration/0.8.2/migrate.py')
-rwxr-xr-xscripts/migration/0.8.2/migrate.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/migration/0.8.2/migrate.py b/scripts/migration/0.8.2/migrate.py
new file mode 100755
index 00000000..159905ef
--- /dev/null
+++ b/scripts/migration/0.8.2/migrate.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+# migrate.py
+
+"""
+Migrate CouchDB schema to Soledad 0.8.2 schema.
+
+******************************************************************************
+ ATTENTION!
+
+ - This script does not backup your data for you. Make sure you have a backup
+ copy of your databases before running this script!
+
+ - Make sure you turn off any service that might be writing to the couch
+ database before running this script.
+
+******************************************************************************
+
+Run this script with the --help option to see command line options.
+
+See the README.md file for more information.
+"""
+
+import datetime
+import logging
+import os
+
+from argparse import ArgumentParser
+
+from migrate_couch_schema import migrate
+
+
+TARGET_VERSION = '0.8.2'
+DEFAULT_COUCH_URL = 'http://127.0.0.1:5984'
+
+
+#
+# command line args and execution
+#
+
+def _configure_logger(log_file):
+ if not log_file:
+ fname, _ = os.path.basename(__file__).split('.')
+ timestr = datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
+ filename = 'soledad_%s_%s_%s.log' \
+ % (TARGET_VERSION, fname, timestr)
+ dirname = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)), 'log')
+ log_file = os.path.join(dirname, filename)
+ logging.basicConfig(
+ filename=log_file,
+ filemode='a',
+ format='%(asctime)s,%(msecs)d %(levelname)s %(message)s',
+ datefmt='%H:%M:%S',
+ level=logging.DEBUG)
+
+
+def _parse_args():
+ parser = ArgumentParser()
+ parser.add_argument(
+ '--couch_url',
+ help='the url for the couch database',
+ default=DEFAULT_COUCH_URL)
+ parser.add_argument(
+ '--do-migrate',
+ help='actually perform the migration (otherwise '
+ 'just print what would be done)',
+ action='store_true')
+ parser.add_argument(
+ '--log-file',
+ help='the log file to use')
+ return parser.parse_args()
+
+
+if __name__ == '__main__':
+ args = _parse_args()
+ _configure_logger(args.log_file)
+ migrate(args, TARGET_VERSION)