Not able to add a new record on a table due to a “type xxxxx does not exist” error.
Actually this type does not exist on our database but it’s also not that one which should be used.
Forestadmin backend is looking for a type named “enum_token_account_access_permissions” while on our database the type is called “token_account_access_permissions_enum”.
It seems to be only when we try to insert data as when displayed values of this type are correct.
@anon39940173 thanks for your answer, we are using @forestadmin/datasource-sql but there is no create table statement. At that stage we try to insert a new row on an existing table (from forestadmin app, click on + Add button
I meant, can you provide me with a create table statement so that I can create the same table on a local database (on my machine) and try to reproduce the issue?
You can get those on most postgres GUI, or using pg dump
sorry I misunderstood, here is the create table statement :
CREATE TABLE test.access (
account_id character varying NOT NULL,
token_id character varying NOT NULL,
agent character varying,
provider character varying DEFAULT 'USER_MANAGED'::character varying NOT NULL,
permissions test.token_account_access_permissions_enum[] NOT NULL
);
We use sequelize under the hood in the @forestadmin/datasource-sql so that it is feasible for us to support most database vendors without maintaining separate codebases.
The issue comes from the fact that when using sequelize’s enum type, the ORM assumes that the name of the custom type in postgres is enum_${tableName}_${columnName} (which is the case when the database is initially constructed with sequelize).
I’m working on checking if I can find a fix, but honestly, I don’t think it will get done today. This will most likely involve creating a custom type in sequelize, which will take some time to write / review / release on our side.
As a workaround, would you consider renaming your enum?
ALTER TYPE old_type_name RENAME TO new_type_name;
Links to the failing code in sequelize for reference:
Hi @anon39940173 I’ve tested the latest version of packages and I still have an error : from what I can see the enum name is now correct but I think the schema name is missing and forest is not able to retrieve properly the enum (it’s looking for token_account_access_permissions_enum[] instead of servicing.token_account_access_permissions_enum[] (not 100% sure)
I also encounter the same issue as I’m using Prisma.
I tried the latest version and there’s a remaining issue linked to casing.
If the enum name contains uppercase characters, the name has to be quoted to prevent it from being automatically lowercased by Postgres.
I was able to make it work by applying this patch :
diff --git a/node_modules/@forestadmin/datasource-sql/dist/orm-builder/helpers/sequelize-type.js b/node_modules/@forestadmin/datasource-sql/dist/orm-builder/helpers/sequelize-type.js
index 8a8561e..671dd37 100644
--- a/node_modules/@forestadmin/datasource-sql/dist/orm-builder/helpers/sequelize-type.js
+++ b/node_modules/@forestadmin/datasource-sql/dist/orm-builder/helpers/sequelize-type.js
@@ -40,7 +40,7 @@ class SequelizeTypeFactory {
constructor() {
super();
this.isDataSourceSqlEnum = true;
- this.key = name;
+ this.key = '"'+name+'"';
// Steal the validate method from the ENUM type
this.validate = sequelize_1.DataTypes.ENUM.prototype.validate;
this.values = values;
@@ -54,7 +54,7 @@ class SequelizeTypeFactory {
// Setting this tells sequelize the name of the type in the database.
// This is used, most notably, when casting values (which happens when the enum is used in
// arrays)
- _a.key = name,
+ _a.key = '"'+name+'"',
_a);
return new Type();
}
Though I’m not sure if it’s the proper place to make this fix.