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
            ];
        }
    }
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
            ];
        }
    }
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 ] ; } }
Move the primary key index into the correct place for database drivers.

@param string $tableName The name of the table.
@param array &$tableDef The table definition.
@param array|null $curTableDef The current database table def used to resolve conflicts in some names.
@throws \Exception Throws an exception when there is a mismatch between the primary index and the primary key
defined on the columns themselves.
Move the primary key index into the correct place for database drivers .