add new column after another column in symfony using docrine schema

Viewed 805

Code

Entity for room table.

use Doctrine\ORM\Mapping as ORM;

class Room
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    private $name;

   /**
     * @var int
     *
     * @ORM\Column(type="integer")
     */
    private $groupOrder;

    /**
     * @var boolean
     *
     * @ORM\Column(type="boolean", options={"after": "active","default": false})
     */
    private $isAssociable;

    /**
     * @var bool
     *
     * @ORM\Column(type="boolean", options={"default" : 1})
     */
    private $active = true;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    private $createdAt;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime")
     */
    private $updatedAt;
}

I'm running following command on console, but the output is not as expected

php bin/console doctrine:schema:update --dump-sql

Expected Output

ALTER TABLE room ADD is_associable TINYINT(1) DEFAULT '0' NOT NULL AFTER active;

What I'm getting(Output)

ALTER TABLE room ADD is_associable TINYINT(1) DEFAULT '0' NOT NULL;

1 Answers

It seems that natively you can't do that in Doctrine. Option parameter for the column which might handle that isn't available. Anyway maybe you can achieve that by (of course all of ideas are a workarounds):

  • creating custom "position" annotation for field, of course you need write custom command which will run doctrine:schema:update --dump-sql and will modify an sql output (it's just my idea).

  • do that with using migration where you will put raw sql

  • create PR or Issue to Doctrine ORM project on github here.

Related