← Back to team overview

openerp-community-reviewer team mailing list archive

[Bug 1319843] Re: duplicate_database missing

 

** Also affects: ocb-server
   Importance: Undecided
       Status: New

** Also affects: ocb-server/6.1
   Importance: Undecided
       Status: New

-- 
You received this bug notification because you are a member of OpenERP
Community Backports, which is subscribed to OpenERP Community Backports
(Server).
https://bugs.launchpad.net/bugs/1319843

Title:
  duplicate_database  missing

Status in OpenERP Community Backports (Server):
  New
Status in OpenERP Community Backports (Server) 6.1 series:
  New
Status in OpenERP Server:
  New

Bug description:
  on webinterface is not possible to duplicate db as on version 7


  
  this will fix bug:

  
  === modified file 'openerp/service/web_services.py'
  --- openerp/service/web_services.py	2012-03-23 11:17:50 +0000
  +++ openerp/service/web_services.py	2014-05-04 12:49:29 +0000
  @@ -101,7 +101,7 @@
   
       def dispatch(self, method, params):
           if method in [ 'create', 'get_progress', 'drop', 'dump',
  -            'restore', 'rename',
  +            'restore', 'rename', 'duplicate_database',
               'change_admin_password', 'migrate_databases',
               'create_database' ]:
               passwd = params[0]
  @@ -126,6 +126,18 @@
           finally:
               cr.close()
   
  +    def exp_duplicate_database(self, db_original_name, db_name):
  +        _logger.info('Duplicate database `%s` to `%s`.', db_original_name, db_name)
  +        sql_db.close_db(db_original_name)
  +        db = sql_db.db_connect('postgres')
  +        cr = db.cursor()
  +        try:
  +            cr.autocommit(True) # avoid transaction block
  +            cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
  +        finally:
  +            cr.close()
  +        return True
  +
       def exp_create(self, db_name, demo, lang, user_password='admin'):
           self.id_protect.acquire()
           self.id += 1

  @@ -185,11 +197,17 @@
               # Try to terminate all other connections that might prevent
               # dropping the database
               try:
  -                cr.execute("""SELECT pg_terminate_backend(procpid)
  +
  +                # PostgreSQL 9.2 renamed pg_stat_activity.procpid to pid:
  +                # http://www.postgresql.org/docs/9.2/static/release-9-2.html#AEN110389
  +                pid_col = 'pid' if cr._cnx.server_version >= 90200 else 'procpid'
  +
  +                cr.execute("""SELECT pg_terminate_backend(%(pid_col)s)
                                 FROM pg_stat_activity
  -                              WHERE datname = %s AND 
  -                                    procpid != pg_backend_pid()""",
  +                              WHERE datname = %%s AND 
  +                                    %(pid_col)s != pg_backend_pid()""" % {'pid_col': pid_col},
                              (db_name,))
  +
               except Exception:
                   pass

To manage notifications about this bug go to:
https://bugs.launchpad.net/ocb-server/+bug/1319843/+subscriptions