-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Diff is not working if options are set directly in Type::getSQLDeclaration() #3021
Comments
what about custom type mediumint? |
The issue is with DOctrine diff, run: Run it twice and based on my past testing the command was producing SQL queries to update the schema again and again, but it should update the DB and then produce no SQL queries on the 2nd run. |
my whole class: <?php declare(strict_types=1);
namespace App\Extensions\Doctrine\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
/**
* Type that maps a database MEDIUMINT to a PHP integer.
*/
class MediumIntType extends Type implements PhpIntegerMappingType
{
/**
* @const string
*/
const MEDIUMINT = 'mediumint';
/**
* {@inheritdoc}
*/
public function getName(): string
{
return self::MEDIUMINT;
}
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'MEDIUMINT UNSIGNED';
}
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?int
{
return $value === null ? null : (int)$value;
}
/**
* {@inheritdoc}
*/
public function getBindingType(): int
{
return ParameterType::INTEGER;
}
} with schema create - everything is ok, but when I'm trying to update or generate diff - it always doing alter for no reason. |
Yes, this is the issue that have to be addressed. |
Are you up-to-date? I think https://www.doctrine-project.org/2021/11/26/dbal-3.2.0.html might fix that kind of issues |
closing because of Platform-aware schema comparison (#4746) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I created a custom BooleanType with the following method:
The issue is that the diff keeps altering the table as it thinks no unsigned type option should be presented.
I think there are two solutions:
a) Parse the options from Type::getSQLDeclaration() method as from the standard table definition
b) The type will implement method like "makeDefaultColumnOptions" which can every custom type override and add all options this way
mikeSimonson commented 5 hours ago
What is an unsigned boolean ?
mvorisek commented 5 hours ago
MySQL has no boolean data type. It has only TINYINT data type. So I wanted to restrict this data type to UNSIGNED one to prevent at least negative values.
note: the example is simplified, I removed all other unnecessary code, I leaved only the code which return the implicit/forced column option and it should be honored by the diff engine.
from doctrine/migrations#601 - see this thread for more comments
The text was updated successfully, but these errors were encountered: