hooks/syncschema.py
branchstable
changeset 7879 9aae456abab5
parent 7815 2a164a9cf81c
child 7880 f475a34d0ddc
equal deleted inserted replaced
7874:be04706eacc9 7879:9aae456abab5
   244     * create the necessary table
   244     * create the necessary table
   245     * set creation_date and modification_date by creating the necessary
   245     * set creation_date and modification_date by creating the necessary
   246       CWAttribute entities
   246       CWAttribute entities
   247     * add owned_by relation by creating the necessary CWRelation entity
   247     * add owned_by relation by creating the necessary CWRelation entity
   248     """
   248     """
       
   249     entity = None # make pylint happy
   249 
   250 
   250     def precommit_event(self):
   251     def precommit_event(self):
   251         session = self.session
   252         session = self.session
   252         entity = self.entity
   253         entity = self.entity
   253         schema = session.vreg.schema
   254         schema = session.vreg.schema
   757 
   758 
   758 # operations for in-memory schema synchronization  #############################
   759 # operations for in-memory schema synchronization  #############################
   759 
   760 
   760 class MemSchemaCWETypeDel(MemSchemaOperation):
   761 class MemSchemaCWETypeDel(MemSchemaOperation):
   761     """actually remove the entity type from the instance's schema"""
   762     """actually remove the entity type from the instance's schema"""
       
   763     etype = None # make pylint happy
       
   764 
   762     def postcommit_event(self):
   765     def postcommit_event(self):
   763         # del_entity_type also removes entity's relations
   766         # del_entity_type also removes entity's relations
   764         self.session.vreg.schema.del_entity_type(self.etype)
   767         self.session.vreg.schema.del_entity_type(self.etype)
   765 
   768 
   766 
   769 
   767 class MemSchemaCWRTypeAdd(MemSchemaOperation):
   770 class MemSchemaCWRTypeAdd(MemSchemaOperation):
   768     """actually add the relation type to the instance's schema"""
   771     """actually add the relation type to the instance's schema"""
       
   772     rtypedef = None # make pylint happy
       
   773 
   769     def precommit_event(self):
   774     def precommit_event(self):
   770         self.session.vreg.schema.add_relation_type(self.rtypedef)
   775         self.session.vreg.schema.add_relation_type(self.rtypedef)
   771 
   776 
   772     def revertprecommit_event(self):
   777     def revertprecommit_event(self):
   773         self.session.vreg.schema.del_relation_type(self.rtypedef.name)
   778         self.session.vreg.schema.del_relation_type(self.rtypedef.name)
   774 
   779 
   775 
   780 
   776 class MemSchemaCWRTypeDel(MemSchemaOperation):
   781 class MemSchemaCWRTypeDel(MemSchemaOperation):
   777     """actually remove the relation type from the instance's schema"""
   782     """actually remove the relation type from the instance's schema"""
       
   783     rtype = None # make pylint happy
       
   784 
   778     def postcommit_event(self):
   785     def postcommit_event(self):
   779         try:
   786         try:
   780             self.session.vreg.schema.del_relation_type(self.rtype)
   787             self.session.vreg.schema.del_relation_type(self.rtype)
   781         except KeyError:
   788         except KeyError:
   782             # s/o entity type have already been deleted
   789             # s/o entity type have already been deleted
   784 
   791 
   785 
   792 
   786 class MemSchemaPermissionAdd(MemSchemaOperation):
   793 class MemSchemaPermissionAdd(MemSchemaOperation):
   787     """synchronize schema when a *_permission relation has been added on a group
   794     """synchronize schema when a *_permission relation has been added on a group
   788     """
   795     """
       
   796     eid = action = group_eid = expr = None # make pylint happy
   789 
   797 
   790     def precommit_event(self):
   798     def precommit_event(self):
   791         """the observed connections.cnxset has been commited"""
   799         """the observed connections.cnxset has been commited"""
   792         try:
   800         try:
   793             erschema = self.session.vreg.schema.schema_by_eid(self.eid)
   801             erschema = self.session.vreg.schema.schema_by_eid(self.eid)
   843 
   851 
   844     # XXX revertprecommit_event
   852     # XXX revertprecommit_event
   845 
   853 
   846 
   854 
   847 class MemSchemaSpecializesAdd(MemSchemaOperation):
   855 class MemSchemaSpecializesAdd(MemSchemaOperation):
       
   856     etypeeid = parentetypeeid = None # make pylint happy
   848 
   857 
   849     def precommit_event(self):
   858     def precommit_event(self):
   850         eschema = self.session.vreg.schema.schema_by_eid(self.etypeeid)
   859         eschema = self.session.vreg.schema.schema_by_eid(self.etypeeid)
   851         parenteschema = self.session.vreg.schema.schema_by_eid(self.parentetypeeid)
   860         parenteschema = self.session.vreg.schema.schema_by_eid(self.parentetypeeid)
   852         eschema._specialized_type = parenteschema.type
   861         eschema._specialized_type = parenteschema.type
   854 
   863 
   855     # XXX revertprecommit_event
   864     # XXX revertprecommit_event
   856 
   865 
   857 
   866 
   858 class MemSchemaSpecializesDel(MemSchemaOperation):
   867 class MemSchemaSpecializesDel(MemSchemaOperation):
       
   868     etypeeid = parentetypeeid = None # make pylint happy
   859 
   869 
   860     def precommit_event(self):
   870     def precommit_event(self):
   861         try:
   871         try:
   862             eschema = self.session.vreg.schema.schema_by_eid(self.etypeeid)
   872             eschema = self.session.vreg.schema.schema_by_eid(self.etypeeid)
   863             parenteschema = self.session.vreg.schema.schema_by_eid(self.parentetypeeid)
   873             parenteschema = self.session.vreg.schema.schema_by_eid(self.parentetypeeid)