equal
deleted
inserted
replaced
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() |
513 # execute post-create files |
521 # execute post-create files |
514 for pack in reversed(newcubes): |
522 for pack in reversed(newcubes): |
515 self.exec_event_script('postcreate', self.config.cube_dir(pack)) |
523 self.exec_event_script('postcreate', self.config.cube_dir(pack)) |
516 self.commit() |
524 self.commit() |
517 |
525 |
518 def cmd_remove_cube(self, cube): |
526 def cmd_remove_cube(self, cube, removedeps=False): |
519 removedcubes = super(ServerMigrationHelper, self).cmd_remove_cube(cube) |
527 removedcubes = super(ServerMigrationHelper, self).cmd_remove_cube( |
|
528 cube, removedeps) |
520 if not removedcubes: |
529 if not removedcubes: |
521 return |
530 return |
522 fsschema = self.fs_schema |
531 fsschema = self.fs_schema |
523 removedcubes_schema = self.config.load_schema(construction_mode='non-strict') |
532 removedcubes_schema = self.config.load_schema(construction_mode='non-strict') |
524 reposchema = self.repo.schema |
533 reposchema = self.repo.schema |
686 |
695 |
687 `oldname` is a string giving the name of the existing entity type |
696 `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 |
697 `newname` is a string giving the name of the renamed entity type |
689 """ |
698 """ |
690 self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(oldname)s', |
699 self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(oldname)s', |
691 {'newname' : unicode(newname), 'oldname' : oldname}) |
700 {'newname' : unicode(newname), 'oldname' : oldname}, |
|
701 ask_confirm=False) |
692 if commit: |
702 if commit: |
693 self.commit() |
703 self.commit() |
694 |
704 |
695 def cmd_add_relation_type(self, rtype, addrdef=True, commit=True): |
705 def cmd_add_relation_type(self, rtype, addrdef=True, commit=True): |
696 """register a new relation type named `rtype`, as described in the |
706 """register a new relation type named `rtype`, as described in the |