question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column not renamed when schema is set in Postgres

See original GitHub issue

Issue Description

Automatic syncronization not detect column name or type was renamed or changed

Expected Behavior

Should detect change and syncronize with database

Actual Behavior

Typeorm not detecting column name / type was changed. But syncronize work if create new entity (typeorm creating new table)

Steps to Reproduce

Typeorm Config

{
  host: process.env.PG_HOST,
  port: process.env.PG_PORT,
  username: process.env.PG_USERNAME,
  password: process.env.PG_PASSWORD,
  database: process.env.PG_DATABASE,
  schema: process.env.PG_SCHEMA
  type: 'postgres',
  logging: ['error', 'migration', 'schema', 'query'],
  namingStrategy: new SnakeNamingStrategy(),
  synchronize: this.configService.isDevelopment(),
  logger: 'advanced-console',
  migrationsTransactionMode: 'each',
  entities: [
    __dirname + '/../**/*.entity.{ts,js}',
  ]
}

Entity

export enum CourierClass {
  SAMEDAY = 'same-day',
  NEXTDAY = 'next-day',
  REGULER = 'reguler',
}

@Entity()
export class Courier {
  @PrimaryColumn()
  code: string

  @Column()
  name: string

  @Column('enum', { enum: CourierClass })
  class: CourierClass

  @Column()
  cashless: boolean

  @Column()
  logistic: string
}

Edit: Minimal repository to reproduce https://github.com/ardyfeb/typeorm-syncronize-bug

  • Run yarn run start it will syncronize first time
  • Then try change some column, name -> name_changed
  • Run yarn run start again to syncronize changes
  • Updated column will not synced with database

My Environment

Dependency Version
Operating System Linux
Node.js version v16.3.0
Typescript version ^0.2.34
TypeORM version ^4.3.5

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
imnotjamescommented, Jul 13, 2021

Digging more, this is a huge pain.

The way the table name is generated is incredibly inconsistent which is causing this issue. table.name gets set up as foo but then it gets compared against metadata.tablePath which is bar.foo. ):

I’m going to make a consistent path on the Table class which is always populated with the fully-qualified path name. This can be used for our internal comparisons. I think it will also fix a NUMBER of the other synchronization bugs we have. There’s also a few other places where I think this will help.

2reactions
imnotjamescommented, Jul 12, 2021

We reaaaaally need to create a test that would have caught this under the functional tests somewhere. I’ll get something up for that into a draft PR that I’ll use as a WIP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Renaming a column - PostgreSQL Tutorial
In this tutorial, you will learn how to use the PostgreSQL RENAME COLUMN clause in the ALTER TABLE statement to rename one or...
Read more >
Documentation: 9.6: ALTER TABLE - PostgreSQL
All the forms of ALTER TABLE that act on a single table, except RENAME, and SET SCHEMA can be combined into a list...
Read more >
Can't rename columns in PostgreSQL views with CREATE OR ...
If you issue a drop view first, it'll let you re-create the view with a changed name. I have no idea why create...
Read more >
Renaming columns not working when new name is longer ...
Hello! I found strange behavior in Postgrest: If we have a column name longer than 63 bytes (longest table/column name in bytes that...
Read more >
How to Rename the columns of a table in PostgreSQL
PostgreSQL provides a RENAME COLUMN clause that is used with the collaboration of ALTER TABLE command to rename a column.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found