Skip to content
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

Workaround for virtual columns #1904

Closed
bspot opened this issue Jun 4, 2021 · 0 comments · Fixed by #3503
Closed

Workaround for virtual columns #1904

bspot opened this issue Jun 4, 2021 · 0 comments · Fixed by #3503
Labels
enhancement New feature or request

Comments

@bspot
Copy link

bspot commented Jun 4, 2021

Is your feature request related to a problem? Please describe.
Although MicroORM does not explicitly support MySql virtual columns, I can create one quite easily using columnType, e.g.

@Entity
class Foo {
  @Property({ columnType: 'bool GENERATED ALWAYS AS (<SOME EXPRESSION>))' })
  generated_value?: boolean
}

This appears to work fine, except that each mikro-orm migration:create will produce an alter table ... modify ... for that column, because the generator expression is currently not read back from the information schema.

Describe the solution you'd like
I understand that implementing virtual columns properly would be a major effort.
For now, I would be happy if I could tell MicroORM to just ignore that column when generating migrations.

If it helps, I would even be fine with the column not beeing part of the entity class, i.e. not having MikroORM be aware of it at all.

Describe alternatives you've considered
I'm using the virtual column to enforce a partial uniqueness constraint on the table, and I would have to find a completely different solution to doing that, e.g. triggers (which MikroORM also does not support at the moment, I think?) or just using LOCK TABLES.

@bspot bspot added the enhancement New feature or request label Jun 4, 2021
PenguinToast added a commit to PenguinToast/mikro-orm that referenced this issue Sep 14, 2022
```ts
@Property({
  columnType: 'timestamp',
  extra: 'VIRTUAL GENERATED',
  ignoreSchemaChanges: ['type', 'extra'],
})
changingField!: Date;
```

This is useful for situations such as mikro-orm#1904, where `knex` is unable to
properly diff the column.
B4nan pushed a commit that referenced this issue Sep 14, 2022
```ts
@Property({
  columnType: 'timestamp',
  extra: 'VIRTUAL GENERATED',
  ignoreSchemaChanges: ['type', 'extra'],
})
changingField!: Date;
```

This is useful for situations such as #1904, where `knex` is unable to properly diff the column.

Closes #1904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant