Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/driver/postgres/PostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,12 @@ export class PostgresDriver implements Driver {
tableColumn.type !== this.normalizeType(columnMetadata) ||
tableColumn.length !== columnMetadata.length ||
tableColumn.isArray !== columnMetadata.isArray ||
tableColumn.precision !== columnMetadata.precision ||
(columnMetadata.scale !== undefined &&
(this.withPrecisionColumnTypes.indexOf(columnMetadata.type) !==
-1 &&
tableColumn.precision !== columnMetadata.precision) ||
(this.withScaleColumnTypes.indexOf(columnMetadata.type) !==
-1 &&
columnMetadata.scale !== undefined &&
tableColumn.scale !== columnMetadata.scale) ||
tableColumn.comment !==
this.escapeComment(columnMetadata.comment) ||
Expand Down
10 changes: 8 additions & 2 deletions src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,14 @@ export class PostgresQueryRunner
}

if (
newColumn.precision !== oldColumn.precision ||
newColumn.scale !== oldColumn.scale
(this.driver.withPrecisionColumnTypes.indexOf(
newColumn.type as ColumnType,
) !== -1 &&
newColumn.precision !== oldColumn.precision) ||
(this.driver.withScaleColumnTypes.indexOf(
newColumn.type as ColumnType,
) !== -1 &&
newColumn.scale !== oldColumn.scale)
) {
upQueries.push(
new Query(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Column, Entity, Index, PrimaryColumn } from "../../../../../../src"

@Entity()
@Index(["location", "area"], { spatial: true })
export class Test {
@PrimaryColumn()
id: number

@Column({
type: "geometry",
srid: 4326,
spatialFeatureType: "Point",
precision: 15,
})
location: string

@Column({
type: "geometry",
srid: 4326,
spatialFeatureType: "Polygon",
precision: 15,
})
area: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { DataSource } from "../../../../../src"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../../../utils/test-utils"
import { Test } from "./entity/Test"
import { expect } from "chai"

describe("schema builder > idempotency > spatial precision", () => {
let dataSources: DataSource[]
before(async () => {
dataSources = await createTestingConnections({
entities: [Test],
enabledDrivers: ["postgres"],
})
})
beforeEach(() => reloadTestingDatabases(dataSources))
after(() => closeTestingConnections(dataSources))

// https://github.com/typeorm/typeorm/issues/12800
it("should not generate migrations for spatial columns with precision participating in a composite index", async () => {
await Promise.all(
dataSources.map(async (connection) => {
const sqlInMemory = await connection.driver
.createSchemaBuilder()
.log()
expect(sqlInMemory.upQueries).to.eql([])
expect(sqlInMemory.downQueries).to.eql([])
}),
)
})
})
Loading