Column not renamed when schema is set in Postgres
See original GitHub issueIssue 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:
- Created 2 years ago
- Comments:11 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 asfoo
but then it gets compared againstmetadata.tablePath
which isbar.foo
. ):I’m going to make a consistent
path
on theTable
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.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.