Created
August 22, 2018 12:00
-
-
Save radheymkumar/5a24aedccd9d9322834ca5b487e9fce8 to your computer and use it in GitHub Desktop.
Drupal 8 Install Table and Add Field
This file contains hidden or 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 | |
use Drupal\Core\Database\Database; | |
/** | |
* Implements hook_schema(). | |
*/ | |
function dots_schema() { | |
$schema['dots_table'] = [ | |
'description' => 'dots table', | |
'fields' => [ | |
'id' => [ | |
'type' => 'serial', | |
'unsigned' => TRUE, | |
'not null' => TRUE, | |
'description' => "dots id.", | |
], | |
'name' => [ | |
'description' => 'dots name.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'email' => [ | |
'description' => 'dots email.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'mobile' => [ | |
'description' => 'dots mobile.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'dob' => [ | |
'description' => 'dots dob.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'gender' => [ | |
'description' => 'dots gender.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'created' => [ | |
'description' => 'dots created.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
'changed' => [ | |
'description' => 'dots changed.', | |
'type' => 'varchar', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
], | |
/* 'node_id' => [ | |
'description' => 'dots node id', | |
'type' => 'int', | |
'length' => 255, | |
'not null' => TRUE, | |
'default' => '' | |
],*/ | |
], | |
'primary key' => ['id'], | |
]; | |
return $schema; | |
} | |
function dots_update_8002() { | |
$spec = array( | |
'type' => 'int', | |
'description' => "dots node id", | |
'length' => 20, | |
); | |
$schema = Database::getConnection()->schema(); | |
$schema->addField('dots_table', 'node_id', $spec); | |
} | |
function dots_update_8003() { | |
$spec = array( | |
'type' => 'int', | |
'description' => "dots user uid", | |
'length' => 20, | |
); | |
$schema = Database::getConnection()->schema(); | |
$schema->addField('dots_table', 'user_id', $spec); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment