Skip to content

Instantly share code, notes, and snippets.

@codexmas
Last active June 26, 2020 03:14
Show Gist options
  • Save codexmas/1709926b89b3461f7692a64ec6f51ebf to your computer and use it in GitHub Desktop.
Save codexmas/1709926b89b3461f7692a64ec6f51ebf to your computer and use it in GitHub Desktop.
<?php
use Drupal\Core\Database\Database;
function lotus_update_8001(&$sandbox) {
$spec = [
'type' => 'varchar',
'description' => "New Col",
'length' => 20,
'not null' => FALSE,
];
$schema = Database::getConnection()->schema();
$schema->addField('lotus', 'newcol', $spec);
$schema->addIndex('lotus', ['newcol']);
}
function lotus_update_8002(&$sandbox) {
$spec = array(
'description' => 'My description',
'fields' => array(
'myfield1' => array(
'description' => 'Myfield1 description.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'myfield2' => array(
'description' => 'Myfield2 description',
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array('myfield1'),
);
$schema = Database::getConnection()->schema();
$schema->createTable('lotustwo', $spec);
}
function lotus_post_update_change_title_of_node() {
$node = \Drupal::entityManager()->loadEntityByUuid('FC0C01C6-B758-450D-A1BC-93D91D7786CB');
$node->setTitle('hello world');
$node->save();
return t('Node successfully updated.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment