Do we have to add enums to the migration manually?

I have the following in the my schema:
const membershipRoleEnum = pgEnum('membership_role', [
'GUEST',
'MEMBER',
'PREMIUM_MEMBER',
'ADMIN',
'SUPER_ADMIN',
]);

export const groupMembers = pgTable(
'group_members',
{
id: serial('id').primaryKey(),
memberId: integer('member_id').references(() => users.id),
groupId: integer('group_id').references(() => groups.id),
role: membershipRoleEnum('role'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
},
(table) => ({
memberIdx: index('member_idx').on(table.memberId),
groupIdx: index('group_idx').on(table.groupId),
})
);
const membershipRoleEnum = pgEnum('membership_role', [
'GUEST',
'MEMBER',
'PREMIUM_MEMBER',
'ADMIN',
'SUPER_ADMIN',
]);

export const groupMembers = pgTable(
'group_members',
{
id: serial('id').primaryKey(),
memberId: integer('member_id').references(() => users.id),
groupId: integer('group_id').references(() => groups.id),
role: membershipRoleEnum('role'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow(),
},
(table) => ({
memberIdx: index('member_idx').on(table.memberId),
groupIdx: index('group_idx').on(table.groupId),
})
);
Everything worked great except the enums did not get added to my sql file. I needed to manually add the following to my sql file:
CREATE TYPE membership_role AS ENUM (
'GUEST',
'MEMBER',
'PREMIUM_MEMBER',
'ADMIN',
'SUPER_ADMIN',
);
CREATE TYPE membership_role AS ENUM (
'GUEST',
'MEMBER',
'PREMIUM_MEMBER',
'ADMIN',
'SUPER_ADMIN',
);
Is that expected for now?
2 Replies
Andrii Sherman
You need to export membershipRoleEnum as well drizzle-kit is importing everything from schema files everything that was not exported won't be visible for drizzle-kit
Super 🦸🏻
Super 🦸🏻OP2y ago
Thank you
Want results from more Discord servers?
Add your server