Skip to content

Instantly share code, notes, and snippets.

@v1talii-dev
Last active July 11, 2017 18:39
Show Gist options
  • Save v1talii-dev/5534780ef6891c40d67f5e4552bdf985 to your computer and use it in GitHub Desktop.
Save v1talii-dev/5534780ef6891c40d67f5e4552bdf985 to your computer and use it in GitHub Desktop.
D7: custom table in module
<?php
# test.install
/**
* Implements hook_schema().
*
* @see https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_schema/7.x
* @link https://www.drupal.org/node/146862
*/
function test_schema() {
$schema['test'] = array(
'description' => '',
'fields' => array(
'id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
'default' => '',
),
'date' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
),
),
'primary key' => array('id'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*
* Delete config variable and module table.
* @see https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_uninstall/7.x
*/
function test_uninstall() {
drupal_uninstall_schema('test');
variable_del('test_var');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment