laravel-doctrine/migrations

Add attributes metadata support

jurgenbosch opened this issue · 7 comments

Doctrine ORM 2.9 now supports Attributes mapping. According to this ticket the support for such attributes was added in some of the latest versions of the ORM package.

Unfortunately this appears not to work for the migrations.

Is there any plan to support this? It currently stops us from adapting this new annotation style (that I really like ;))

Thanks in advance.

eigan commented

Copy-paste reply from me in a different thread:

As of now laravel-doctrine do not have any maintainer that moves the project forward. Almost all contributions are provided from non team members. We are just making sure that pull requests are merged and released. It might appear that we do not even use laravel-doctrine, but the reason (for me at least) is that we do not keep up with the laravel/doctrine packages and features

So, no there is no plans, however I am active and will answer questions. Sadly I have no time to implement or look for solutions.

Our setup as of now: laravel 8, doctrine 2.9 and PHP 7.4. Plan is to upgrade to PHP 8 by this year which means that these issues will be sorted out by me, unless someone else provide PR :)

Thanks for the quick reply.
I did a really quick scan of the procedure to detect the differences to see if there is a way I can help.
Are you doing some kind of regex to detect the annotations? If so maybe I can put some time in to make it work for the new PHP8 annotations.

PS. I'm currently using Laravel 8, Doctrine 2.9 and PHP 8.0.9 and the package works just fine with that setup.

eigan commented

I have not tested PHP 8 annotations with doctrine at all actually. Just assumed that doctrine would handle it when using the correct config (as the PR in this repo introduced).

@eigan Is there any progress on the upgrade to PHP8? Maybe a better question; Is this package still considered to be alive as the last change is close to a year old.

eigan commented

Hello, I am here and project is still alive even no activity. I am just thinking it's a sign that it works for everyone perhaps :)

Our codebase has been ready for PHP 8 for a while, just waiting for the "Operation Team" to upgrade.. so I have not yet tested annotation, have you?

My testing show that doctrine:migrations:diff works just fine with DOCTRINE_METADATA=attributes

<?php

namespace App\Entities;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;

#[Entity]
#[Table(name: "user")]
class User
{
    #[Id, Column(type: "integer"), GeneratedValue()]
    protected $id = null;

    #[Column(type: "string", length: 32, unique: true, nullable: false)]
    protected $username;

    #[Column(type: "string", length: 32, unique: true, nullable: false)]
    protected $email;
}
<?php

namespace Database\Migrations;

use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;

class Version20220121162247 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema): void
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(32) NOT NULL, email VARCHAR(32) NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema): void
    {
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('DROP TABLE user');
    }
}

closing until there is a supplied bug/issue/example of what down not work