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

Diff is not working if options are set directly in Type::getSQLDeclaration() #3021

Closed
mvorisek opened this issue Feb 13, 2018 · 8 comments
Closed

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Feb 13, 2018

I created a custom BooleanType with the following method:

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) {
    return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration) . ' UNSIGNED';
}

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

@UBERPHP
Copy link

UBERPHP commented Jan 6, 2019

what about custom type mediumint?
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'MEDIUMINT UNSIGNED';
}

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 6, 2019

The issue is with DOctrine diff, run:
.\doctrine.bat orm:schema-tool:update --dump-sql --force

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.

@UBERPHP
Copy link

UBERPHP commented Jan 6, 2019

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.
Additionally - is I'm changing existing text type field in the database to longtext - diff/update wont detect it and do correction.

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 6, 2019

with schema create - everything is ok, but when I'm trying to update or generate diff - it always doing alter for no reason.
Additionally - is I'm changing existing text type field in the database to longtext - diff/update wont detect it and do correction.

Yes, this is the issue that have to be addressed.

@jurgenbosch
Copy link

@mvorisek @UBERPHP Is there any update on the issue mentioned above? I have a custom type and on each diff the diff is altering the table on the custom type.

@greg0ire
Copy link
Member

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

@mvorisek
Copy link
Contributor Author

closing because of Platform-aware schema comparison (#4746)

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants