-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve issue of generating migration for numeric arrays repeate…
- Loading branch information
1 parent
8af533f
commit 39fdcf6
Showing
4 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class Foo { | ||
@PrimaryGeneratedColumn("uuid", { primaryKeyConstraintName: "PK_foo" }) | ||
id: string | ||
|
||
@Column("numeric", { | ||
precision: 12, | ||
scale: 7, | ||
array: true, | ||
}) | ||
bar: number[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
|
||
describe("github issues > #10043 Numeric array column type creates migration repeatedly", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
migrations: [__dirname + "/migration/*{.js,.ts}"], | ||
schemaCreate: false, | ||
dropSchema: true, | ||
enabledDrivers: ["postgres"], | ||
})), | ||
) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("should not generate migration for synchronized sized-numeric array column", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await dataSource.runMigrations() | ||
|
||
const sqlInMemory = await dataSource.driver | ||
.createSchemaBuilder() | ||
.log() | ||
|
||
sqlInMemory.upQueries.length.should.equal(0) | ||
sqlInMemory.downQueries.length.should.equal(0) | ||
}), | ||
)) | ||
}) |
15 changes: 15 additions & 0 deletions
15
test/github-issues/10043/migration/1699343893360-create-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MigrationInterface, QueryRunner } from "../../../../src" | ||
|
||
export class CreateTable1699343893360 implements MigrationInterface { | ||
name = "CreateTable1699343893360" | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "foo" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "bar" numeric(12,7) array NOT NULL, CONSTRAINT "PK_foo" PRIMARY KEY ("id"))`, | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "foo"`) | ||
} | ||
} |