Skip to content

Generated migrations confused by columnDefinition that contains GENERATED ALWAYS AS #6641

@gravitiq-cm

Description

@gravitiq-cm

Bug Report

Q A
Version dbal: 3.9.3, orm: 2.20.0

Summary

When using make:migration to generate migrations, fields which use columnDefinitions end up generating the same up() statement every time (even after the migration has been run).

Current behavior

Field attribute is something like this:

#[ORM\Column(type: Types::STRING, length: 10, insertable: false, updatable: false, 
columnDefinition: 'VARCHAR(10) GENERATED ALWAYS AS (bar) STORED')]

Generated migration looks something like this:

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE my_table CHANGE foo foo VARCHAR(10) GENERATED ALWAYS AS (bar) STORED');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE my_table CHANGE foo foo VARCHAR(10) DEFAULT NULL');
    }

When you run the migration everything works. But when you generate the next migration it tries to make the same changes again.

Expected behavior

When you generate the next migration, Doctrine should recognise that it is trying to make a change that has already been done and not add the GENERATED ALWAYS... code to the next migration

How to reproduce

Add a columnDefinition to a field, generate migration, run it then generate the next migration.

I tried looking in the Comparator but struggled to find the detail. In diffColumn() I can see that $column2['columnDefinition'] is blank compared to $column1['columnDefinition'] which contains the GENERATED ALWAYS code, but I don't fully understand where $column2 comes from or why Connection::getSchema() would return a blank columnDefinition...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions