DEV Community

Cover image for Quick conversion of Enums into Tables for Hasura
Olivier
Olivier

Posted on

Quick conversion of Enums into Tables for Hasura

tldr; I have a ton of Enums in my pretty schema but now Hasura tells me they want tables instead! Here is a script #regexForTheWin


Why?

Hasura recommends Tables versus Enum types see why here

How it works.js

Given a sql string with CREATE TYPEs. .. in it, convert them to CREATE TABLE.

Don't forget

Tell hasura to use those tables as enum tables and don't forget to update the fields that used to reference your enums by pointing to the table and adding foreign keys. For example:

ALTER TABLE myschema.users ADD CONSTRAINT
  myschema."usersStatus_fkey" FOREIGN KEY (status) REFERENCES myschema."Status";
Enter fullscreen mode Exit fullscreen mode

Here is the gist of it:

What you get

Top comments (0)