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

Schema sync not able to find diff correctly and executes same queries on every run #7276

Closed
2 of 21 tasks
codeslayer1 opened this issue Jan 14, 2021 · 0 comments · Fixed by #7575
Closed
2 of 21 tasks

Comments

@codeslayer1
Copy link

codeslayer1 commented Jan 14, 2021

Issue Description

I am migrating an existing Postgres DB to Typeorm. I generated the entities using this package. My entities were generated correctly and schema sync was also able to recreate all my tables on a fresh instance. But the problem is that if I try to run schema:sync again, it starts executing the same queries again even though all the tables & constraints are already there.

Attaching one of my entity files

import { Column, Entity, Index } from 'typeorm';

@Index('cluster_clu_created_fef900_idx', ['created_at'], {})
@Index('cluster_cluster_pkey', ['uuid'], { unique: true })
@Entity('cluster_cluster', { schema: 'public' })
export class ClusterCluster {
  @Column('uuid', { primary: true, name: 'uuid' })
  uuid: string;

  @Column('timestamp with time zone', { name: 'created_at' })
  created_at: Date;

  @Column('timestamp with time zone', { name: 'updated_at' })
  updated_at: Date;

  @Column('character varying', { name: 'category', length: 30 })
  category: string;

  @Column('character varying', { name: 'parent', length: 255 })
  parent: string;

  @Column('varchar', { name: 'children', array: true })
  children: string[];
}

I tried to look into existing issues and found one similar issue #3907 . On removing the { schema: 'public' } from my entities, the create table queries were fixed & not getting recreated but the indexes and constraints are still getting dropped & recreated. Also I don't think removing schema is a permanent solution since I wish to use multiple schemas. Could someone point me in the right direction here. Thanks.

Expected Behavior

The create table/indexes/constraints queries to be executed on first schema sync and thereafter no queries should be executed if no entity changes are present

Actual Behavior

Check issue description

Steps to Reproduce

Not sure. I guess creating any entity with schema decorator could result in this issue.

My Environment

Dependency Version
Operating System Mac
Node.js version v12.16.3
Typescript version v4.1.3
TypeORM version v0.2.29
Project Nest.js

Additional Context

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • 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.
  • Yes, I have the time, but I don't know how to start. I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@AlexMesser AlexMesser self-assigned this Apr 10, 2021
AlexMesser added a commit that referenced this issue Apr 16, 2021
AlexMesser added a commit that referenced this issue Apr 16, 2021
AlexMesser added a commit that referenced this issue Apr 17, 2021
…ry queries during schema sync (#7575)

* working on #7276

* minor fix

* fix #7276

* lint fix

* added `getCurrentDatabase()` and `getCurrentSchema()` methods in QueryRunner

* fixed falling test;

* fixed default schema in other drivers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants