diff --git a/py/webnotes/modules/patch_handler.py b/py/webnotes/modules/patch_handler.py index 67034b1924..bf6d45c82c 100644 --- a/py/webnotes/modules/patch_handler.py +++ b/py/webnotes/modules/patch_handler.py @@ -33,7 +33,6 @@ class PatchHandler: self.verbose = kwargs.get('verbose') try: self.db_name = kwargs.get('db_name') - webnotes.conn = None webnotes.conn = Database(user=self.db_name) webnotes.conn.use(self.db_name) if not (webnotes.session and webnotes.session['user']): @@ -70,8 +69,8 @@ class PatchHandler: patch = __import__(module_file, fromlist=True) getattr(patch, 'execute')() - self.log(log_type='success', patch_module=patch_module, patch_file=patch_file) webnotes.conn.commit() + self.log(log_type='success', patch_module=patch_module, patch_file=patch_file) except Exception, e: webnotes.conn.rollback() @@ -156,6 +155,8 @@ class PatchHandler: self.block_user(False) + webnotes.conn.close() + def log(self, **kwargs): """ @@ -177,9 +178,11 @@ class PatchHandler: patch = str(patch_module) + "." + str(patch_file) if log_type == 'success': + webnotes.conn.begin() webnotes.conn.sql("""\ INSERT INTO `__PatchLog` VALUES (%s, now())""", patch) + webnotes.conn.commit() if self.verbose: print 'Patch: %s applied successfully on %s' % (patch, str(self.db_name)) elif log_type == 'error' or log_type == 'info': diff --git a/wnf.py b/wnf.py index 3976fe5bab..e9fe64e041 100755 --- a/wnf.py +++ b/wnf.py @@ -78,6 +78,9 @@ def run(): parser.add_option("-f", "--force", action="store_true", dest="force", default=False, help="Force Apply all patches specified using option -p or --patch") + parser.add_option("-d", "--db", + dest="db_name", + help="Apply the patches on given db") (options, args) = parser.parse_args() if options.patch_list: @@ -91,7 +94,7 @@ def run(): } kwargs = options.__dict__ from webnotes.modules.patch_handler import PatchHandler - PatchHandler(db_name=getattr(webnotes.defs, 'default_db_name'), verbose=kwargs.get('verbose')).run(**kwargs) + PatchHandler(db_name=kwargs.get('db_name') or getattr(webnotes.defs, 'default_db_name'), verbose=kwargs.get('verbose')).run(**kwargs) if __name__=='__main__':