Versi Drupal 8 dari kode file * .install disediakan oleh @ Елин Й .:
Catatan: Basis data harus ada dan ditentukan di settings.php.
<?php
function mymodule_schema_otherdb() {
$schema['mytable'] = array(
'description' => 'My table description',
'fields' => array(
'myfield' => array(
'description' => 'My field description',
'type' => 'serial',
'size' => 'medium',
'not null' => TRUE,
'unsigned' => TRUE,
),
),
'primary key' => array('myfield'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function mymodule_install() {
\Drupal\Core\Database\Database::setActiveConnection('otherdb');
$connection = \Drupal\Core\Database\Database::getConnection();
$schema = mymodule_schema_shared();
foreach ($schema as $name => $table) {
$connection->schema()->createTable($name, $table);
}
\Drupal\Core\Database\Database::setActiveConnection();
}
/**
* Implements hook_uninstall().
*/
function mymodule_uninstall() {
\Drupal\Core\Database\Database::setActiveConnection('otherdb');
$connection = \Drupal\Core\Database\Database::getConnection();
$schema = mymodule_schema_shared();
foreach ($schema as $name => $table) {
$connection->schema()->dropTable($name);
}
\Drupal\Core\Database\Database::setActiveConnection();
}
Inilah intinya .