sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Support MariaDB UUID type

Open mpldr opened this issue 1 year ago • 2 comments

What do you want to change?

MariaDB has some extensions over standard MySQL, most notably a UUID type, which currently leads to:

internal/datastore/mysql/migrations/schema.sql:4:44: syntax error near "uuid NOT NULL DEFAULT (uuid()), `uploaded` datetime NOT NULL DEFAULT (current_timestamp()), `owner` int NOT NULL, PRIMARY KEY (`id`), INDEX `owner` (`owner`), CONSTRAINT `owner` FOREIGN KEY (`owner`) REFERENCES `irori`.`organisations` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;"

It would be nice to have it supported.

The schema:

-- Create "organisations" table
CREATE TABLE `irori`.`organisations` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `description` varchar(255) NOT NULL, PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
-- Create "documents" table
CREATE TABLE `irori`.`documents` (`id` uuid NOT NULL DEFAULT (uuid()), `uploaded` datetime NOT NULL DEFAULT (current_timestamp()), `owner` int NOT NULL, PRIMARY KEY (`id`), INDEX `owner` (`owner`), CONSTRAINT `owner` FOREIGN KEY (`owner`) REFERENCES `irori`.`organisations` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
-- Create "user" table
CREATE TABLE `irori`.`user` (`id` int NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `token_sub` varchar(128) NOT NULL, PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
-- Create "user_organisations" table
CREATE TABLE `irori`.`user_organisations` (`user` int NOT NULL, `organisation` int NOT NULL, `permissions` int NOT NULL, INDEX `organisation` (`organisation`), INDEX `user` (`user`), CONSTRAINT `organisation` FOREIGN KEY (`organisation`) REFERENCES `irori`.`organisations` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT `user` FOREIGN KEY (`user`) REFERENCES `irori`.`user` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION) CHARSET utf8mb4 COLLATE utf8mb4_general_ci;

What database engines need to be changed?

MySQL

What programming language backends need to be changed?

Go

mpldr avatar May 27 '24 14:05 mpldr

Since this is in a sense an extension to MySQL, this should probably be accompanied by a warning about this type not being available in all server implementations.

mpldr avatar May 27 '24 15:05 mpldr

Okay, I've taken a look, and it seems to be something for github.com/pingcap/tidb's parser, which would probably involve a lot of convincing. Any idea on how to do it better?

mpldr avatar May 30 '24 12:05 mpldr