0

I'm currently setting up doctrine-migrations for a symfony project. I'm wondering why the auto generated migrations use direct SQL-Statements. These ones for example restrict it to mysql and INNODB-enginge (since it's my local environment). But the database environment the project it will run in might differ.

Why does it not let the entity manager handle this kind of stuff ?

E.g. in the up-function it will generated something like:

$this->addSql('CREATE TABLE tag (id INT AUTO_INCREMENT NOT NULL, category_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, is_active TINYINT(1) DEFAULT \'1\' NOT NULL, INDEX IDX_389B78312469DE2 (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');

Why does it not use the schemaTool ? like:

$schemaTool = new SchemaTool($em);
        $metaData = $em->getClassMetadata($className);

        if ($this->sm->tablesExist(array($metaData->getTableName())) == true) {
            $this->write("Table already exists :" . $className);
        }
        else{
            $schemaTool->createSchema([
                $metaData
            ]);
        }

This way it would not be depending on my DB-Settings. Am i missing something ? or are there mayor downsides to let the schemaTool take care of it or use the entitymanager for the data-migration at all?

Rob
  • 1
  • 1
    There is a [Symfony Slack channel](https://symfony.com/community) which is probably better for these sorts of discussion oriented questions. Might also check the Doctrine docs. Suffice it to say that trying to migrate from one type of database to another is much more difficult than it might seem. – Cerad Sep 04 '19 at 12:42
  • I can't find the relevant discussion (was in a ticket on github somewhere), but it has been mentioned by the devs that autogenerating migrations is just for convenience and not a canonical tool and that you should generate the migrations manually if you require more control. – msg Sep 04 '19 at 20:41
  • @Cerad - i do not know which DB will be used in the environment(s) the application will run in - so the DB type inside one environment will be consistent. But i will see to ask it in the slack channel. msg Cerad thank you both for your input- – Rob Sep 06 '19 at 06:16

0 Answers0