Skip to content

Numeric array column type creates migration repeatedly #10043

@jorenvandeweyer

Description

@jorenvandeweyer

Issue description

When generating a migration, typeorm repeatedly creates a migration for a column that has not changed.

Expected Behavior

There should no migration be generated.

Actual Behavior

A migration is generated which should not be generated.

import type { MigrationInterface, QueryRunner } from 'typeorm'

export class FixMigrations1683791266417 implements MigrationInterface {
  name = 'FixMigrations1683791266417'

  public async up (queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('ALTER TABLE "benefit_code_schema" ALTER COLUMN "values" TYPE numeric(11,4) array')
  }

  public async down (queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('ALTER TABLE "benefit_code_schema" ALTER COLUMN "values" TYPE numeric array')
  }
}

Steps to reproduce

I already created a failing test to debug the issue

// test/github-issues/10043/entity/Receipt.ts

import { Column, Entity, PrimaryGeneratedColumn } from '../../../../src';

@Entity()
export class Receipt {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ type: 'numeric', precision: 11, scale: 4, array: true })
  values: number[]
}
// test/github-issues/10043/issue-10043.ts

import "reflect-metadata";
import { createTestingConnections, closeTestingConnections, reloadTestingDatabases } from "../../utils/test-utils";
import { DataSource } from "../../../src/data-source/DataSource"

describe.only("github issues > #10043 Numeric array column type creates migration repeatedly", () => {

    let dataSources: DataSource[];
    before(async () => dataSources = await createTestingConnections({
        entities: [__dirname + "/entity/*{.js,.ts}"],
        schemaCreate: true,
        dropSchema: true,
    }));
    beforeEach(() => reloadTestingDatabases(dataSources));
    after(() => closeTestingConnections(dataSources));

    it("can recognize model changes", () => Promise.all(dataSources.map(async dataSource => {
      if (dataSource.driver.options.type !== "postgres") {
        return;
      }
      const sqlInMemory = await dataSource.driver.createSchemaBuilder().log();
      sqlInMemory.upQueries.length.should.be.greaterThan(0);
      sqlInMemory.downQueries.length.should.be.greaterThan(0);
    })));

    it("does not generate when no model changes", () => Promise.all(dataSources.map(async dataSource => {
      if (dataSource.driver.options.type !== "postgres") {
        return;
      }
      await dataSource.driver.createSchemaBuilder().build();

      const sqlInMemory = await dataSource.driver.createSchemaBuilder().log();

      sqlInMemory.upQueries.length.should.be.equal(0);
      sqlInMemory.downQueries.length.should.be.equal(0);
    })));
});

My Environment

Dependency Version
Operating System Mac
Node.js version 20.0.0
Typescript version 4.9.5
TypeORM version 0.3.16

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

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

Yes, I have the time, but I don't know how to start. I would need guidance.

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