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