|
@@ -52,6 +52,28 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
|
52
|
52
|
self._create_default_tables(self.drop_if_exists)
|
53
|
53
|
pass
|
54
|
54
|
|
|
55
|
+ ## @brief Delete all table created by the MH
|
|
56
|
+ # @param model Model : the Editorial model
|
|
57
|
+ def __purge_db(self, model):
|
|
58
|
+ for uid in [c.uid for c in model.components('EmClass')]:
|
|
59
|
+ try:
|
|
60
|
+ self.delete_emclass_table(model, uid)
|
|
61
|
+ except pymysql.err.InternalError as e:
|
|
62
|
+ print(e)
|
|
63
|
+
|
|
64
|
+ for tname in [ MySQL.get_r2t2table_name(f.em_class.name, model.component(f.rel_to_type_id).name) for f in model.components('EmField') if f.fieldtype == 'rel2type' ]:
|
|
65
|
+ try:
|
|
66
|
+ self._query("DROP TABLE %s;"%tname)
|
|
67
|
+ except pymysql.err.InternalError as e:
|
|
68
|
+ print(e)
|
|
69
|
+
|
|
70
|
+ for tname in [ MySQL.relations_table_name, MySQL.objects_table_name ]:
|
|
71
|
+ try:
|
|
72
|
+ self._query("DROP TABLE %s;"%tname)
|
|
73
|
+ except pymysql.err.InternalError as e:
|
|
74
|
+ print(e)
|
|
75
|
+
|
|
76
|
+
|
55
|
77
|
## @brief Modify the db given an EM change
|
56
|
78
|
#
|
57
|
79
|
# @param em model : The EditorialModel.model object to provide the global context
|
|
@@ -185,13 +207,15 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
|
185
|
207
|
# @param em Model : A Model instance
|
186
|
208
|
# @param uid int : An EmField uid
|
187
|
209
|
def delete_emclass_table(self, em, uid):
|
188
|
|
- emclass = emcomponent(uid)
|
|
210
|
+ emclass = em.component(uid)
|
189
|
211
|
if not isinstance(emclass, EditorialModel.classes.EmClass):
|
190
|
212
|
raise ValueError("The give uid is not an EmClass uid")
|
191
|
|
- tname = self.datasource.escape_idname(self._emclass2table_name(emclass))
|
|
213
|
+ tname = self._emclass2table_name(emclass)
|
192
|
214
|
# Delete the table triggers to prevent errors
|
193
|
215
|
self._generate_triggers(tname, dict())
|
194
|
216
|
|
|
217
|
+ tname = self.datasource.escape_idname(tname)
|
|
218
|
+
|
195
|
219
|
self._query("""DROP TABLE {table_name};""".format(table_name = tname))
|
196
|
220
|
|
197
|
221
|
## @brief Given an EmField delete the corresponding column
|