58 CubicWebRelationSchema, order_eschemas) |
58 CubicWebRelationSchema, order_eschemas) |
59 from cubicweb.cwvreg import CW_EVENT_MANAGER |
59 from cubicweb.cwvreg import CW_EVENT_MANAGER |
60 from cubicweb import repoapi |
60 from cubicweb import repoapi |
61 from cubicweb.migration import MigrationHelper, yes |
61 from cubicweb.migration import MigrationHelper, yes |
62 from cubicweb.server import hook, schemaserial as ss |
62 from cubicweb.server import hook, schemaserial as ss |
63 from cubicweb.server.schema2sql import eschema2sql, rschema2sql, unique_index_name |
63 from cubicweb.server.schema2sql import eschema2sql, rschema2sql, unique_index_name, sql_type |
64 from cubicweb.server.utils import manager_userpasswd |
64 from cubicweb.server.utils import manager_userpasswd |
65 from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX |
65 from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX |
66 |
66 |
67 |
67 |
68 class ClearGroupMap(hook.Hook): |
68 class ClearGroupMap(hook.Hook): |
1506 sql = ("UPDATE cw_CWAttribute " |
1506 sql = ("UPDATE cw_CWAttribute " |
1507 "SET cw_to_entity=(SELECT cw_eid FROM cw_CWEType WHERE cw_name='%s')" |
1507 "SET cw_to_entity=(SELECT cw_eid FROM cw_CWEType WHERE cw_name='%s')" |
1508 "WHERE cw_eid=%s") % (newtype, rdef.eid) |
1508 "WHERE cw_eid=%s") % (newtype, rdef.eid) |
1509 self.sqlexec(sql, ask_confirm=False) |
1509 self.sqlexec(sql, ask_confirm=False) |
1510 dbhelper = self.repo.system_source.dbhelper |
1510 dbhelper = self.repo.system_source.dbhelper |
1511 sqltype = dbhelper.TYPE_MAPPING[newtype] |
1511 newrdef = self.fs_schema.rschema(attr).rdef(etype, newtype) |
|
1512 sqltype = sql_type(dbhelper, newrdef) |
1512 cursor = self.cnx.cnxset.cu |
1513 cursor = self.cnx.cnxset.cu |
|
1514 # consider former cardinality by design, since cardinality change is not handled here |
1513 allownull = rdef.cardinality[0] != '1' |
1515 allownull = rdef.cardinality[0] != '1' |
1514 dbhelper.change_col_type(cursor, 'cw_%s' % etype, 'cw_%s' % attr, sqltype, allownull) |
1516 dbhelper.change_col_type(cursor, 'cw_%s' % etype, 'cw_%s' % attr, sqltype, allownull) |
1515 if commit: |
1517 if commit: |
1516 self.commit() |
1518 self.commit() |
1517 # manually update live schema |
1519 # manually update live schema |