Skip to content

Model dependent PHP migrations cannot be executed after modification #56

@Mikulas

Description

@Mikulas

Initial state:

class Foo
{
	 /**
	 * @ORM\Column(type="text")
	 */
	private $content;
}

php migration (2016-01-01.php)

assert($entityManager instanceof Doctrine\ORM\EntityManager);

foreach ($entityManager->getRepository(Foo::class)->findAll() as $foo) {
    // ... queries db
}

If we ever change the original model, for example by adding additional property

class Foo
{
	 /**
	 * @ORM\Column(type="text")
	 */
	private $content;

+	 /**
+	 * @ORM\Column(type="datetime_immutable")
+	 */
+	private $createdAt;
}

we will break the php migration, because Doctrine will query the database as

SELECT t0.content AS content, t0.created_at AS created_at -- ...   

but the newly added column was not yet added to database when the php migration executes.

In other words, php migrations use latest meta data with Doctrine, because the model itself is not versioned (or at least the versions are not used for migration purposes).

I don't have a solution to propose, other than not using default Doctrine queries in php migrations. Even writing custom DQL/SQL queries cannot handle renamed columns etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions