Skip to content

[5.6] RenameIndex support for migrations#24147

Merged
taylorotwell merged 3 commits into
laravel:5.6from
slava-vishnyakov:rename-index
May 21, 2018
Merged

[5.6] RenameIndex support for migrations#24147
taylorotwell merged 3 commits into
laravel:5.6from
slava-vishnyakov:rename-index

Conversation

@slava-vishnyakov

@slava-vishnyakov slava-vishnyakov commented May 8, 2018

Copy link
Copy Markdown
Contributor

As described here: laravel/ideas#443 and as suggested by @tomschlick here, opening a PR for migration call to rename index (->renameIndex('from', 'to')).

Additionally tested on local installations of MySQL, Postgres, MS SQL - those support renaming indexes.

SQLite doesn't support renaming indexes (as is correctly pointed in laravel/ideas#443), so I'm using Doctrine and its getRenameIndexSQL, unfortunately it's protected, so basically, I've copied the implementation (this is from Doctrine's source):

protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
    return [
        $this->getDropIndexSQL($oldIndexName, $tableName),
        $this->getCreateIndexSQL($index, $tableName)
    ];
}

So, for SQLite it's drop and re-create (and requires Doctrine), for others - it's native calls.

(Edit: wrong code snippet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants