Useful Drush Commands

Technologies: 

Log out all active Users:

drush sql-query 'TRUNCATE TABLE sessions;'

Download drupal and rename:
Downloads and renames to web

drush dl drupal --drupal-project-rename=web -y

Install Drupal database:
Installs drupal when executed inside the drupal folder.

Upgrading from Drupal 9 to Drupal 10

Technologies: 

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

Install and Sync to setup a Dev Drupal platform

Technologies: 

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:

Useful DB Queries for Drupal Applications

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

Get MySQL tables having free space for optimize

Technologies: 

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:

Update Drupal 7 text fields max length for fields having data

Technologies: 
<?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