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
}
- Synchronize or create the schema.
- Run
migration:generate (or createSchemaBuilder().log()): three ALTER COLUMN ... TYPE statements.
- 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)
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.
Issue description
A geometry or geography column declared without
spatialFeatureTypeorsridproduces the sameALTER COLUMN ... TYPEstatement on everymigration:generate, even though nothing changed and running the generated migration is a no-op.Expected Behavior
Once the schema is in sync,
migration:generatereports "No changes in database schema were found."Actual Behavior
Every run emits, for each such column:
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, whichgeometry_columnsreports back as feature typeGEOMETRYwith SRID0, while the entity metadata keeps both undefined.findChangedColumnscompares the raw values, so the column always looks changed. The decorator reference already documents those defaults ("If not specified, it will behave as thoughGeometrywas provided" and "If not specified, it will default to0"); they are simply not applied in the comparison.This is distinct from #12800, which is about
precisionon spatial columns.Steps to reproduce
migration:generate(orcreateSchemaBuilder().log()): threeALTER COLUMN ... TYPEstatements.My Environment
PostgreSQL 14.22 with PostGIS 3.6.2 (the CI image) and CockroachDB v24.3.8.
Relevant Database Driver(s)
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.