private function fixIndexes(string $tableName, array &$tableDef, $curTableDef = null) {
        $tableDef += ['indexes' => []];

        // Loop through the columns and add the primary key index.
        $primaryColumns = [];
        foreach ($tableDef['columns'] as $cname => $cdef) {
            if (!empty($cdef['primary'])) {
                $primaryColumns[] = $cname;
            }
        }

        // Massage the primary key index.
        $primaryFound = false;
        foreach ($tableDef['indexes'] as &$indexDef) {
            $indexDef += ['name' => $this->buildIndexName($tableName, $indexDef), 'type' => null];

            if ($indexDef['type'] === Db::INDEX_PK) {
                $primaryFound = true;

                if (empty($primaryColumns)) {
                    foreach ($indexDef['columns'] as $cname) {
                        $tableDef['columns'][$cname]['primary'] = true;
                    }
                } elseif (array_diff($primaryColumns, $indexDef['columns'])) {
                    throw new \Exception("There is a mismatch in the primary key index and primary key columns.", 500);
                }
            } elseif (isset($curTableDef['indexes'])) {
                foreach ($curTableDef['indexes'] as $curIndexDef) {
                    if ($this->indexCompare($indexDef, $curIndexDef) === 0) {
                        if (!empty($curIndexDef['name'])) {
                            $indexDef['name'] = $curIndexDef['name'];
                        }
                        break;
                    }
                }
            }
        }

        if (!$primaryFound && !empty($primaryColumns)) {
            $tableDef['indexes'][] = [
                'columns' => $primaryColumns,
                'type' => Db::INDEX_PK
            ];
        }
    }