Last active
July 11, 2017 18:39
-
-
Save v1talii-dev/5534780ef6891c40d67f5e4552bdf985 to your computer and use it in GitHub Desktop.
D7: custom table in module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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