System generated primary key

Feature(s) impacted

I am trying to let users create rows from the ForestAdmin. Most tables have an id column that stores a unique UUID for that row. It’s a bad user experience to make a user generate a UUID to then plug into the create form. So the thinking was, let MySQL generate that UUID.

| clients | CREATE TABLE `clients` (
  `id` char(36) NOT NULL DEFAULT (uuid()),
  `name` varchar(255) DEFAULT NULL,
  `slug` varchar(15) NOT NULL,
  `date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `date_updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `slug` (`slug`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |

This works fine. However, ForestAdmin tries to insert the string “uuid()” everytime a row is created now. Is there anyway to trick ForestAdmin into not inserting anything in that id column?

Is there some alternative way here? I definitely don’t want to change all my tables away from UUIDs but I will if that is impossible to have with Forest. I don’t want users to have to generate a UUID to plug into a create form field.

Context

  • Project name: refinition-data
  • Database type: MySQL 8

Hello @nkconnor,

Thanks for reporting on your issue. It seems like we have a bug on our end. I’m opening a ticket to track it on our side and will report once it has been resolved.

Regards,

@Nicolas.M

Thanks Nick. Have you seen any common patterns on how other users utilize UUIDs as a primary key but also allow users to create models without having to type out UUIDs?

I would assume that most users use an auto-increment integer primary key instead of a default uuid generated by a function:
You may find some info about that here for MySQL:
https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html
If you have some control over the database schema, this might help you work around the issue while we perform the fix.

Regards,

Hello @nkconnor,

We just released new versions of the packages @forestadmin/agent and @forestadmin/datasource-sql that are fixing this issue.

Could you please upgrade to the latest versions and check if it’s working on your side?

Thanks

Good morning @GuillaumeGautreau ,

I have attempted writing to a table with a uuid defaulting primary key per Nick’s original message. A true uuid is now being written properly to the DB instead of the string “uuid()”. However, it does not appear that Forest is properly forwarding the UI to the new entity.

The error message returned instead is: “Temp Test Entity #[object Object] cannot be found”

The table DDL is basic for a proof of concept:

create table temp_test_entity(
	uuid char(36) default (UUID()) primary key,
    name varchar(25)
);

Unfortunately, this issue renders the earlier solution useless to us. Please let me know if you have any questions.

Thank you for your help,
Brendan

Hello @Brendan_Arsenault , and welcome to the community.

Since this is a solved topic, I suggest that you open up a new topic following the template pertaining to your particular project details.
Could you please also provide some more details about your issue. I’m not sure what ‘However, it does not appear that Forest is properly forwarding the UI to the new entity.’ means in this context.

It will be easier for us to manage and find a suitable resolution

Thanks ! :pray:

Regards,

@Nicolas.M