Since hook_schema_alter()
was removed from Drupal 8, how do I alter any existing schema defined from another module in Drupal 8?
I have used mymodule_update_8201
(hook_update_N()
) in my .install file, but no new field or column gets added into my existing table. Is there any other way to achieve this?
This is the code for the first module (a.install).
function a_schema() {
$schema['my_table'] = array(
'fields' => array(
'type' => array(
'description' => 'registration type',
'type' => 'varchar',
'length' => 255,
),
),
);
}
This is the code for the second module (b.install).
/**
* Implements hook_update_N().
*/
function b_update_8201() {
$spec = array(
'type' => 'varchar',
'description' => "New Col",
'length' => 20,
'not null' => FALSE,
);
$schema = Database::getConnection()->schema();
$schema->addField('my_table', 'newcol', $spec);
return $schema;
}