Closed
Description
Issue description
When i generates new migrations, then typeorm always trying to recreate some defualts
Expected Behavior
Typeorm shouldn't try to recreate defauls
Actual Behavior
Typeorm always recreates defaults.
Steps to reproduce
This is what typeorm generates
await queryRunner.query(`ALTER TABLE "channel_events_donations" ADD "donateId" character varying`);
await queryRunner.query(`ALTER TABLE "channels_modules_settings" ALTER COLUMN "id" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "channels_modules_settings" ALTER COLUMN "id" SET DEFAULT gen_random_uuid()`);
await queryRunner.query(`ALTER TABLE "channels_requested_songs" ALTER COLUMN "id" DROP DEFAULT`);
await queryRunner.query(`ALTER TABLE "channels_requested_songs" ALTER COLUMN "id" SET DEFAULT gen_random_uuid()`);
```
My entity
@entity('channels_modules_settings')
export class ChannelModuleSettings {
@PrimaryColumn('uuid', {
primary: true,
name: 'id',
default: () => 'gen_random_uuid()',
})
id: string;
@column('enum', { enum: ModuleType })
type: ModuleType;
@column('jsonb')
settings: Record<string, any>;
@column()
channelId: string;
@manytoone('Channel', 'modules')
@joincolumn({ name: 'channelId' })
channel?: Relation;
}
### My Environment
| Dependency | Version |
| --- | --- |
| Operating System | |
| Node.js version | 18.2.1 |
| Typescript version | 4.9 |
| TypeORM version | 0.3.10 |
### Additional Context
_No response_
### Relevant Database Driver(s)
- [ ] aurora-mysql
- [ ] aurora-postgres
- [ ] better-sqlite3
- [ ] cockroachdb
- [ ] cordova
- [ ] expo
- [ ] mongodb
- [ ] mysql
- [ ] nativescript
- [ ] oracle
- [X] postgres
- [ ] react-native
- [ ] sap
- [ ] spanner
- [ ] sqlite
- [ ] sqlite-abstract
- [ ] sqljs
- [ ] sqlserver
### Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don't know how to start. I would need guidance.
Activity
jleverenz commentedon Feb 2, 2023
I just ran into a similar issue, due to the
default: () => 'gen_random_uuid()'
configuration. Re-reading the TypeORM docs, switching to one of theGenerated
decorators solved it for me, it might work for you. Try:I think you might get the same effective sql generated, without the repeated migrations.
kacsablabla commentedon May 23, 2023
I've had the same issue when upgrading typeorm 0.3.11 to 0.3.16. I reverted it, and works again.
N-Andronopoulos commentedon May 28, 2023
I have the same issue with mysql2 v2 or v3 driver after version 0.3.10 (tried 0.3.12 and 0.3.16 issue exists in both).
It tries to recreate ids and relations FKs etc.
We use
@PrimaryGeneratedColumn('uuid')
on all entities as well.e.g.
arminhupka commentedon May 31, 2023
I had the same issue and I decided to update to @next version and everything is now is ok
ankitchhatbar commentedon Jun 3, 2023
The below works well for me
N-Andronopoulos commentedon Jun 4, 2023
Linked to #10090
pleerock commentedon Jun 20, 2023
Must be fixed by #10041
sirmonin commentedon Feb 26, 2024
@pleerock this issue has been fixed for MySQL only. PostgreSQL is mentioned in the issue description by @Satont, and I can confirm that even 0.3.20 version still has this issue. Please, reopen this.
I use @PrimaryGeneratedColumn('uuid') and pgcrypto plugin