cubicweb/misc/migration/bootstrapmigration_repository.py
changeset 11763 39df042f4ab4
parent 11246 ceb0e8e9129e
child 11767 432f87a63057
equal deleted inserted replaced
11762:7518cb58ab4c 11763:39df042f4ab4
    67     attrtype = y2sql.type_from_constraints(dbhelper, rdefdef.object, rdefdef.constraints).split()[0]
    67     attrtype = y2sql.type_from_constraints(dbhelper, rdefdef.object, rdefdef.constraints).split()[0]
    68     cursor = session.cnxset.cu
    68     cursor = session.cnxset.cu
    69     sql('UPDATE entities SET asource = source WHERE asource is NULL')
    69     sql('UPDATE entities SET asource = source WHERE asource is NULL')
    70     dbhelper.change_col_type(cursor, 'entities', 'asource', attrtype, False)
    70     dbhelper.change_col_type(cursor, 'entities', 'asource', attrtype, False)
    71     dbhelper.change_col_type(cursor, 'entities', 'source', attrtype, False)
    71     dbhelper.change_col_type(cursor, 'entities', 'source', attrtype, False)
    72 
       
    73     # we now have a functional asource column, start using the normal eid_type_source method
       
    74     if repo.system_source.eid_type_source == repo.system_source.eid_type_source_pre_131:
       
    75         del repo.system_source.eid_type_source
       
    76 
    72 
    77 if applcubicwebversion < (3, 19, 0) and cubicwebversion >= (3, 19, 0):
    73 if applcubicwebversion < (3, 19, 0) and cubicwebversion >= (3, 19, 0):
    78     try: 
    74     try: 
    79         # need explicit drop of the indexes on some database systems (sqlserver)
    75         # need explicit drop of the indexes on some database systems (sqlserver)
    80         sql(repo.system_source.dbhelper.sql_drop_index('entities', 'mtime'))
    76         sql(repo.system_source.dbhelper.sql_drop_index('entities', 'mtime'))
   337     rql('SET C relations RT WHERE C relations RDEF, RDEF relation_type RT')
   333     rql('SET C relations RT WHERE C relations RDEF, RDEF relation_type RT')
   338     commit()
   334     commit()
   339     drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWAttribute')
   335     drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWAttribute')
   340     drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWRelation')
   336     drop_relation_definition('CWUniqueTogetherConstraint', 'relations', 'CWRelation')
   341 
   337 
   342 
       
   343 if applcubicwebversion < (3, 4, 0) and cubicwebversion >= (3, 4, 0):
       
   344 
       
   345     with hooks_control(session, session.HOOKS_ALLOW_ALL, 'integrity'):
       
   346         session.set_shared_data('do-not-insert-cwuri', True)
       
   347         add_relation_type('cwuri')
       
   348         base_url = session.base_url()
       
   349         for eid, in rql('Any X', ask_confirm=False):
       
   350             type, source, extid = session.describe(eid)
       
   351             if source == 'system':
       
   352                 rql('SET X cwuri %(u)s WHERE X eid %(x)s',
       
   353                     {'x': eid, 'u': u'%s%s' % (base_url, eid)})
       
   354         isession.commit()
       
   355         session.set_shared_data('do-not-insert-cwuri', False)
       
   356 
       
   357 if applcubicwebversion < (3, 5, 0) and cubicwebversion >= (3, 5, 0):
   338 if applcubicwebversion < (3, 5, 0) and cubicwebversion >= (3, 5, 0):
   358     # check that migration is not doomed
   339     # check that migration is not doomed
   359     rset = rql('Any X,Y WHERE X transition_of E, Y transition_of E, '
   340     rset = rql('Any X,Y WHERE X transition_of E, Y transition_of E, '
   360                'X name N, Y name N, NOT X identity Y',
   341                'X name N, Y name N, NOT X identity Y',
   361                ask_confirm=False)
   342                ask_confirm=False)