Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MariaDB can't use rename index syntax generated by migrations #196

Closed
driesvints opened this issue Dec 19, 2014 · 2 comments
Closed

MariaDB can't use rename index syntax generated by migrations #196

driesvints opened this issue Dec 19, 2014 · 2 comments

Comments

@driesvints
Copy link

Ever since DBAL 2.5 was released and we upgraded to it, Doctrine migrations have been generating migrations to rename all of the indexes. This uses the RENAME INDEX command. Example:

$this->addSql('ALTER TABLE account RENAME INDEX account_admin_id_idx TO IDX_7D3656A4642B8210');
$this->addSql('ALTER TABLE account RENAME INDEX account_plan_id_uniq TO UNIQ_7D3656A4E899029B');
$this->addSql('ALTER TABLE account RENAME INDEX account_address_id_uniq TO UNIQ_7D3656A4F5B7AF75');
$this->addSql('ALTER TABLE account RENAME INDEX account_profile_id_uniq TO UNIQ_7D3656A4CCFA12B8');
$this->addSql('ALTER TABLE account RENAME INDEX account_invoice_settings_id_uniq TO UNIQ_7D3656A44EDAFABB');

Problem is that Maria DB fails on this. Could this be because I'm not on a latest version and that it doesn't recognizes the syntax? Here's the stacktrace what I get when running doctrine migrations:migrate

WARNING! You are about to execute a database migration that could result in schema changes and data lost. Are you sure you wish to continue? (y/n)y
Migrating up to 20141219134957 from 20141218132129

  ++ migrating 20141219134957

     -> ALTER TABLE account RENAME INDEX account_admin_id_idx TO IDX_7D3656A4642B8210
Migration 20141219134957 failed during Execution. Error An exception occurred while executing 'ALTER TABLE account RENAME INDEX account_admin_id_idx TO IDX_7D3656A4642B8210':

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INDEX account_admin_id_idx TO IDX_7D3656A4642B8210' at line 1

  [Doctrine\DBAL\Exception\SyntaxErrorException]
  An exception occurred while executing 'ALTER TABLE account RENAME INDEX account_admin_id_i
  dx TO IDX_7D3656A4642B8210':
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL synt
  ax; check the manual that corresponds to your MariaDB server version for the right syntax
  to use near 'INDEX account_admin_id_idx TO IDX_7D3656A4642B8210' at line 1


  [Doctrine\DBAL\Driver\PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL synt
  ax; check the manual that corresponds to your MariaDB server version for the right syntax
  to use near 'INDEX account_admin_id_idx TO IDX_7D3656A4642B8210' at line 1


  [PDOException]
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL synt
  ax; check the manual that corresponds to your MariaDB server version for the right syntax
  to use near 'INDEX account_admin_id_idx TO IDX_7D3656A4642B8210' at line 1

Output for mysql --version is:

mysql  Ver 15.1 Distrib 10.0.14-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Funny thing is that if I run doctrine orm:schema-tool:update --dump-sql on a MySQL based DB I don't get the RENAME INDEX syntax but a drop/create syntax:

DROP INDEX account_admin_id_idx ON account;
CREATE INDEX IDX_7D3656A4642B8210 ON account (admin_id);
DROP INDEX account_plan_id_uniq ON account;
CREATE UNIQUE INDEX UNIQ_7D3656A4E899029B ON account (plan_id);
DROP INDEX account_address_id_uniq ON account;
CREATE UNIQUE INDEX UNIQ_7D3656A4F5B7AF75 ON account (address_id);
DROP INDEX account_profile_id_uniq ON account;
CREATE UNIQUE INDEX UNIQ_7D3656A4CCFA12B8 ON account (profile_id);
DROP INDEX account_invoice_settings_id_uniq ON account;
CREATE UNIQUE INDEX UNIQ_7D3656A44EDAFABB ON account (invoice_settings_id);

MySQL version for this is:

mysql  Ver 14.14 Distrib 5.1.73, for debian-linux-gnu (i486) using readline 6.1

So my question basically is: how can I get my migrations to generate and run properly for Maria DB?

@stof
Copy link
Member

stof commented Dec 19, 2014

This is because of the version guessing in the platform. doctrine/dbal#742 is fixing the issue.

In the meantime, you can configure the serverVersion explicitly to avoid this (set it to something lower than 5.7 because MariaDB does not support the MySQL 5.7 syntax for indexes). If you are using Symfony, the way to configure this in DoctrineBundle 1.3 is described in doctrine/DoctrineBundle#351 (comment)

Anyway, closing this issue as it is not an issue in doctrine/migrations but in doctrine/dbal.

@stof stof closed this as completed Dec 19, 2014
@driesvints
Copy link
Author

@stof ok, thanks for the help! :)

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

No branches or pull requests

2 participants