Esempio n. 1
0
 def upgrade_patches(self, patches, execute_sql=True):
     dbrepo = self._get_repo()
     applied_patches = self.applied_patches
     plan = generate_upgrade_plan(applied_patches=applied_patches,
             to_be_applied_patches=patches)
     for patch in plan:
         print "applying patch '%s'" % patch.name
         self.sess.add(AppliedPatch(dbrepo.repository_id, patch.name))
         if patch.upgrade_sql is not None and execute_sql:
             for patch_name in patch.missing_deps:
                 print " (ignoring optional missing patch '%s')" % patch_name
             with _TranslateErrors("patch upgrade failed '%s'" % (
                     patch.name)):
                 execute_script(self.sess, patch.upgrade_sql)
     return plan
Esempio n. 2
0
 def downgrade_patches(self, patches, execute_sql=True):
     dbrepo = self._get_repo()
     applied_patches = self.applied_patches
     plan = generate_downgrade_plan(applied_patches=applied_patches,
             to_be_removed_patches=patches)
     for patch in plan:
         print "removing patch '%s'" % patch.name
         dbpatch = self.sess.query(AppliedPatch)\
                 .filter_by(repository_id=dbrepo.repository_id,
                         patch_name=patch.name)\
                 .one()
         self.sess.delete(dbpatch)
         if patch.downgrade_sql is not None and execute_sql:
             for patch_name in patch.missing_deps:
                 print " (ignoring optional missing patch '%s')" % patch_name
             with _TranslateErrors("patch downgrade failed '%s'" % (
                     patch.name)):
                 execute_script(self.sess, patch.downgrade_sql)
     return plan