Hi,
Could we add to the CI codebase for both v.3 and v.4 the ability to add field comments in migrations.
I use the following. I came across this functionality while googling and have been using it for a while now, to add comments to fields in migrations.
In system/database/DB_forge.php
Code:
abstract class CI_DB_forge {
.
.
.
/**
* COMMENT value representation in CREATE/ALTER TABLE statements
*
* @var string
*/
protected $_comment = ' COMMENT ';
.
.
.
/**
* Process column
*
* @param array $field
* @return string
*/
protected function _process_column($field)
{
return $this->db->escape_identifiers($field['name'])
.' '.$field['type'].$field['length']
.$field['unsigned']
.$field['default']
.$field['null']
.$field['auto_increment']
.$field['comment'] // <-- this is the added code
.$field['unique'];
}
.
.
.
/**
* Field attribute COMMENT
*
* @param array &$attributes
* @param array &$field
* @return void
*/
protected function _attr_comment(&$attributes, &$field)
{
if ($this->_comment === FALSE)
{
return;
}
if (!empty($attributes['COMMENT']))
{
$field['comment'] = $this->_default.$this->db->escape($attributes['COMMENT']);
}
}
// --------------------------------------------------------------------
}
To implement, in a migration execute the following:
Code:
public function up()
{
$this->dbforge->add_field(
array(
'id' => array(
'null' => FALSE,
'type' => 'INT',
'constraint' => 11,
'auto_increment' => TRUE,
),
'my_field' => array(
'type' => 'VARCHAR',
'constraint' => 30,
'null' => FALSE,
'comment' => 'Put the field comment here',
),
)
);
.
.
.
}