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

DBAL-939: schema update doesnt detect boolean type correctly #2182

Closed
doctrinebot opened this issue Jul 16, 2014 · 4 comments
Closed

DBAL-939: schema update doesnt detect boolean type correctly #2182

doctrinebot opened this issue Jul 16, 2014 · 4 comments

Comments

@doctrinebot
Copy link

Jira issue originally created by user rehfeldchris:

_edited_

Dbal for db2 doesn't seem to be able to differentiate between a smallint and a boolean field on db2. If I make an entity which has a boolean field, it will create a table using type smallint. If I later try to update the schema, it will detect the column in the table as a small int, not a boolean. So, it will produce sql update statements to change the type from smallint to smallint, which is obviously unnecessary. I understand db2 doesn't have a boolean type, but it would be nice if dbal realized that a smallint is essentially already a dbal boolean.

Additionally, the update statement is invalid syntax and fails, although this is probably a separate issue.

Example entity

<?php
/****
 * @ORM\Entity
 ****/
class Widget
{
    /*** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue ***/
    protected $id;

    /*** @ORM\Column(type="boolean", nullable=false) ***/
    private $isGoat;
}

orm:schema-tool:create produces:
CREATE TABLE Widget (id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL, isGoat SMALLINT NOT NULL, PRIMARY KEY(id));

If you then run orm:schema-tool:update, it will try to run:

ALTER TABLE WIDGET ALTER ISGOAT isGoat SMALLINT NOT NULL; CALL SYSPROC.ADMIN_CMD ('REORG TABLE WIDGET');

but no column alteration is obviosuly needed.

So in summary, smallint to boolean type mapping isn't realized, causing the update command to think it needs to change the type of the column.

@doctrinebot
Copy link
Author

Comment created by rehfeldchris:

I was thinking of giving this bug an attempt, but I want some advice on how to fix it properly from those who live and breathe this code base.

Additionally, I recently added a custom utcdatetime type , and now I'm having the same issue with that - doctrine reporting that I should alter all my date columns to modify them to a "TIMESTAMP(0)", even though they're already that type. So, I really think a proper solution would look at the actual mapping definitions being used to decide if a schema change should be suggested.

One idea I have is to modify Doctrine\DBAL\Schema\Comparator->diffColumn() so that it doesn't report this as a diff. However, I think this boolean to smallint mapping fact is platform dependent, so there would need to be some way for the Comparator to behave platform specific for this behavior. This sounds ugly to me.

Another idea would be to modify the specific platform objects themselves to take care of filtering out these frivolous differences in their getAlterTableSQL() methods. The platform object seems to know about type mappings, so maybe it would be appropriate to do something here.

I also see some event listeners that look like they might be able to be leveraged to pull this off here.

Any suggestions? Thanks.

@doctrinebot doctrinebot added the Bug label Dec 7, 2015
@deeky666 deeky666 assigned deeky666 and unassigned beberlei Jan 6, 2016
@deeky666 deeky666 added this to the 2.5.5 milestone Jan 6, 2016
@deeky666 deeky666 added the WIP label Jan 6, 2016
@deeky666 deeky666 added PR Created and removed WIP labels Jan 6, 2016
deeky666 added a commit to deeky666/dbal that referenced this issue Jan 6, 2016
- fixes platform's COMMENT ON statement support
- implements reverse engineering for column comments
- marks boolean column type commented for distinction

fixes doctrine#2182
@deeky666
Copy link
Member

deeky666 commented Jan 6, 2016

Patch provided in #2277

deeky666 added a commit to deeky666/dbal that referenced this issue Jan 8, 2016
- fixes platform's COMMENT ON statement support
- implements reverse engineering for column comments
- marks boolean column type commented for distinction

fixes doctrine#2182
Ocramius pushed a commit that referenced this issue Sep 9, 2016
- fixes platform's COMMENT ON statement support
- implements reverse engineering for column comments
- marks boolean column type commented for distinction

fixes #2182
Ocramius added a commit that referenced this issue Sep 9, 2016
…n-on-db2-2.5' into 2.5

Close #2182
Close #2277
Close DBAL-939
Ocramius added a commit that referenced this issue Sep 9, 2016
@Ocramius
Copy link
Member

Ocramius commented Sep 9, 2016

Handled in #2277

@github-actions
Copy link

github-actions bot commented Aug 7, 2022

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 Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants