Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model dependent PHP migrations cannot be executed after modification #56

Open
Mikulas opened this issue Dec 28, 2016 · 1 comment
Open
Labels

Comments

@Mikulas
Copy link
Contributor

Mikulas commented Dec 28, 2016

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.

@JanTvrdik
Copy link
Member

Yes, this is a well known limitation. The only solution I know was proposed by @PetrP and that is to essentially checkout old PHP files from Git repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants