misc/migration/3.14.4_Any.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 23 Apr 2012 18:01:30 +0200
branchstable
changeset 8374 04054efc0a54
parent 8263 a73ad255ff63
child 8375 7d8979176bc0
permissions -rw-r--r--
[migration/3.14.4] prevent migration crash when there are NULLs in asource

from yams import schema2sql as y2sql

dbhelper = repo.system_source.dbhelper
rdefdef = schema['CWSource'].rdef('name')
attrtype = y2sql.type_from_constraints(dbhelper, rdefdef.object, rdefdef.constraints).split()[0]

cursor = session.cnxset['system']
rql('UPDATE entities SET asource = source WHERE asource is NULL')
dbhelper.change_col_type(cursor, 'entities', 'asource', attrtype, False)
dbhelper.change_col_type(cursor, 'entities', 'source', attrtype, False)
dbhelper.change_col_type(cursor, 'deleted_entities', 'source', attrtype, False)