drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[drizzle-kit] Add support for table and column comments

Open xcfox opened this issue 8 months ago • 14 comments

This PR implements the support for table and column comments as discussed here and here.

import * as my from 'drizzle-orm/mysql-core'

const schema = my.mysqlTable(
  'users',
  {
    id: my.serial('id').primaryKey().comment('users id'),
    name: my.text('name').notNull().comment('users name'),
  },
  () => [my.comment('users table')]
)

This PR has implemented:

  • [x] PostgreSQL

    • [x] Table comments
    • [x] Column comments
  • [x] MySQL

    • [x] Table comments
    • [x] Column comments
  • [x] SingleStore

    • [x] Table comments
    • [x] Column comments.
  • ⚠️ SQLite: SQLite does not support persistent table comments and column comments

Why are comments necessary?

  • For non-English teams, comments are necessary information to help understand the tables.
  • Comments are widely supported in database management tools such as phpMyAdmin, DBeaver, and Beekeeper.
  • For members who are not involved in code development, comments are an important way to understand the table structure.
  • Comments can serve as metadata of the tables and be used to generate documents or code, which is very useful for libraries such as drizzle-zod, drizzle-valibot, drizzle-graphql, and GQLoom.

What's next?

  • Add examples of comments in the documentation.
  • Use comments in drizzle-zod to generate descriptions of Zod types.
  • Use comments in drizzle-valibot to generate descriptions of Valibot types.
  • Use comments in drizzle-graphql to generate descriptions of GraphQL types.

xcfox avatar Apr 23 '25 12:04 xcfox

This is amazing! it would be amazing to ping the drizzle team to get this one merged!

eduardo-trawa avatar May 19 '25 13:05 eduardo-trawa

my project need this feature 🔥

mioe avatar May 26 '25 16:05 mioe

Agreed, this would be very nice for our customers to better understand the table structure - since the data we are inserting originates in a different language - so it would be good to comment where the column originates from

suuunly avatar May 27 '25 12:05 suuunly

There is not enough such a chip for a more beautiful description of the base, I would like to get this improvement soon!

MoloF avatar May 28 '25 15:05 MoloF

very useful feature, hope you release it soon.

SystemsFailure avatar May 28 '25 15:05 SystemsFailure

+1

Tixxxon avatar May 28 '25 16:05 Tixxxon

+1

Tsuev avatar May 29 '25 03:05 Tsuev

Added a new discussion to push this feature

eduardo-trawa avatar Jun 04 '25 12:06 eduardo-trawa

+1

PromiseAll avatar Jul 11 '25 01:07 PromiseAll

SQLite: SQLite does not support persistent table comments and column comments

I use @elysiajs/openapi on Elysia. I want the data fields in the API document generated by OpenAI to be described. What should I do?

This is ok: image

preview: image

This won't work: image

image image

ywenhao avatar Sep 18 '25 01:09 ywenhao

@xcfox

ywenhao avatar Sep 18 '25 02:09 ywenhao

@AndriiSherman

ywenhao avatar Sep 19 '25 08:09 ywenhao

@ywenhao stop.

read this

nikelborm avatar Sep 19 '25 08:09 nikelborm

@ywenhao stop.

read this

ok.

ywenhao avatar Sep 19 '25 10:09 ywenhao