How to add comment on postgres table columns (and other one-time operations like add trigger)

I want to add comment on columns of my postgres table (COMMENT ON COLUMN). There is no native function in drizzle. I can see suggestions like
export default {
async up(db) {
await db.execute(sql`COMMENT ON COLUMN users.username IS 'User\'s unique username';`);
await db.execute(sql`COMMENT ON COLUMN users.email IS 'User\'s email address';`);
},
export default {
async up(db) {
await db.execute(sql`COMMENT ON COLUMN users.username IS 'User\'s unique username';`);
await db.execute(sql`COMMENT ON COLUMN users.email IS 'User\'s email address';`);
},
But won't this be executed every time? I faced same doubt when trying to add trigger+function.
3 Replies
François
François3w ago
Hey @nu , I think this question can only be answered by yourself because you call the up function yourself no?
François
François3w ago
If I were you I would add this kind of work as a custom migration script. This will ensure that it will only be run when the migrations will be applied aka when the database schema is being set up by drizzle kit. Have a look at https://orm.drizzle.team/docs/kit-custom-migrations for more information on migrations
Drizzle ORM - Custom migrations
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
nu
nuOP3w ago
Hi @François . Thanks for the help. No at this point I don't have the up function. I only have my tables defined. The link you shared looks like a good idea (probably that's how I will do it). Although this will loose track of a timeline of changes in git I assume, which was one of my goals behind using an ORM. I assume the migrate() function mustn't track changes in a migration file? (say I create a stored proc with custom mig file and update the same file to update the stored proc)
Want results from more Discord servers?
Add your server