-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
Migration - unecessary sql statements #1096
Comments
Experiencing the same. It also generates these unnecessary migrations when specifying the @Enum({
items: () => CoreTaskStateEnum,
columnType: 'int2' // also tried 'smallint'
})
state!: CoreTaskStateEnum Using ReflectMetadataProvider |
This is most probably because you are passing the items there. The ORM tries to diff the enum items, but it is a numeric enum, you don't really need to pass items as long as you specify the column type. This will work fine: @Enum({ columnType: 'int2' })
state!: CoreTaskStateEnum |
Let's keep this open, it should work like this automatically. |
Just had another occurence of this issue: @Enum(() => StringEnum)
type!: StringEnum with export enum StringEnum {
TEST= 'TEST'
} and the String Based Enum only has 1 value, it emits: this.addSql('alter table "test_table" drop constraint if exists "test_table_type_check";');
this.addSql('alter table "test_table" alter column "type" type text using ("type"::text);');
this.addSql('alter table "test_table" add constraint "test_table_type_check" check ("type" in (\'TEST\'));'); when you add a second value it stops emitting the Migration. If you change the enum to be like this, it stops emitting the unnecessary Migrations: export enum StringEnum {
TEST= 'TEST',
ANOTHER = 'ANOTHER'
} |
@visurel this issue is about numeric enums, string based enums should be well tested: https://github.com/mikro-orm/mikro-orm/blob/master/tests/SchemaGenerator.test.ts#L289 So if you see similar issue there, it would be great to create separate reproduction for that. |
Fixed in |
Describe the bug
Every migration in my env generates the following statements:
These are clearly unecessary, for example core_task.state is already int2 and executing does not change anything. The bug persists since i'm using mikro-orm (4.x.x) and until now only occurs when using enums.
To Reproduce
Generate a migration after applying initial migration (metadataProvider: TsMorphMetadataProvider).
Expected behavior
No unecessary/duplicate sql statement.
Versions
| Dependency | Version |
| node | 15.2.1 |
| typescript | 4.0.5 |
| mikro-orm | 4.3.0 |
| pg | 8.5.1 | (server 12)
The text was updated successfully, but these errors were encountered: