-
-
Notifications
You must be signed in to change notification settings - Fork 499
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
Native enum support for postgres #2764
Comments
We use mikro orm and postgres massively at work. So when I discovered this issue I spoke to my superior wether it is also interesting for us. There is a general interest there so I would like to try to implement a working solution for this problem. If I understand it correctly, The solution has to at least fullfill these conditions:
Which points do I miss? I have to work on it during my off hours so it might not be very fast, but if that is ok, I would start during this week (after thursday because its my mothers 60. birthday and I will be beaten up if I work during that ordeal) and try to implement a solution. |
Great to hear that!
Nothing should change even with postgres driver, this should be optional. We could switch the default in v6 (it will be a breaking change). But I would like to first see general community interest in that, personally as a postgres user, I am fine with current approach, but it's been some time since I worked on any web app, so my optionion is not really important :]
Yes. Note that you don't have to care about migrations, but rather about schema generator support.
I would do both global and local (in enum decorator options). I can imagine people will want to use native enums in existing apps for new things, but keep the old way so they dont have to migrate existing data. |
Sry for the silence. Due to some work I could not start with the implementation. But the good news is, that I am able to implement during work time now, because we need this feature soon... Today I only forked the project and got it to run the tests successfully. The reason for my hard time was that I tried to use my windows build environment, which does not work with your build. For a long time I tried to fix it so that it runs (I was somewhat successful), in the end i discarded my repo. Instead I use wsl2 with ubuntu 20.4 and docker-desktop. With that it took me about 5 Minutes to get everything to run smoothly and all tests to work. So tomorrow I will start with the implementation. Maybe its a good idea to add a paragraph in CONTRIBUTING.md to use wsl in windows enviroments... PS: We rebuild our fulltext search at work, based on postgres fulltext search and hope to contribute some of our results here in the near future, if you are interested. |
Cant wait for this enhancement! |
Should be an option, using enum in postgres come with some downside with array and index, which require custom index operator sometimes |
Indeed, this will be opt in, I want to keep the default as is. |
Any news regarding this feature? Happy to help to get it done if needed |
@goeddek any updates, do you need help with something? Are you stuck somewhere or just lack of time? |
This is also very useful when adding mikro-orm on top of databases that already exist and have been modeled with native enums (which is my case). |
Looks like they deleted their account - a bit interested in this feature |
Mmmm that's a shame, apparently that guy had some WIP we could at least build upon... I guess there will need to be someone else pioneering this feature. |
So this is happening for v6, see initial implementation in #4296. Few notes:
|
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes mikro-orm#2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the `nativeEnumName` option. ```ts @entity() export class User { @enum({ items: () => UserRole, nativeEnumName: 'user_role' }) role!: UserRole; } export enum UserRole { ADMIN = 'admin', MODERATOR = 'moderator', USER = 'user', } ``` Closes #2764
Is your feature request related to a problem? Please describe.
Currently we use text columns with check constraints instead of native enums.
Describe the solution you'd like
While using native enums on runtime should be generally supported, we don't allow using them in schema reflection/diffing or entity generator.
EnumOptions
andEntityProperty
to distinguish native enums (maybe also allow switching this globally)The text was updated successfully, but these errors were encountered: