Skip to content

Postgres/CockroachDB: spatial columns without spatialFeatureType or srid generate an endless no-op migration #12811

Description

@samuelmbabhazi

Issue description

A geometry or geography column declared without spatialFeatureType or srid produces the same ALTER COLUMN ... TYPE statement on every migration:generate, even though nothing changed and running the generated migration is a no-op.

Expected Behavior

Once the schema is in sync, migration:generate reports "No changes in database schema were found."

Actual Behavior

Every run emits, for each such column:

ALTER TABLE "post" ALTER COLUMN "geom" TYPE geometry
ALTER TABLE "post" ALTER COLUMN "pointWithoutSRID" TYPE geometry(Point)
ALTER TABLE "post" ALTER COLUMN "geog" TYPE geography

This reproduces with the repository's own spatial test entity (test/functional/spatial/postgres/entity/Post.ts): logging the schema builder against it returns those three queries on PostGIS 3.6 and on CockroachDB v24.3.8 alike.

Cause: the column is created as plain geometry, which geometry_columns reports back as feature type GEOMETRY with SRID 0, while the entity metadata keeps both undefined. findChangedColumns compares the raw values, so the column always looks changed. The decorator reference already documents those defaults ("If not specified, it will behave as though Geometry was provided" and "If not specified, it will default to 0"); they are simply not applied in the comparison.

This is distinct from #12800, which is about precision on spatial columns.

Steps to reproduce

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

    @Column("geometry", { nullable: true })
    geom: Geometry

    @Column("geometry", { nullable: true, spatialFeatureType: "Point" })
    pointWithoutSRID: Point

    @Column("geography", { nullable: true })
    geog: Geography
}
  1. Synchronize or create the schema.
  2. Run migration:generate (or createSchemaBuilder().log()): three ALTER COLUMN ... TYPE statements.
  3. Apply them and generate again: the same three statements.

My Environment

Dependency Version
Operating System Linux
Node.js version 22
Typescript version 5.x
TypeORM version master (b495ed4)

PostgreSQL 14.22 with PostGIS 3.6.2 (the CI image) and CockroachDB v24.3.8.

Relevant Database Driver(s)

  • postgres
  • cockroachdb

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions