31 |
31 |
32 from yams.constraints import SizeConstraint |
32 from yams.constraints import SizeConstraint |
33 from yams.schema2sql import eschema2sql, rschema2sql |
33 from yams.schema2sql import eschema2sql, rschema2sql |
34 |
34 |
35 from cubicweb import AuthenticationError, ETYPE_NAME_MAP |
35 from cubicweb import AuthenticationError, ETYPE_NAME_MAP |
36 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CubicWebRelationSchema |
36 from cubicweb.schema import (META_RTYPES, VIRTUAL_RTYPES, |
|
37 CubicWebRelationSchema, order_eschemas) |
37 from cubicweb.dbapi import get_repository, repo_connect |
38 from cubicweb.dbapi import get_repository, repo_connect |
38 from cubicweb.common.migration import MigrationHelper, yes |
39 from cubicweb.common.migration import MigrationHelper, yes |
39 |
40 |
40 try: |
41 try: |
41 from cubicweb.server import SOURCE_TYPES, schemaserial as ss |
42 from cubicweb.server import SOURCE_TYPES, schemaserial as ss |
516 # add new entity and relation types |
517 # add new entity and relation types |
517 for rschema in newcubes_schema.relations(): |
518 for rschema in newcubes_schema.relations(): |
518 if not rschema in self.repo.schema: |
519 if not rschema in self.repo.schema: |
519 self.cmd_add_relation_type(rschema.type) |
520 self.cmd_add_relation_type(rschema.type) |
520 new.add(rschema.type) |
521 new.add(rschema.type) |
521 for eschema in newcubes_schema.entities(): |
522 toadd = [eschema for eschema in newcubes_schema.entities() |
522 if not eschema in self.repo.schema: |
523 if not eschema in self.repo.schema] |
523 self.cmd_add_entity_type(eschema.type) |
524 for eschema in order_eschemas(toadd): |
524 new.add(eschema.type) |
525 self.cmd_add_entity_type(eschema.type) |
|
526 new.add(eschema.type) |
525 # check if attributes has been added to existing entities |
527 # check if attributes has been added to existing entities |
526 for rschema in newcubes_schema.relations(): |
528 for rschema in newcubes_schema.relations(): |
527 existingschema = self.repo.schema.rschema(rschema.type) |
529 existingschema = self.repo.schema.rschema(rschema.type) |
528 for (fromtype, totype) in rschema.iter_rdefs(): |
530 for (fromtype, totype) in rschema.iter_rdefs(): |
529 if existingschema.has_rdef(fromtype, totype): |
531 if existingschema.has_rdef(fromtype, totype): |
551 self.exec_event_script('preremove', self.config.cube_dir(pack)) |
553 self.exec_event_script('preremove', self.config.cube_dir(pack)) |
552 # remove cubes'entity and relation types |
554 # remove cubes'entity and relation types |
553 for rschema in fsschema.relations(): |
555 for rschema in fsschema.relations(): |
554 if not rschema in removedcubes_schema and rschema in reposchema: |
556 if not rschema in removedcubes_schema and rschema in reposchema: |
555 self.cmd_drop_relation_type(rschema.type) |
557 self.cmd_drop_relation_type(rschema.type) |
556 for eschema in fsschema.entities(): |
558 toremove = [eschema for eschema in fsschema.entities() |
557 if not eschema in removedcubes_schema and eschema in reposchema: |
559 if not eschema in removedcubes_schema |
558 self.cmd_drop_entity_type(eschema.type) |
560 and eschema in reposchema] |
|
561 for eschema in reversed(order_eschemas(toremove)): |
|
562 self.cmd_drop_entity_type(eschema.type) |
559 for rschema in fsschema.relations(): |
563 for rschema in fsschema.relations(): |
560 if rschema in removedcubes_schema and rschema in reposchema: |
564 if rschema in removedcubes_schema and rschema in reposchema: |
561 # check if attributes/relations has been added to entities from |
565 # check if attributes/relations has been added to entities from |
562 # other cubes |
566 # other cubes |
563 for fromtype, totype in rschema.iter_rdefs(): |
567 for fromtype, totype in rschema.iter_rdefs(): |