auto_increment_alter
This module allows altering the AUTO_INCREMENT value of database tables.
One use case is to prevent entity ID conflicts when performing Drupal upgrades.
See https://www.udrupal.com/auto-increment-alter-documentation
REQUIREMENTS
At the moment the module only works with the MySQL driver. The core drupal:mysql module must be enabled.
CONFIGURATION / USAGE
The module provides a auto_increment_alter.mysql service, an admin interface (since alpha 5), and Drush commands offering the following functionality:
* Alter the AUTO_INCREMENT value for a single table.
drush auto-increment-alter:table node 500
* Alter the AUTO_INCREMENT value of multiple tables based on the auto_increment_alter_tables setting.
drush auto-increment-alter:tables
This expects an auto_increment_alter_tables setting containing an associative array of table and value pairs. The keys should be the name of the table to alter. The array values should be integers containing the new AUTO_INCREMENT value. For example:
$settings['auto_increment_alter_tables'] = [
'node' => 500,
'node_revision' => 1000,
'users' => 100,
'taxonomy_term_data' => 200,
'taxonomy_term_revision' => 200,
'file_managed' => 300,
'media' => 700,
'media_revision' => 700,
];
* Alter the AUTO_INCREMENT value for a single content entity
drush auto-increment-alter:content-entity node 500 1000
drush auto-increment-alter:content-entity user 100
drush auto-increment-alter:content-entity taxonomy_term 200
The first parameter is the machine name content entity. The second parameter is
the AUTO_INCREMENT value for the base table. The third parameter is the
AUTO_INCREMENT value for the revision table.
If the content entity uses a revision table, but the parameter is not set, the
same value from the base table shall be used. Some content entities do not
make use of revision tables. In those cases, the revision value is ignored even
if set.
* Alter the AUTO_INCREMENT value of content entity tables based on the auto_increment_alter_content_entities setting.
drush auto-increment-alter:content-entities
This expects an auto_increment_alter_content_entities setting containing an associative array of table and value pairs. If a content entity is set, but it does not exist in the current installation it will be filtered out before calling the alter operation. The base and revision tables for the content entity are identified using the entity_type.manager service.
The setting's keys should be the machine name of the content entities. The array values can be set in three ways:
- An array with two integer values. The first is used for the base table and the second is used for the revision table.
- An array with one integer value. It is used for both the base and revisions tables.
- An integer value. It is used for both the base and revisions tables.
Some content entities do not make use of revision tables. In those cases, the revision value is ignored even if set.
$settings['auto_increment_alter_content_entities'] = [
'node' => [500, 1000],
'user' => [100],
'taxonomy_term' => [200],
'file' => 300,
'media' => 700,
];
* Get the list of entities, optionally filtered by group.
drush auto-increment-alter:entity-list
drush auto-increment-alter:entity-list --group=content
drush auto-increment-alter:entity-list --group=configuration* Get the list of tables.
drush auto-increment-alter:table-list
* Get the AUTO_INCREMENT value for a single table.
drush auto-increment-alter:value node
* Get the AUTO_INCREMENT value for all tables.
drush auto-increment-alter:values
drush auto-increment-alter:values --all
This returns table names and their corresponding AUTO_INCREMENT value. If the --all option is provided, the output will include tables that do not
have the AUTO_INCREMENT value set.
See example.settings.auto_increment_alter.php for an example on how to configure the variables used by this module.