Skip to content

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

Open
xcfox wants to merge 8 commits into
drizzle-team:betafrom
xcfox:column_comments
Open

[drizzle-kit] Add support for table and column comments#4446
xcfox wants to merge 8 commits into
drizzle-team:betafrom
xcfox:column_comments

Conversation

@xcfox
Copy link
Copy Markdown

@xcfox xcfox commented Apr 23, 2025

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

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

const users = my.mysqlTable(
  'users',
  {
    id: my.serial('id').primaryKey().comment('Primary key'),
    name: my.text('name').notNull().comment('User name'),
  },
  () => [my.comment('Application users table')]
)
Dialect Table Comment Column Comment SQL Generation Introspection TypeScript Generation
MySQL COMMENT='...' / COMMENT '...'
SingleStore (inherits MySQL)
PostgreSQL COMMENT ON TABLE/COLUMN
CockroachDB COMMENT ON TABLE/COLUMN
MSSQL sp_addextendedproperty
SQLite

SQL Examples

MySQL:

CREATE TABLE `users` (
  `id` serial PRIMARY KEY COMMENT 'Primary key',
  `name` text NOT NULL COMMENT 'User name'
) COMMENT='Application users table';

PostgreSQL:

CREATE TABLE "users" (
  "id" serial PRIMARY KEY,
  "name" text NOT NULL
);
COMMENT ON TABLE "users" IS 'Application users table';
COMMENT ON COLUMN "users"."id" IS 'Primary key';

MSSQL:

CREATE TABLE [users] (
  [id] int IDENTITY(1,1) PRIMARY KEY,
  [name] nvarchar(255) NOT NULL
);
EXEC sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'users', @level2type=N'COLUMN', @level2name=N'id';

SQLite

SQLite has no native COMMENT syntax and no kit-level support (comment metadata is stored in Drizzle ORM schema only, not in DDL snapshots or SQL migrations). The .comment() and comment() APIs work in ORM schema definitions and can be used by downstream tools (drizzle-zod, drizzle-valibot, drizzle-graphql) for documentation generation, but drizzle-kit will not generate, diff, or introspect SQLite comments.

Next Steps

  • Add documentation examples
  • Integrate with drizzle-zod / drizzle-valibot / drizzle-graphql for schema descriptions

@eduardo-trawa
Copy link
Copy Markdown

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

@mioe
Copy link
Copy Markdown

mioe commented May 26, 2025

my project need this feature 🔥

@suuunly
Copy link
Copy Markdown

suuunly commented May 27, 2025

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

@MoloF
Copy link
Copy Markdown

MoloF commented May 28, 2025

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

@SystemsFailure
Copy link
Copy Markdown

very useful feature, hope you release it soon.

@Tixxxon
Copy link
Copy Markdown

Tixxxon commented May 28, 2025

+1

1 similar comment
@Tsuev
Copy link
Copy Markdown

Tsuev commented May 29, 2025

+1

@eduardo-trawa
Copy link
Copy Markdown

Added a new discussion to push this feature

Copy link
Copy Markdown

@erguotou520 erguotou520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@PromiseAll
Copy link
Copy Markdown

+1

@ywenhao
Copy link
Copy Markdown

ywenhao commented Sep 18, 2025

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
Copy link
Copy Markdown

ywenhao commented Sep 18, 2025

@xcfox

@ywenhao
Copy link
Copy Markdown

ywenhao commented Sep 19, 2025

@AndriiSherman

@nikelborm
Copy link
Copy Markdown

@ywenhao stop.

read this

@ywenhao
Copy link
Copy Markdown

ywenhao commented Sep 19, 2025

@ywenhao stop.

read this

ok.

@xcfox
Copy link
Copy Markdown
Author

xcfox commented Dec 13, 2025

I see that the new engine has been completed, and I think I should re-implement this requirement on the new engine.

@xcfox xcfox marked this pull request as draft December 13, 2025 14:47
@xcfox xcfox force-pushed the column_comments branch from 5f3badb to 4df2329 Compare May 28, 2026 13:59
@xcfox xcfox changed the base branch from main to beta May 28, 2026 14:00
@xcfox xcfox marked this pull request as ready for review May 28, 2026 19:03
@xcfox
Copy link
Copy Markdown
Author

xcfox commented May 28, 2026

Finally, I have reimplemented this feature on the new engine.

@xcfox xcfox force-pushed the column_comments branch from b99bb6d to 6704954 Compare May 30, 2026 13:13
@xcfox xcfox force-pushed the column_comments branch from 6704954 to 7b8441e Compare May 30, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.