Since, hook_schema_alter() is hook_schema_alter()
was removed from Drupal 8, how todo I alter any existing schema of somedefined from another module in Drupal 8?
I have used mymodule_update_8201
(hook_update_N()
) function in my .install file
use Drupal\Core\Database\Database;
But, but no new field or column gets added into my existing table. Is theirthere any other way to achieve this?
@edit
This is the code for the first module a
a.install
(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
(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;
}