Manage field size via vardefs

CI_Assessments custom module was built in Module Builder and released from there with all fields altogether. The issue now to reduce size of some fields, as we get row size over limit for the main table of the module.

When I am looking into the file modules/CI_Assessments/vardefs.php

For example, field partner_threatened has attributes:

'partner_threatened' =>
array (
  'required' => false,
  'readonly' => false,
  'name' => 'partner_threatened',
  'vname' => 'LBL_PARTNER_THREATENED',
  'type' => 'enum',
  'massupdate' => true,
  'hidemassupdate' => false,
  'no_default' => false,
  'comments' => '',
  'help' => '',
  'importable' => 'true',
  'duplicate_merge' => 'enabled',
  'duplicate_merge_dom_value' => '1',
  'audited' => false,
  'reportable' => true,
  'unified_search' => false,
  'merge_filter' => 'disabled',
  'pii' => false,
  'calculated' => false,
  'len' => 25,
  'size' => '20',
  'options' => 'yes_no_list',
  'default' => '',
  'dependency' => false,)

 Where len = 25 and size = 25.

BUT if I look into DB, field is

`partner_threatened` varchar(100) COLLATE utf8mb4_general_ci DEFAULT '',

 Which attribute defines the size of the field in DB? How I can manage it via vardefs?

  • Hi  ,

    For dropdown and text fields, the 'len' property dictates size of the varchar column in the database. If you recently changed the 'len' parameter for the field, please make sure you run a Quick Repair & Rebuild from the Admin section. When that process completes, it should detect mismatches between your vardefs and schema and provide queries to align the database with the vardefs.

    If the Quick Repair does not suggest any corrective database queries, then it's possible you have something overriding the base field vardef to set a larger length. The true definition of the field observed by Sugar will be found in ./cache/modules/CI_Assessments/ as this file is compiled combination of base and custom vardefs for all the fields in the module. If you see the length of the field is different than your base vardef file, then it is likely that there is an extended vardef overriding the value and you will need to locate that file to make the change. Extended vardefs can be found in ./custom/Extension/modules/CI_Assessments/Ext/Vardefs/.

    Chris

  • Hi Chris,

    Thank you for your reply, I did check Extension vardefs - nothing custom, and did check a final vardefs in cache folder, values are: 

    'len' => 25,
    'size' => '20',

    And this is where my confusion is. R&R does not give me a SQL to fix column size.

    Then I did another step: 

    ALTER TABLE ci_assessments   modify COLUMN partner_threatened varchar(20) COLLATE utf8mb4_general_ci DEFAULT '';

    run R&R : no SQL to fix column size.

    Not sure if it is a platform bug.

    BUT if I change any field via Studio on that module, at the background SQL runs:

    ALTER TABLE er_assessments   modify COLUMN partner_threatened varchar(100)  DEFAULT '' NULL ;
  • Hi  ,

    That is strange. There are stock dropdown fields (e.g. accounts.industry and accounts.account_type) where the 'len' is defined as 50 and the database columns have the respective length. I thought I recalled being able to modify dropdown field database column lengths through the vardefs in the past.

    Perhaps there is an override forcing all custom dropdowns to be varchar(100) and disregarding the 'len' attribute. That may explain why the quick repair doesn't identify the mismatch.

    Chris

  • I could fix it. Before, I was update direct vardefs.php file of the module, as this is a custom module, so I was modifying vardefs.php and it did not work well. But once I overwrote vardefs within custom/Extensions/... folder - it did apply the change of the fields size.

    Looks like something else is happening after main vardefs.php file read, but custom/Extensions override it at the end.