Skip to content

Collation changes are not synced to RDBMS #8647

@ghost

Description

Issue Description

The RDBMS schema builder ignores changes in column collation when running schema sync or when generating migrations.

For example, TypeORM may have previously generated a PostgreSQL column of type character varying COLLATE "default". I want to change the collation on the column, so I add the following decorator:

@Column({ collation: 'en-US-x-icu' })

Expected Behavior

Running typeorm schema:sync should update the collation of the column to "en-US-x-icu".

Running typeorm migration:generate should generate a migration with the query ALTER TABLE ... ALTER COLUMN ... SET DATA TYPE ... COLLATE "en-US-x-icu" as expected by PostgreSQL, or correspondingly for other DBMS's.

Actual Behavior

Running typeorm schema:sync does not change the collation of any existing columns.

Running typeorm migration:generate shows "No changes in database schema were found - cannot generate a migration."

I can still set the correct collation by running typeorm schema:drop and then typeorm schema:sync, but this obviously deletes all data, which is not always desirable.

Steps to Reproduce

  1. Create an entity:
import { Entity, Column } from 'typeorm';

@Entity()
export class Foo {
  @Column()
  name: string;
}
  1. Run typeorm schema:sync.
  2. There should now be a column named "foo"."name" with the default collation.
  3. Change the entity:
import { Entity, Column } from 'typeorm';

@Entity()
export class Foo {
  @Column({ collation: 'en-US-x-icu' })
  name: string;
}
  1. Run typeorm schema:sync again.
  2. Observe that the collation in the database has not been updated.

My Environment

Dependency Version
Operating System Debian 10.11
Node.js version 16.3.0
Typescript version 4.5.5
TypeORM version 0.2.41

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

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, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions