Skip to content

Virtual columns are dropped and regenerated in each migrations #8520

@RawZ06

Description

@RawZ06

Issue Description

Expected Behavior

I would like not regenerate virtual columns.

Actual Behavior

When I create a virtual column, each time I type typeorm migration:generate, typeorm dropped and regenerate virtual column.

Steps to Reproduce

  1. I create an entity with virtual column
@Column({
    asExpression: `CONCAT(firstname, ' ', lastname)`,
    generatedType: 'VIRTUAL',
    length: 255,
    nullable: false,
})
name: string;
  1. I generate migration with typeorm migration:generate
  2. I regenerate migration

And I have this ouput in my migration :

public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(
            `ALTER TABLE \`user\` CHANGE \`name\` \`name\` varchar(255) AS (CONCAT(firstname, ' ', lastname)) VIRTUAL`,
        );
}

public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(
            `ALTER TABLE \`user\` CHANGE \`name\` \`name\` varchar(255) AS CONCAT(firstname, ' ', lastname)) VIRTUAL`,
        );
}

My Environment

Dependency Version
Operating System Linux Ubuntu 18.04
Node.js version 14.17
Typescript version 4.1.5
TypeORM version 0.2.41

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
mariadb yes
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions