Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration: every generate include alter geometry column even that column wasn't change #4534

Open
smonv opened this issue Aug 3, 2019 · 5 comments

Comments

@smonv
Copy link

smonv commented Aug 3, 2019

Issue type:

[ ] question
[ x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x ] 0.2.18 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Entity

import { Entity, Column } from 'typeorm';
import { Geometry } from 'geojson';

@Entity()
export class Store {
    @Column({ type: 'geometry', srid: 4326 })
    geometry: Geometry;
}

Everytime I run migration:generate it include the code below to migration script. I have manually delete it inside up and down function.

await queryRunner.query(`ALTER TABLE "store" ALTER COLUMN "geometry" TYPE geometry(GEOMETRY,0)`);
@krazibit
Copy link

You need to add the spartialFeatureType option and set it to Geometry in your case.
The issue is from here https://github.com/typeorm/typeorm/blob/master/src/driver/postgres/PostgresDriver.ts#L783
The code column metadata differs from that from the actual table, because it's defaulted to geometry on the table when not specified I think, so comparing undefined with geometry .
Same issue would happen if srid is not defined in the column options, the code metadata would have undefined for the srid because of here

if (options.args.options.srid)
, and the db column metadata defaults to 0.
This makes the migration process think there are changes.
@pleerock can you confirm. Thanks

@dflourusso
Copy link

I'm using:

  @Column('geometry', { spatialFeatureType: 'Point', srid: 4326 })
  @IsNotEmpty()
  location: Point

and having the same issue. How can i solve it?

@smonv
Copy link
Author

smonv commented Feb 14, 2020

After applied the suggestion from @krazibit , i'm still facing same issue

@Column('geometry', { srid: 4326, spatialFeatureType: 'Point' })
coordinates: Point;
 await queryRunner.query(
       `ALTER TABLE "store" ALTER COLUMN "coordinates" TYPE geometry(Point,4326)`,
        undefined,
 );

@JeyongOh-MAASASIA
Copy link

JeyongOh-MAASASIA commented Feb 17, 2020

This PR #5525 solves this problem.
I forgot to link this issue in PR, so this issue is not closed automatically.
This issue can be closed.
@pleerock

@BlakeGardner
Copy link

For anyone else looking for a solution to this issue, this was affecting me with Postgres using the following code:

  @Column({
    type: 'point',
    spatialFeatureType: 'Point',
    srid: 4326,
  })
  point: string;

For whatever reason, changing my column to this fixed the issue for me:

import { Point } from 'typeorm';


  @Column('geometry', {
    spatialFeatureType: 'Point',
    srid: 4326,
  })
  point: Point;

Not entirely sure if this is still considered a bug, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants