Skip to content

Postgres: geometry column with precision generates an endless phantom migration #12800

Open

Description

@mkovac-conductive

Issue description

A geometry column declared with precision produces the same ALTER COLUMN ... TYPE geometry(...) statements on every migration:generate, even when nothing has changed. Running the generated migration is a no-op, and the next generate emits the identical statements again — an endless phantom diff.

Expected Behavior

After applying a generated migration, a subsequent migration:generate on an unchanged schema should report "No changes in database schema were found."

Actual Behavior

migration:generate repeatedly emits, for each geometry column, an ALTER COLUMN ... TYPE statement even when nothing has changed:

ALTER TABLE "WorkOrder" ALTER COLUMN "geometry" TYPE geometry(Geometry,4326)
Applying the generated migration is a no-op, and the next migration:generate emits the identical statement again — an endless phantom diff that never converges to "No changes in database schema were found."

Steps to reproduce

Define an entity with a geometry column that sets precision (commonly done so TypeORM reads it as ST_AsGeoJSON(col, ) and preserves coordinate digits):

@Column({
  type: 'geometry',
  srid: 4326,
  spatialFeatureType: 'Geometry',
  precision: 15,
})
geometry: string

Sync/create the column in the database.

Run migration:generate — it emits ALTER COLUMN "geometry" TYPE geometry(Geometry,4326).

Apply that migration (migration:run).

Run migration:generate again → the same statement is emitted. Repeat forever.

My Environment

Dependency Version
Operating System macOS 14.4.1
Node.js version 22.18.0
Typescript version 5.9.3
TypeORM version 0.3.28

Additional Context

No response

Relevant Database Driver(s)

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

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

Yes, I have the time, and I know how to start.

Activity

  1. added 2 commits that reference this issue on Aug 26, 2026
    7bdaa00
    5a8c652
  2. mkovac-conductive commented on Aug 26, 2026

    @mkovac-conductive
    Author

    Why the bug happens:

    You declare a geometry column with precision: 15. That number only exists in TypeORM's entity metadata — it's used to read the column as ST_AsGeoJSON(col, 15). PostgreSQL never stores it: a geometry column's type is just geometry(Point, 4326) — feature type and SRID, no precision.

    So on every sync, TypeORM compares:

    • entity says precision = 15
    • database reads back precision = undefined (nothing to store it in)

    15 !== undefined is always true → the column is flagged as "changed." Applying a migration can't fix it either, because the geometry type carries no precision to write — so the mismatch is permanent and repeats forever.

  3. added a commit that references this issue on Aug 27, 2026
    673232c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions