drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Support Comments for Column definitions and introspections
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
MySQL has a feature where you can add comments to the [column definitions](https://dev.mysql.com/doc/refman/8.0/en/create-table.html). This is useful when exploring the database from a Database manager as the comment adds information for what the column is for, if the name is not suffitiencly explicit.

_(screenshot of phpMyAdmin, a mySQL db manager as an example of how comments are displayed)_
I think is a good feature as it allows the dabase to have better documentation. I imagine it as follows:
The following code
```ts
export const User = mysqlTable("user", {
id: int("id").primaryKey().autoincrement().notNull(),
email: varchar("email", { length: 255 }).notNull().unique().comment("email of the user"), // comment
});
```
would generate the following table
```sql
CREATE TABLE `user` (
`id` int AUTO_INCREMENT NOT NULL,
`email` varchar(255) NOT NULL COMMENT 'email of the user', -- comment
CONSTRAINT `user_id` PRIMARY KEY(`id`),
CONSTRAINT `user_email_unique` UNIQUE(`email`)
);
```
To update a column, alter statements allow to add comments as described [here](https://stackoverflow.com/questions/2162420/alter-mysql-table-to-add-comments-on-columns).
Also, for the introspect tool, current comments can be read as explained [here](https://stackoverflow.com/questions/6752169/how-to-obtain-column-comments-from-sql).
**PS:** sorry if this was proposed before, I did not find any issue relating column comments
Thanks!
Contributor guide
Research direction
Start with the MySQL column-definition and introspection paths described in the issue, then trace how ALTER statements are generated. The work is done when comments can be defined, emitted in CREATE and ALTER SQL, and read back by introspection with coverage for the shown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100