Browse Source

Add support for multivalue field deletion (unstested)

Yann Weber 8 years ago
parent
commit
aaaf0af558
1 changed files with 26 additions and 0 deletions
  1. 26
    0
      DataSource/MySQL/migrationhandler.py

+ 26
- 0
DataSource/MySQL/migrationhandler.py View File

220
         if not isinstance(emfield, EditorialModel.fields.EmField):
220
         if not isinstance(emfield, EditorialModel.fields.EmField):
221
             raise ValueError("The given uid is not an EmField uid")
221
             raise ValueError("The given uid is not an EmField uid")
222
 
222
 
223
+        if isinstance(emfield.fieldtype_instance(), MultiValueFieldType):
224
+            return self._del_column_multivalue(emfield)
225
+
223
         emclass = emfield.em_class
226
         emclass = emfield.em_class
224
         tname = utils.object_table_name(emclass.name)
227
         tname = utils.object_table_name(emclass.name)
225
         # Delete the table triggers to prevent errors
228
         # Delete the table triggers to prevent errors
455
         # adding the column
458
         # adding the column
456
         self._add_column(table_name, col_name, col_ftype)
459
         self._add_column(table_name, col_name, col_ftype)
457
 
460
 
461
+    ## @brief Delete a multivalue column
462
+    # @param emfield EmField : EmField instance
463
+    # @note untested
464
+    def _del_column_multivalue(self, emfield):
465
+        ftype = emfield.fieldtype_instance()
466
+        if not isinstance(ftype, MultiValueFieldType):
467
+            raise ValueError("Except an emfield with multivalue fieldtype")
468
+        tname = utils.object_table_name(emfield.em_class.name)
469
+        tname = utils.multivalue_table_name(tname, ftype.keyname)
470
+        self._del_column(tname, emfield.name)
471
+        if len([ f for f in emfield.em_class.fields()]) == 0:
472
+            try:
473
+                self._query("DROP TABLE %s;" % utils.escape_idname(tname))
474
+            except self._dbmodule.err.InternalError as expt:
475
+                print(expt)
476
+
458
 
477
 
459
     ## @brief Add a foreign key
478
     ## @brief Add a foreign key
460
     # @param src_table_name str : The name of the table where we will add the FK
479
     # @param src_table_name str : The name of the table where we will add the FK
549
     ## @brief Delete all table created by the MH
568
     ## @brief Delete all table created by the MH
550
     # @param model Model : the Editorial model
569
     # @param model Model : the Editorial model
551
     def __purge_db(self, model):
570
     def __purge_db(self, model):
571
+        for uid in [
572
+                    field
573
+                    for field in model.components('EmField')
574
+                    if isinstance(field.fieldtype_instance(), MultiValueFieldType)
575
+        ]:
576
+            self._del_column_multivalue(field)
577
+
552
         for uid in [c.uid for c in model.components('EmClass')]:
578
         for uid in [c.uid for c in model.components('EmClass')]:
553
             try:
579
             try:
554
                 self.delete_emclass_table(model, uid)
580
                 self.delete_emclass_table(model, uid)

Loading…
Cancel
Save