Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3365

Indexes and uniqueConstraints has been ignored

    Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 12.04 with MySQL 5.5 and PHP 5.4

      Description

      I using the Doctrine Migrations and when I declared my entity with the indexes section, the index name has been ignored. It's like this:

      indexes:
      IDX_ADDRESS_CITY:
      columns: city_id

      but, the diff tools ignore it and give me this code:
      $this->addSql("CREATE INDEX IDX_7299B5238BAC62AF ON tb_address (city_id)");

      and it should be:
      $this->addSql("CREATE INDEX IDX_ADDRESS_CITY ON tb_address (city_id)");

      Notice: I open the same bug on the migrations repository in github and @kimhemsoe told me to open here, since this is generated by DBAL component.

      1. dbal-fixing-373.patch
        4 kB
        Diego Oliveira
      2. orm-fixing-373.patch
        2 kB
        Diego Oliveira

        Activity

        Hide
        Padraig O'Sullivan added a comment -

        Did you specify an index name in the indexes property for your entity in your PHP file? In this case, you should have something like:

        indexes={@Index(name="IDX_ADDRESS_CITY", columns={"city_id"})}
        

        That should result in the correct SQL being generated. If I modify the above to:

        indexes={@Index(columns={"city_id"})}
        

        I also get a migration that has SQL with an auto-generated index name.

        Show
        Padraig O'Sullivan added a comment - Did you specify an index name in the indexes property for your entity in your PHP file? In this case, you should have something like: indexes={@Index(name= "IDX_ADDRESS_CITY" , columns={ "city_id" })} That should result in the correct SQL being generated. If I modify the above to: indexes={@Index(columns={ "city_id" })} I also get a migration that has SQL with an auto-generated index name.
        Hide
        Diego Oliveira added a comment - - edited

        Yes I did specify a name, as you can see:

        uniqueConstraints:
            UNIQUE_STATE_SLUG:
                columns: slug
        indexes:
            IDX_USER_ADDRESS:
                columns: address_id
        

        I don't try do to it using annotations because I choose do use yaml to describe my entities. I will take a look on the source code to see if I can fix it and send a PR.

        Show
        Diego Oliveira added a comment - - edited Yes I did specify a name, as you can see: uniqueConstraints: UNIQUE_STATE_SLUG: columns: slug indexes: IDX_USER_ADDRESS: columns: address_id I don't try do to it using annotations because I choose do use yaml to describe my entities. I will take a look on the source code to see if I can fix it and send a PR.
        Hide
        Diego Oliveira added a comment -

        I already sent this patch to Guilherme Blanco, but I guess he doesn't have time to take a look on it.

        I guess my solution it's not ideal, but it solve the problem and can be a base to make a better solution.

        Show
        Diego Oliveira added a comment - I already sent this patch to Guilherme Blanco, but I guess he doesn't have time to take a look on it. I guess my solution it's not ideal, but it solve the problem and can be a base to make a better solution.
        Hide
        Benjamin Eberlei added a comment -

        Diego Oliveira the fix doesn't seem too nice with the additional boolean flag.

        I would rather like to fix the root cause instead of adding this solution.

        Show
        Benjamin Eberlei added a comment - Diego Oliveira the fix doesn't seem too nice with the additional boolean flag. I would rather like to fix the root cause instead of adding this solution.
        Hide
        Benjamin Eberlei added a comment -

        The issue is tricky, because we cannot just move the index definitions above, they will need the columns, however that directly generates the index in the schema tool. Maybe if the gather join column methods would check if they can add an index already it would work.

        Show
        Benjamin Eberlei added a comment - The issue is tricky, because we cannot just move the index definitions above, they will need the columns, however that directly generates the index in the schema tool. Maybe if the gather join column methods would check if they can add an index already it would work.
        Hide
        Steve Müller added a comment -

        Moving this to ORM as it is completely related to ORM's schema tool. The schema tool hast to declare the order and priority of indexes.

        Show
        Steve Müller added a comment - Moving this to ORM as it is completely related to ORM's schema tool. The schema tool hast to declare the order and priority of indexes.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Diego Oliveira
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated: