server/migractions.py
branchstable
changeset 2107 6c4a4c514ac2
parent 1977 606923dff11b
child 2122 4ea13a828513
equal deleted inserted replaced
2106:2295f2aba61d 2107:6c4a4c514ac2
    21 import os
    21 import os
    22 from os.path import join, exists
    22 from os.path import join, exists
    23 from datetime import datetime
    23 from datetime import datetime
    24 
    24 
    25 from logilab.common.deprecation import deprecated_function, obsolete
    25 from logilab.common.deprecation import deprecated_function, obsolete
    26 from logilab.common.decorators import cached
    26 from logilab.common.decorators import cached, clear_cache
    27 from logilab.common.adbh import get_adv_func_helper
    27 from logilab.common.adbh import get_adv_func_helper
    28 
    28 
    29 from yams.constraints import SizeConstraint
    29 from yams.constraints import SizeConstraint
    30 from yams.schema2sql import eschema2sql, rschema2sql
    30 from yams.schema2sql import eschema2sql, rschema2sql
    31 
    31 
    33 from cubicweb.schema import CubicWebRelationSchema
    33 from cubicweb.schema import CubicWebRelationSchema
    34 from cubicweb.dbapi import get_repository, repo_connect
    34 from cubicweb.dbapi import get_repository, repo_connect
    35 from cubicweb.common.migration import MigrationHelper, yes
    35 from cubicweb.common.migration import MigrationHelper, yes
    36 
    36 
    37 try:
    37 try:
    38     from cubicweb.server import schemaserial as ss
    38     from cubicweb.server import SOURCE_TYPES, schemaserial as ss
    39     from cubicweb.server.utils import manager_userpasswd
    39     from cubicweb.server.utils import manager_userpasswd, ask_source_config
    40     from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX
    40     from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX
    41 except ImportError: # LAX
    41 except ImportError: # LAX
    42     pass
    42     pass
    43 
    43 
    44 
    44 
    75 
    75 
    76     def rewrite_vcconfiguration(self):
    76     def rewrite_vcconfiguration(self):
    77         """write current installed versions (of cubicweb software
    77         """write current installed versions (of cubicweb software
    78         and of each used cube) into the database
    78         and of each used cube) into the database
    79         """
    79         """
    80         self.cmd_set_property('system.version.cubicweb', self.config.cubicweb_version())
    80         self.cmd_set_property('system.version.cubicweb',
       
    81                               self.config.cubicweb_version())
    81         for pkg in self.config.cubes():
    82         for pkg in self.config.cubes():
    82             pkgversion = self.config.cube_version(pkg)
    83             pkgversion = self.config.cube_version(pkg)
    83             self.cmd_set_property('system.version.%s' % pkg.lower(), pkgversion)
    84             self.cmd_set_property('system.version.%s' % pkg.lower(), pkgversion)
    84         self.commit()
    85         self.commit()
    85 
    86 
   477         cube schema is already in there)
   478         cube schema is already in there)
   478         """
   479         """
   479         newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes)
   480         newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes)
   480         if not newcubes:
   481         if not newcubes:
   481             return
   482             return
   482         for pack in newcubes:
   483         for cube in newcubes:
   483             self.cmd_set_property('system.version.'+pack,
   484             self.cmd_set_property('system.version.'+cube,
   484                                   self.config.cube_version(pack))
   485                                   self.config.cube_version(cube))
       
   486             if cube in SOURCE_TYPES:
       
   487                 # don't use config.sources() in case some sources have been
       
   488                 # disabled for migration
       
   489                 sourcescfg = self.config.read_sources_file()
       
   490                 sourcescfg[cube] = ask_source_config(cube)
       
   491                 self.config.write_sources_file(sourcescfg)
       
   492                 clear_cache(self.config, 'read_sources_file')
   485         if not update_database:
   493         if not update_database:
   486             self.commit()
   494             self.commit()
   487             return
   495             return
   488         newcubes_schema = self.config.load_schema(construction_mode='non-strict')
   496         newcubes_schema = self.config.load_schema(construction_mode='non-strict')
   489         new = set()
   497         new = set()
   686 
   694 
   687         `oldname` is a string giving the name of the existing entity type
   695         `oldname` is a string giving the name of the existing entity type
   688         `newname` is a string giving the name of the renamed entity type
   696         `newname` is a string giving the name of the renamed entity type
   689         """
   697         """
   690         self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(oldname)s',
   698         self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(oldname)s',
   691                      {'newname' : unicode(newname), 'oldname' : oldname})
   699                      {'newname' : unicode(newname), 'oldname' : oldname},
       
   700                      ask_confirm=False)
   692         if commit:
   701         if commit:
   693             self.commit()
   702             self.commit()
   694 
   703 
   695     def cmd_add_relation_type(self, rtype, addrdef=True, commit=True):
   704     def cmd_add_relation_type(self, rtype, addrdef=True, commit=True):
   696         """register a new relation type named `rtype`, as described in the
   705         """register a new relation type named `rtype`, as described in the