Skip to main content

Change Drupal 7 decimal field scale or precision

Submitted by system on

We wanted to change the MRP field 'field_per_item_cost' from DECIMAL (12,2) to DECIMAL (12,3).

 The following SQL Query will do the trick:  

ALTER TABLE field_data_field_per_item_cost MODIFY field_per_item_cost_value DECIMAL(12,3); 

ALTER TABLE field_revision_field_per_item_cost MODIFY field_per_item_cost_value DECIMAL(12,3); 

UPDATE field_config SET data = REPLACE(data, '"scale";s:1:"2";', '"scale";s:1:"3";') WHERE field_name = 'field_per_item_cost'; 

Upgrading from Drupal 9 to Drupal 10

Submitted by system on

1. Install Upgrade Status[https://www.drupal.org/project/upgrade_status] module to check issues contrib and custom modules compatibility. 

2. Remove Upgrade Status when all checks are green and ready to go. Uninstall Upgrade status and remove it from Composer.

 
composer remove drupal/upgrade_status 

3. Temporarily add write access to protected files and directories
chmod 777 sites/default chmod 666 sites/default/*settings.php chmod 666 sites/default/*services.yml 

Install and Sync to setup a Dev Drupal platform

Submitted by system on

Drush can be used for installing website programmatically. However after installation, you might want to update the synchronization. Install Drupal database: Installs drupal when executed inside the drupal folder.
drush site-install --db-url=mysql://dbuser:dbpass@localhost/dbname --account-name=admin --account-pass=secret -y 

Remove Shortcut links:
drush ev '\Drupal::entityTypeManager()->getStorage("shortcut_set")->load("default")->delete();' 

Useful DB Queries for Drupal Applications

Submitted by system on
Show grouped node counts based on OG group ids for nodes created after a particular time stamp select gid, count(*) from og_membership inner join node on og_membership.etid = node.nid and node.created >= 1678127400 group by gid;
Show node type specific node count list select type,count(*) from node group by type;
Show group membership wise node counts select gid,count(*) from og_membership group by gid;
Start the node next Increment number from a specific nid ALTER TABLE node AUTO_INCREMENT = 20000000;

Get MySQL tables having free space for optimize

Submitted by system on
The following query lists tables with free space greater than equal to 50MB to optimize mysql> select table_name, table_schema, round(data_length/1024/1024) as data_length_mb, round(data_free/1024/1024) as data_free_mb from information_schema.tables where round(data_free/1024/1024) > 50 order by data_free_mb;
Example response: +---------------------------------+-----------------+----------------+--------------+
| TABLE_NAME | TABLE_SCHEMA | data_length_mb | data_free_mb |

CheatSheets

Submitted by system on
Drupal 8 Entity API Cheat sheet Link: https://www.metaltoad.com/blog/drupal-8-entity-api-cheat-sheet Drupal Twig Cheat sheet Link: https://git.drupalcode.org/project/twig_tweak/-/blob/3.x/docs/cheat-sheet.md?plain=0 Drupal 8 Form API reference Link: https://drupalize.me/tutorial/form-element-reference?p=2766 -- Source https://cheatography.com/programming/ https://www.drupaleasy.com/blogs/ultimike/2022/08/are-cheatsheets-still-thing-drupal-developers

MySQL Convert Varchar column to Unsigned INT.

Submitted by system on
The flagging table for Drupal 9 had entity_id field as Varchar which prevented indexing to work during joins as entity_ids from other tables were unsigned int. Flagging table before: flagging | CREATE TABLE `flagging` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`flag_id` varchar(32) CHARACTER SET ascii NOT NULL COMMENT 'The ID of the target entity.',
`uuid` varchar(128) CHARACTER SET ascii NOT NULL,
`entity_type` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
`entity_id` int unsigned DEFAULT NULL,
`global` tinyint DEFAULT NULL,

Update Drupal 7 text fields max length for fields having data

Submitted by system on
<?php
/*
* Utility to change the max length of a text field
*/
function change_text_field_max_length($field_name, $new_length) {
$field_table = 'field_data_' . $field_name;
$field_revision_table = 'field_revision_' . $field_name;
$field_column = $field_name . '_value';

// Alter value field length in fields table
db_query("ALTER TABLE `{$field_table}` CHANGE `{$field_column}` `{$field_column}` VARCHAR( {$new_length} )");
// Alter value field length in fields revision table