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

Custom doctrine types keep getting their definition generated in migrations #1435

Open
geoffroyp opened this issue Jun 18, 2024 · 2 comments

Comments

@geoffroyp
Copy link

Q A
ORM 3.2.0
DBAL 4.0.3

Support Question

I have recently upgrade doctrine to DBAL 4 / ORM 3, and when I run make:migration, then run doctrine:migration:migration, then run make:migration again, the exact same file is generated, with the same changes....
From what I see, the big majority of those changes are related to custom doctrine type, and I believe it is related to the fact that "Type::requiresSQLCommentHint()" has been removed from doctrine

My problem seems very similar to #1434 that you closed, except that in my case, I'm using MySQL and I removed all comments related to DC2Type. But still, make:migration keeps generating those changes, over and over again.

Any way to fix this?

@geoffroyp geoffroyp changed the title Custom doctrine types keep getting their definition generated in migration- Custom doctrine types keep getting their definition generated in migrations Jun 19, 2024
@stof
Copy link
Member

stof commented Jun 19, 2024

Please share a reproducer for the issue.

Also, which version of doctrine/migrations are you using ?

@geoffroyp
Copy link
Author

I am using doctrine/doctrine-migrations-bundle v3.3.1, which itself uses doctrine/migrations v3.7.4

Here's an example of custom type that keeps getting generated, but used to work perfectly before, with DC2Type comments:

<?php

namespace App\Doctrine\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Override;

class AmountType extends Type
{
	public const AMOUNT = 'amount';

	/**
	 * {@inheritDoc}
	 */
	#[Override]
	public function convertToPHPValue($value, AbstractPlatform $platform): ?float
	{
		return null !== $value ? (float) $value : null;
	}

	/**
	 * {@inheritDoc}
	 */
	#[Override]
	public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
	{
		$column['precision'] = max($column['precision'], 16);
		$column['scale'] = max($column['scale'], 2);

		$declaration = 'DECIMAL(' . $column['precision'] . ', ' . $column['scale'] . ')';
		$declaration .= $column['unsigned'] ? ' UNSIGNED' : '';

		return $declaration;
	}
}

and another example:

<?php

namespace App\Doctrine\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Override;

class TinyInt extends IntegerType
{
	public const string TINYINT = 'tinyint';

	/**
	 * @param array $column
	 * @param AbstractPlatform $platform
	 *
	 * @return string
	 */
	#[Override]
	public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
	{
		$autoinc = '';
		if (!empty($column['autoincrement'])) {
			$autoinc = ' AUTO_INCREMENT';
		}

		return 'TINYINT' . (!empty($column['unsigned']) ? ' UNSIGNED' : '') . $autoinc;
	}
	
	public function requiresSQLCommentHint(AbstractPlatform $platform): bool
	{
		return true;
	}
	
	public function getName(): string
	{
		return self::TINYINT;
	}
}

so, when I run make:migration, then run doctrine:migration:migrate, then run make:migration again, every column using one of these customTypes are getting their definition generated every time

Let me know if I shall add more details / code.

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

No branches or pull requests

2 participants