changeset 2779:d0d3158850d4 beta

migrations: fix old hook values - nicer notifications
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 02 Sep 2012 22:17:21 +0200
parents 0e73626f6040
children dd222038535d d03d51b6541e
files rhodecode/lib/db_manage.py
diffstat 1 files changed, 41 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/db_manage.py	Sun Sep 02 21:32:03 2012 +0200
+++ b/rhodecode/lib/db_manage.py	Sun Sep 02 22:17:21 2012 +0200
@@ -40,7 +40,6 @@
     UserRepoGroupToPerm
 
 from sqlalchemy.engine import create_engine
-from sqlalchemy.schema import MetaData
 from rhodecode.model.repos_group import ReposGroupModel
 #from rhodecode.model import meta
 from rhodecode.model.meta import Session, Base
@@ -49,6 +48,14 @@
 log = logging.getLogger(__name__)
 
 
+def notify(msg):
+    """
+    Notification for migrations messages
+    """
+    ml = len(msg) + (4 * 2)
+    print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper()
+
+
 class DbManage(object):
     def __init__(self, log_sql, dbconf, root, tests=False):
         self.dbname = dbconf.split('/')[-1]
@@ -130,7 +137,7 @@
                    ' as version %s' % curr_version)
             api.version_control(db_uri, repository_path, curr_version)
 
-        print (msg)
+        notify(msg)
 
         if curr_version == __dbversion__:
             sys.exit('This database is already at the newest version')
@@ -138,6 +145,7 @@
         #======================================================================
         # UPGRADE STEPS
         #======================================================================
+
         class UpgradeSteps(object):
             """
             Those steps follow schema versions so for example schema
@@ -149,32 +157,32 @@
 
             def step_0(self):
                 # step 0 is the schema upgrade, and than follow proper upgrades
-                print ('attempting to do database upgrade to version %s' \
+                notify('attempting to do database upgrade to version %s' \
                                 % __dbversion__)
                 api.upgrade(db_uri, repository_path, __dbversion__)
-                print ('Schema upgrade completed')
+                notify('Schema upgrade completed')
 
             def step_1(self):
                 pass
 
             def step_2(self):
-                print ('Patching repo paths for newer version of RhodeCode')
+                notify('Patching repo paths for newer version of RhodeCode')
                 self.klass.fix_repo_paths()
 
-                print ('Patching default user of RhodeCode')
+                notify('Patching default user of RhodeCode')
                 self.klass.fix_default_user()
 
                 log.info('Changing ui settings')
                 self.klass.create_ui_settings()
 
             def step_3(self):
-                print ('Adding additional settings into RhodeCode db')
+                notify('Adding additional settings into RhodeCode db')
                 self.klass.fix_settings()
-                print ('Adding ldap defaults')
+                notify('Adding ldap defaults')
                 self.klass.create_ldap_options(skip_existing=True)
 
             def step_4(self):
-                print ('create permissions and fix groups')
+                notify('create permissions and fix groups')
                 self.klass.create_permissions()
                 self.klass.fixup_groups()
 
@@ -182,23 +190,37 @@
                 pass
 
             def step_6(self):
-                print ('re-checking permissions')
+
+                notify('re-checking permissions')
                 self.klass.create_permissions()
 
-                print ('installing new hooks')
+                notify('fixing old PULL hook')
+                _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
+                if _pull:
+                    _pull.ui_key = RhodeCodeUi.HOOK_PULL
+                    Session().add(_pull)
+
+                notify('fixing old PUSH hook')
+                _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
+                if _push:
+                    _push.ui_key = RhodeCodeUi.HOOK_PUSH
+                    Session().add(_push)
+
+                notify('installing new pre-push hook')
                 hooks4 = RhodeCodeUi()
                 hooks4.ui_section = 'hooks'
                 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
                 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
                 Session().add(hooks4)
 
+                notify('installing new pre-pull hook')
                 hooks6 = RhodeCodeUi()
                 hooks6.ui_section = 'hooks'
                 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
                 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
                 Session().add(hooks6)
 
-                print ('installing hgsubversion option')
+                notify('installing hgsubversion option')
                 # enable hgsubversion disabled by default
                 hgsubversion = RhodeCodeUi()
                 hgsubversion.ui_section = 'extensions'
@@ -207,7 +229,7 @@
                 hgsubversion.ui_active = False
                 Session().add(hgsubversion)
 
-                print ('installing hg git option')
+                notify('installing hg git option')
                 # enable hggit disabled by default
                 hggit = RhodeCodeUi()
                 hggit.ui_section = 'extensions'
@@ -216,16 +238,20 @@
                 hggit.ui_active = False
                 Session().add(hggit)
 
-                print ('re-check default permissions')
+                notify('re-check default permissions')
                 self.klass.populate_default_permissions()
 
         upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
 
         # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
+        _step = None
         for step in upgrade_steps:
-            print ('performing upgrade step %s' % step)
+            notify('performing upgrade step %s' % step)
             getattr(UpgradeSteps(self), 'step_%s' % step)()
             self.sa.commit()
+            _step = step
+
+        notify('upgrade to version %s successful' % _step)
 
     def fix_repo_paths(self):
         """