Browse Source

Better comments for MySQL MH

Yann Weber 9 years ago
parent
commit
3e3114a0b2
1 changed files with 16 additions and 10 deletions
  1. 16
    10
      EditorialModel/migrationhandler/mysql.py

+ 16
- 10
EditorialModel/migrationhandler/mysql.py View File

@@ -53,6 +53,12 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
53 53
         pass
54 54
     
55 55
     ## @brief Modify the db given an EM change
56
+    # 
57
+    # @param em model : The EditorialModel.model object to provide the global context
58
+    # @param uid int : The uid of the change EmComponent
59
+    # @param initial_state dict | None : dict with field name as key and field value as value. Representing the original state. None mean creation of a new component.
60
+    # @param new_state dict | None : dict with field name as key and field value as value. Representing the new state. None mean component deletion
61
+    # @throw EditorialModel.exceptions.MigrationHandlerChangeError if the change was refused
56 62
     def register_change(self, em, uid, initial_state, new_state, engine = None):
57 63
         if engine is None:
58 64
             engine = self.db_engine
@@ -83,11 +89,14 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
83 89
                 elif new_state is None:
84 90
                     #Rel2type attr deletion
85 91
                     self.del_relationnal_field(em, uid)
92
+
86 93
     ## @brief dumdumdummy
94
+    # @note implemented to avoid the log message of EditorialModel.migrationhandler.dummy.DummyMigrationHandler
87 95
     def register_model_state(self, em, state_hash):
88 96
         pass
89 97
 
90 98
     ## @brief Exec a query
99
+    # @param query str : SQL query
91 100
     def _query(self, query):
92 101
         if self.debug:
93 102
             print(query+"\n")
@@ -146,7 +155,6 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
146 155
     ## @brief Given an EmField uid add a column to the corresponding table
147 156
     # @param em Model : A Model instance
148 157
     # @param uid int : An EmField uid
149
-    # @return None
150 158
     def add_col_from_emfield(self, em, uid):
151 159
         emfield = em.component(uid)
152 160
         if not isinstance(emfield, EditorialModel.fields.EmField):
@@ -160,6 +168,8 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
160 168
         self._generate_triggers(tname, cols_l)
161 169
 
162 170
     ## @brief Given a class uid create the coressponding table
171
+    # @param em Model : A Model instance
172
+    # @param uid int : An EmField uid
163 173
     def create_emclass_table(self, em, uid, engine):
164 174
         emclass = em.component(uid)
165 175
         if not isinstance(emclass, EditorialModel.classes.EmClass):
@@ -172,6 +182,8 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
172 182
             self._add_fk(table_name, self.datasource.objects_table_name, pkname, pkname)
173 183
     
174 184
     ## @brief Given an EmClass uid delete the corresponding table
185
+    # @param em Model : A Model instance
186
+    # @param uid int : An EmField uid
175 187
     def delete_emclass_table(self, em, uid):
176 188
         emclass = emcomponent(uid)
177 189
         if not isinstance(emclass, EditorialModel.classes.EmClass):
@@ -277,7 +289,6 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
277 289
     # @param engine str : The engine to use with this table
278 290
     # @param charset str : The charset of this table
279 291
     # @param if_exist str : takes values in ['nothing', 'drop']
280
-    # @return None
281 292
     def _create_table(self, table_name, pk_name, pk_ftype, engine, charset = 'utf8', if_exists = 'nothing'):
282 293
         #Escaped table name
283 294
         etname = self.datasource.escape_idname(table_name)
@@ -312,7 +323,6 @@ PRIMARY KEY({pk_name})
312 323
     # @param table_name str : The table name
313 324
     # @param col_name str : The columns name
314 325
     # @param col_fieldtype EmFieldype the fieldtype
315
-    # @return None
316 326
     def _add_column(self, table_name, col_name, col_fieldtype, drop_if_exists = False):
317 327
         add_col = """ALTER TABLE {table_name}
318 328
 ADD COLUMN {col_name} {col_type} {col_specs};"""
@@ -372,16 +382,13 @@ DROP FOREIGN KEY {fk_name}""".format(
372 382
                 src_table = self.datasource.escape_idname(src_table_name),
373 383
                 fk_name = self.datasource.escape_idname(self.datasource.get_fk_name(src_table_name, dst_table_name))
374 384
             ))
375
-        except pymysql.err.InternalError: pass
385
+        except pymysql.err.InternalError:
386
+            # If the FK don't exists we do not care
387
+            pass
376 388
     
377
-    #def _fk_name(self, src_table_name, dst_table_name):
378
-    #    return "fk_%s_%s"%(src_table_name, dst_table_name)
379
-
380
-
381 389
     ## @brief Generate triggers given a table_name and its columns fieldtypes
382 390
     # @param table_name str : Table name
383 391
     # @param cols_ftype dict : with col name as key and column fieldtype as value
384
-    # @return None
385 392
     def _generate_triggers(self, table_name, cols_ftype):
386 393
         colval_l_upd = dict() #param for update trigger
387 394
         colval_l_ins = dict() #param for insert trigger
@@ -409,7 +416,6 @@ DROP FOREIGN KEY {fk_name}""".format(
409 416
     # @param table_name str : The table name
410 417
     # @param moment str : can be 'update' or 'insert'
411 418
     # @param cols_val dict : Dict with column name as key and column value as value
412
-    # @return None
413 419
     def _table_trigger(self, table_name, moment, cols_val):
414 420
         trigger_name = self.datasource.escape_idname("%s_%s_trig"%(table_name, moment))
415 421
         #Try to delete the trigger

Loading…
Cancel
Save