accounts icon indicating copy to clipboard operation
accounts copied to clipboard

Schema modification to change unsupported column type

Open kfrajtak opened this issue 5 years ago • 7 comments

Hi,

I am trying to use Accounts graphql module with MySql database in my app and I'm getting

Data type "jsonb" in "User.profile" is not supported by "mysql" database.

Is there a way how change the column type for User.profile without actually modifying the compiled file (node_modules\@accounts\typeorm\lib\entity\UserService.js)? There are more occurrences of the jsonb type.

Thank you, Karel

kfrajtak avatar Mar 14 '19 13:03 kfrajtak

I think for now the typeorm implementation is only working with postgresql, can you confirm @birkir?

pradel avatar Mar 15 '19 08:03 pradel

Yes but my plan was to add non-json column type sql support.

Actually I made sure to already split up the columns so that everything was prepared for this.

Just matter of using JSON.parse/stringify if column type is not json/json.

I will have time for this very soon.

birkir avatar Mar 15 '19 12:03 birkir

@birkir the profile should be managed by the users see #617

pradel avatar Mar 17 '19 21:03 pradel

@birkir @pradel there is another jsonb column in UserService class, the options property. Is it possible to modify it as well? also UserSession.extra property.

this type is not compatible with all databases

lihaibh avatar Mar 18 '19 09:03 lihaibh

@lihaibh you are right, my bad I will reopen the issue

pradel avatar Mar 18 '19 09:03 pradel

@birkir I don't really know how typeorm is working but is there a way to do some database specific logic? (eg use jsonb for postgres and use another table for mysql?) The problem I can see with json stringify / parse is that it will not be easy for the user to run some queries on these fields.

pradel avatar Mar 18 '19 09:03 pradel

@pradel the only workaround I see is to use actual types as entities and OneToOne annotation and if its necessary to add fields we will have to extend these types. so for example for UserService.options:

  @Column('jsonb', { nullable: true })
  public options: { bcrypt: string } | any;

have to replace with:

  @Column({ nullable: true })
  @OneToOne(...)
  public options: UserServiceOptions;

lihaibh avatar Mar 18 '19 10:03 lihaibh