chartdb / chartdb

Free and Open-source database diagrams editor, visualize and design your DB with a single query.
https://chartdb.io
GNU Affero General Public License v3.0
2.93k stars 138 forks source link

Support for user defined types #110

Open LuisSarmientoM opened 2 weeks ago

LuisSarmientoM commented 2 weeks ago

Tables can contain a custom type created by the user with CREATE TYPE visibility AS ENUM ('public', 'private', 'mixed'); to use as an enum on some values

johnnyfish commented 1 week ago

@LuisSarmientoM Thank you! Can you explain how would you going to use that visibility type if we will bring custom types to ChartDB :)?

LuisSarmientoM commented 1 week ago

Sure, CleanShot 2024-09-01 at 14 46 37@2x here I define a relation between users and certifications, each certification has a TYPE value whose only valid value is Certification or License, otherwise prevent the creation or update.


In ChartDB maybe work like this

CleanShot 2024-09-01 at 14 54 04@2x

MrJ8585 commented 1 week ago

Hey @johnnyfish, can I work on this one?

MrJ8585 commented 1 week ago

@johnnyfish I'm already working on this issue, but I have a question There are different ways the DBs support enums (or don't support them natively but can be emulate) Here are some examples PostgreSQL CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral'); CREATE TABLE person ( name text, current_mood mood ); MySQL CREATE TABLE person ( name VARCHAR(50), mood ENUM('happy', 'sad', 'neutral') ); SQL Server, SQLite CREATE TABLE person ( name NVARCHAR(50), mood NVARCHAR(50) CHECK (mood IN ('happy', 'sad', 'neutral')) ); Besides PostgreSQL, the enums are defined in the table, so should I do it that way for all DBs?

johnnyfish commented 1 week ago

@johnnyfish I'm already working on this issue, but I have a question

There are different ways the DBs support enums (or don't support them natively but can be emulate)

Here are some examples

PostgreSQL

`CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral');

CREATE TABLE person (

name text,

current_mood mood

);`

MySQL

`CREATE TABLE person (

name VARCHAR(50),

mood ENUM('happy', 'sad', 'neutral')

);`

SQL Server, SQLite

`CREATE TABLE person (

name NVARCHAR(50),

mood NVARCHAR(50) CHECK (mood IN ('happy', 'sad', 'neutral'))

);`

Besides PostgreSQL, the enums are defined in the table, so should I do it that way for all DBs?

Hey @MrJ8585, sorry I missed your comment here. It's a bit complicated issue and I have already started working on it.

It has 2 parts: 1) importing from the database. 2) visualizing it.

I will handle this. It would be a bit different from what @LuisSarmientoM Hey @MrJ8585, sorry I missed your comment here. It's a bit complicated issue and I have already started working on it.

It has 2 parts: 1) importing from the database. 2) visualizing it.

I will handle this. It would be a bit different from what @LuisSarmientoM showed because the custom type is shared between multiple tables.

We will build it as an object similar to tables/relationships. I will finish that soon!

Appreciate your willingness to help! showed because the custom type is shared between multiple tables.

We will build it as an object similar to tables/relationships. I will finish that soon!

Appreciate your willingness to help!