Fix descending index being converted to ascending (#19749)

Signed-off-by: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com>
This commit is contained in:
Nicolai Ehrhardt 2025-11-22 19:15:56 +01:00
parent 1e56558a7c
commit 1121450864
4 changed files with 25 additions and 3 deletions

View File

@ -271,11 +271,14 @@ class Index
// coming from form
// $columns[names][]
// $columns[sub_parts][]
// $columns[collations][]
foreach ($columns['names'] as $key => $name) {
$sub_part = $columns['sub_parts'][$key] ?? '';
$collation = $columns['collations'][$key] ??
$_columns[] = [
'Column_name' => $name,
'Sub_part' => $sub_part,
'Collation' => $collation,
];
}
} else {

View File

@ -17,7 +17,7 @@ class IndexColumn
/** @var int The column sequence number in the index, starting with 1. */
private $seqInIndex = 1;
/** @var string|null How the column is sorted in the index. "A" (Ascending) or NULL (Not sorted) */
/** @var string|null How the column is sorted in the index. "A" (Ascending), "D" (Descending) or NULL (Not sorted) */
private $collation = null;
/**

View File

@ -2137,11 +2137,20 @@ class Table implements Stringable
$indexFields = [];
foreach ($index->getColumns() as $key => $column) {
$indexFields[$key] = Util::backquote($column->getName());
if (! $column->getSubPart()) {
if ($column->getSubPart()) {
$indexFields[$key] .= '(' . $column->getSubPart() . ')';
}
if (! $column->getCollation()) {
continue;
}
$indexFields[$key] .= '(' . $column->getSubPart() . ')';
$collation = $column->getCollation();
if ($collation === 'A') {
$indexFields[$key] .= ' ASC';
} elseif ($collation === 'D') {
$indexFields[$key] .= ' DESC';
}
}
if (empty($indexFields)) {

View File

@ -143,6 +143,9 @@
<th>
{% trans 'Size' %}
</th>
<th>
{% trans 'Collation' %}
</th>
</tr>
</thead>
{% set spatial_types = [
@ -190,6 +193,13 @@
value="{{ index.getChoice() != 'SPATIAL' ?
column.getSubPart() }}">
</td>
<td>
<select name="index[columns][collations][]">
<option value="None"{{ column.Collation ? ' selected' }}>None</option>
+ <option value="A"{{ column.Collation == 'A' ? ' selected' }}>A</option>
+ <option value="D"{{ column.Collation == 'D' ? ' selected' }}>D</option>
</select>
</td>
</tr>
{% endfor %}
{% if add_fields > 0 %}