|
@@ -340,6 +340,17 @@ class MysqlMigrationHandler(DummyMigrationHandler):
|
340
|
340
|
# @return True if the column was added else return False
|
341
|
341
|
def _add_column(self, table_name, col_name, col_fieldtype, drop_if_exists=False):
|
342
|
342
|
|
|
343
|
+ instr, col_type, col_specs = fieldtypes_utils.fieldtype_db_init(col_fieldtype)
|
|
344
|
+
|
|
345
|
+ if instr == 'table':
|
|
346
|
+ # multivalue field. We are not going to add a column in this table
|
|
347
|
+ # but in corresponding multivalue table
|
|
348
|
+ self._add_column_multivalue(
|
|
349
|
+ table_name,
|
|
350
|
+ key_infos = col_type,
|
|
351
|
+ column_infos = (col_name, col_specs)
|
|
352
|
+ )
|
|
353
|
+
|
343
|
354
|
col_name = utils.column_name(col_name)
|
344
|
355
|
|
345
|
356
|
add_col = """ALTER TABLE {table_name}
|
|
@@ -348,7 +359,6 @@ ADD COLUMN {col_name} {col_type} {col_specs};"""
|
348
|
359
|
etname = utils.escape_idname(table_name)
|
349
|
360
|
ecname = utils.escape_idname(col_name)
|
350
|
361
|
|
351
|
|
- instr, col_type, col_specs = fieldtypes_utils.fieldtype_db_init(col_fieldtype)
|
352
|
362
|
if instr is None:
|
353
|
363
|
return True
|
354
|
364
|
if instr != "column":
|
|
@@ -397,6 +407,32 @@ ADD COLUMN {col_name} {col_type} {col_specs};"""
|
397
|
407
|
|
398
|
408
|
return True
|
399
|
409
|
|
|
410
|
+ ## @brief Add a column to a multivalue table
|
|
411
|
+ #
|
|
412
|
+ # Add a column (and create a table if not existing) for storing multivalue
|
|
413
|
+ # datas. (typically i18n)
|
|
414
|
+ # @param ref_table_name str : Referenced table name
|
|
415
|
+ # @param key_infos tuple : tuple(key_name, key_fieldtype)
|
|
416
|
+ # @param column_infos tuple : tuple(col_name, col_fieldtype)
|
|
417
|
+ def _add_column_multivalue(ref_table_name, key_info, column_infos):
|
|
418
|
+ key_name, key_ftype = key_infos
|
|
419
|
+ col_name, col_ftype = column_infos
|
|
420
|
+ table_name = utils.multivalue_table_name(ref_table_name, key_name)
|
|
421
|
+ # table creation
|
|
422
|
+ self._create_table(
|
|
423
|
+ table_name,
|
|
424
|
+ key_name,
|
|
425
|
+ key_ftype,
|
|
426
|
+ self.db_engine,
|
|
427
|
+ if_exists = 'nothing'
|
|
428
|
+ )
|
|
429
|
+ # with FK
|
|
430
|
+ self._del_fk(table_name, dst_table_name)
|
|
431
|
+ self._add_fk(table_name, dst_table_name, key_name, utils._object_pk[0])
|
|
432
|
+ # adding the column
|
|
433
|
+ self._add_column(table_name, col_name, col_ftype)
|
|
434
|
+
|
|
435
|
+
|
400
|
436
|
## @brief Add a foreign key
|
401
|
437
|
# @param src_table_name str : The name of the table where we will add the FK
|
402
|
438
|
# @param dst_table_name str : The name of the table the FK will point on
|