Problem/Motivation

Faced in #3159210-59: Support route aliasing (Symfony 5.4) and allow deprecating the route name

The method implementation in mysql schema require to pass fields within spec for indexes but pgsql/sqlite require only keys definition in $keys_new

Steps to reproduce

    $spec = [
      'fields' => [
        'alias' => [
          'description' => 'The alias of the route, if applicable.',
          'type' => 'varchar_ascii',
          'length' => 255,
        ],
      ],
    ];
    $schema->addField('router', 'alias', $spec['fields']['alias']);
    $schema->addIndex('router', 'alias', ['alias'], $spec);

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Assigned: Unassigned » daffie

the commit which breaks https://git.drupalcode.org/project/drupal/-/commit/eea37702137e1dce6036f...

it means mysql require to pass "fields" but other drivers are not (as doc block said)

@daffie please check if it works for mongodb

andypost’s picture

daffie’s picture

The fields key needs to be set in mysql/Schema::getNormalizedIndexes(), because we are want the resulting index name to be less than 191 characters. When we use utf8mb4 the resulting index name will be below 756 bytes. That is the maximum name length for an index in InnoDB when the row format is REDUNDANT or COMPACT. See: https://dev.mysql.com/doc/refman/8.4/en/innodb-limits.html.

If it is up to me we would not be doing index changes in the method Schema::addField(). For the better and more stable solution would be the add a field first and then add an index in a seperate call with Schema::AddIndex(). That would be the better solution for all databases, including MongoDB.

andypost’s picture

Assigned: daffie » Unassigned

Then at least doc-block needs rewording to point out that fields are required

without the 'fields' element

from \Drupal\Core\Database\Schema::addField()

   * @param array|null $keys_new
   *   (optional) Keys and indexes specification to be created on the
   *   table along with adding the field. The format is the same as a
   *   table specification but without the 'fields' element. If you are
   *   adding a type 'serial' field, you MUST specify at least one key
   *   or index including it in this array. See ::changeField() for more
   *   explanation why.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.