-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
breaking change on uuid column #8002
Comments
what's the update? I need |
why just mysql changed into |
for mysql, this is like before import { randomUUID } from 'crypto';
import { BaseEntity as TypeORMBaseEntity, BeforeInsert, Column, PrimaryColumn } from 'typeorm';
export abstract class BaseEntity extends TypeORMBaseEntity {
@PrimaryColumn({ charset: 'ascii', length: 36 })
id: string;
@BeforeInsert()
generateId() {
if (this.id == null) {
this.id = randomUUID();
}
}
} |
I'm having same issue, after syncing, our production database columns get cleared because of this. Thanks for new release ! |
Ghosted our nightly DB. No biggie, that's what nightly's for. @pleerock Where does this rank priority-wise? We'd like to take advantage of the latest release. |
The same issue happened to me! This #7853 is more than breaking change to me because I have a lot of Please consider the implementation which we can choose |
Just to share some experience. Basically, the generated migration script will DROP/ADD COLUMN on the keys which can be replaced with MODIFY COLUMN. That's pretty much it for me. It's indeed troublesome if you have many tables. |
Hi! My colleague @jsproede and I had the same problem and since we didn't find any other solution, we wrote a migration. Maybe this helps one or the other. The migration reads all your entities, finds their primary/foreign keys and modifies the column type. The good thing about this solution is that no data is lost! Caution: Use at your own risk! More: #8167 #7853 import { MigrationInterface, QueryRunner } from 'typeorm';
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';
export class UUIDMigration implements MigrationInterface {
name = 'UUIDMigration';
public async up(queryRunner: QueryRunner): Promise<void> {
await this.runMigration(queryRunner, 'CHAR');
}
public async down(queryRunner: QueryRunner): Promise<void> {
await this.runMigration(queryRunner, 'VARCHAR');
}
private async runMigration(queryRunner: QueryRunner, type: 'VARCHAR' | 'CHAR') {
await this.disableForeignKeyChecks(queryRunner);
for (const { tableName, primaryColumns, foreignKeys } of queryRunner.connection.entityMetadatas) {
for (const columnName of this.getRelevantPrimaryColumnNames(primaryColumns)) {
await queryRunner.query(`ALTER TABLE ${tableName} MODIFY ${columnName} ${type}(36);`);
}
for (const foreignKey of foreignKeys) {
for (const columnName of this.getRelevantForeignKeyColumnNames(foreignKey.columns)) {
await queryRunner.query(`ALTER TABLE ${tableName} MODIFY ${columnName} ${type}(36);`);
}
}
}
await this.enableForeignKeyChecks(queryRunner);
}
private getRelevantForeignKeyColumnNames(foreignKeyColumns: ColumnMetadata[]) {
return foreignKeyColumns.filter(column => column.type === 'uuid').map(column => column.databaseName);
}
private getRelevantPrimaryColumnNames(primaryColumns: ColumnMetadata[]) {
return primaryColumns
.filter(({ type, length }) => type === 'uuid' || (type === 'varchar' && length === '36'))
.map(column => column.databaseName);
}
private async disableForeignKeyChecks(queryRunner: QueryRunner) {
await queryRunner.query('SET foreign_key_checks = 0;');
}
private async enableForeignKeyChecks(queryRunner: QueryRunner) {
await queryRunner.query('SET foreign_key_checks = 1;');
}
} |
Issue Description
update to 0.2.35, the uuid column force to char(36) #7853 , even if set type to varchar in options
Expected Behavior
if set type to varchar, it should be varchar
Actual Behavior
always char, no matter what type is set
Steps to Reproduce
// insert code here
My Environment
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?
The text was updated successfully, but these errors were encountered: