81 etype, rschema, rschema) |
81 etype, rschema, rschema) |
82 print sql |
82 print sql |
83 sqlcu.execute(sql) |
83 sqlcu.execute(sql) |
84 |
84 |
85 # schema / perms deserialization ############################################## |
85 # schema / perms deserialization ############################################## |
|
86 OLD_SCHEMA_TYPES = frozenset(('EFRDef', 'ENFRDef', 'ERType', 'EEType', |
|
87 'EConstraintType', 'EConstraint', 'EGroup', |
|
88 'EUser', 'ECache', 'EPermission', 'EProperty')) |
86 |
89 |
87 def deserialize_schema(schema, session): |
90 def deserialize_schema(schema, session): |
88 """return a schema according to information stored in an rql database |
91 """return a schema according to information stored in an rql database |
89 as CWRType and CWEType entities |
92 as CWRType and CWEType entities |
90 """ |
93 """ |
91 # |
94 # |
92 repo = session.repo |
95 repo = session.repo |
93 sqlcu = session.pool['system'] |
96 sqlcu = session.pool['system'] |
94 _3_2_migration = False |
97 _3_2_migration = False |
95 tables = set(t.lower() for t in repo.system_source.dbhelper.list_tables(sqlcu)) |
98 dbhelper = repo.system_source.dbhelper |
|
99 tables = set(t.lower() for t in dbhelper.list_tables(sqlcu)) |
96 if 'eetype' in tables: |
100 if 'eetype' in tables: |
97 _3_2_migration = True |
101 _3_2_migration = True |
98 # 3.2 migration |
102 # 3.2 migration |
99 _set_sql_prefix('') |
103 _set_sql_prefix('') |
100 # first rename entity types whose name changed in 3.2 without adding the |
104 # first rename entity types whose name changed in 3.2 without adding the |
101 # cw_ prefix |
105 # cw_ prefix |
102 for etype in ('EFRDef', 'ENFRDef', 'ERType', 'EEType', |
106 for etype in OLD_SCHEMA_TYPES: |
103 'EConstraintType', 'EConstraint', 'EGroup', 'EUser', |
|
104 'ECache', 'EPermission', 'EProperty'): |
|
105 if etype.lower() in tables: |
107 if etype.lower() in tables: |
106 sql = 'ALTER TABLE %s RENAME TO %s' % (etype, |
108 sql = 'ALTER TABLE %s RENAME TO %s' % (etype, |
107 ETYPE_NAME_MAP[etype]) |
109 ETYPE_NAME_MAP[etype]) |
108 print sql |
110 print sql |
109 sqlcu.execute(sql) |
111 sqlcu.execute(sql) |
121 # just set the eid |
123 # just set the eid |
122 eschema = schema.eschema(etype) |
124 eschema = schema.eschema(etype) |
123 eschema.eid = eid |
125 eschema.eid = eid |
124 index[eid] = eschema |
126 index[eid] = eschema |
125 continue |
127 continue |
126 if etype in ETYPE_NAME_MAP: # XXX <2.45 bw compat |
128 if etype in ETYPE_NAME_MAP: |
127 print 'fixing etype name from %s to %s' % (etype, ETYPE_NAME_MAP[etype]) |
129 netype = ETYPE_NAME_MAP[etype] |
|
130 print 'fixing etype name from %s to %s' % (etype, netype) |
128 # can't use write rql queries at this point, use raw sql |
131 # can't use write rql queries at this point, use raw sql |
129 session.system_sql('UPDATE %(p)sCWEType SET %(p)sname=%%(n)s WHERE %(p)seid=%%(x)s' |
132 session.system_sql('UPDATE %(p)sCWEType SET %(p)sname=%%(n)s WHERE %(p)seid=%%(x)s' |
130 % {'p': sqlutils.SQL_PREFIX}, |
133 % {'p': sqlutils.SQL_PREFIX}, |
131 {'x': eid, 'n': ETYPE_NAME_MAP[etype]}) |
134 {'x': eid, 'n': netype}) |
132 session.system_sql('UPDATE entities SET type=%(n)s WHERE type=%(x)s', |
135 session.system_sql('UPDATE entities SET type=%(n)s WHERE type=%(x)s', |
133 {'x': etype, 'n': ETYPE_NAME_MAP[etype]}) |
136 {'x': etype, 'n': netype}) |
|
137 # XXX should be donne as well on sqlite based sources |
|
138 if not etype in OLD_SCHEMA_TYPES and \ |
|
139 (getattr(dbhelper, 'case_sensitive', False) |
|
140 or etype.lower() != netype.lower()): |
|
141 session.system_sql('ALTER TABLE %s%s RENAME TO %s%s' % ( |
|
142 sqlutils.SQL_PREFIX, etype, sqlutils.SQL_PREFIX, netype)) |
134 session.commit(False) |
143 session.commit(False) |
135 try: |
144 try: |
136 session.system_sql('UPDATE deleted_entities SET type=%(n)s WHERE type=%(x)s', |
145 session.system_sql('UPDATE deleted_entities SET type=%(n)s WHERE type=%(x)s', |
137 {'x': etype, 'n': ETYPE_NAME_MAP[etype]}) |
146 {'x': etype, 'n': netype}) |
138 except: |
147 except: |
139 pass |
148 pass |
140 tocleanup = [eid] |
149 tocleanup = [eid] |
141 tocleanup += (eid for eid, (eidetype, uri, extid) in repo._type_source_cache.items() |
150 tocleanup += (eid for eid, (eidetype, uri, extid) in repo._type_source_cache.items() |
142 if etype == eidetype) |
151 if etype == eidetype) |
143 repo.clear_caches(tocleanup) |
152 repo.clear_caches(tocleanup) |
144 session.commit(False) |
153 session.commit(False) |
145 etype = ETYPE_NAME_MAP[etype] |
154 etype = netype |
146 etype = ybo.EntityType(name=etype, description=desc, meta=meta, eid=eid) |
155 etype = ybo.EntityType(name=etype, description=desc, meta=meta, eid=eid) |
147 eschema = schema.add_entity_type(etype) |
156 eschema = schema.add_entity_type(etype) |
148 index[eid] = eschema |
157 index[eid] = eschema |
149 set_perms(eschema, permsdict.get(eid, {})) |
158 set_perms(eschema, permsdict.get(eid, {})) |
150 try: |
159 try: |